More refactoring
This commit is contained in:
@@ -20,7 +20,6 @@ env:
|
|||||||
- BUILD_CONFIG=feedc0de_usb
|
- BUILD_CONFIG=feedc0de_usb
|
||||||
- BUILD_CONFIG=greyhash_usb
|
- BUILD_CONFIG=greyhash_usb
|
||||||
- BUILD_CONFIG=aveexy_usb
|
- BUILD_CONFIG=aveexy_usb
|
||||||
- BUILD_CONFIG=testbench_usb
|
|
||||||
- BUILD_CONFIG=mickdermack_usb
|
- BUILD_CONFIG=mickdermack_usb
|
||||||
- BUILD_CONFIG=peter_usb
|
- BUILD_CONFIG=peter_usb
|
||||||
|
|
||||||
|
@@ -12,11 +12,11 @@ platformio run --environment bobbycar_usb --target upload
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
### -DFEATURE_3WIRESW
|
|
||||||

|
|
||||||
|
|
||||||
### -DFEATURE_DPAD
|
### -DFEATURE_DPAD
|
||||||

|

|
||||||
|
|
||||||
|
### -DFEATURE_DPAD_3WIRESW
|
||||||
|

|
||||||
|
|
||||||
### -DFEATURE_ROTARY
|
### -DFEATURE_ROTARY
|
||||||

|

|
||||||
|
@@ -51,8 +51,6 @@ build_flags =
|
|||||||
-DTFT_DC=12
|
-DTFT_DC=12
|
||||||
-DTFT_RST=2
|
-DTFT_RST=2
|
||||||
-DSPI_FREQUENCY=27000000
|
-DSPI_FREQUENCY=27000000
|
||||||
-DSPI_READ_FREQUENCY=20000000
|
|
||||||
-DSPI_TOUCH_FREQUENCY=2500000
|
|
||||||
-DDEFAULT_SWAPSCREENBYTES=false
|
-DDEFAULT_SWAPSCREENBYTES=false
|
||||||
-DPINS_RX1=4
|
-DPINS_RX1=4
|
||||||
-DPINS_TX1=5
|
-DPINS_TX1=5
|
||||||
@@ -84,10 +82,10 @@ build_flags =
|
|||||||
${default_limits.build_flags}
|
${default_limits.build_flags}
|
||||||
-DDEVICE_PREFIX=bobbyquad
|
-DDEVICE_PREFIX=bobbyquad
|
||||||
-DFEATURE_WEBSERVER
|
-DFEATURE_WEBSERVER
|
||||||
-DFEATURE_3WIRESW
|
-DFEATURE_DPAD_3WIRESW
|
||||||
-DPINS_3WIRESW_OUT=0
|
-DPINS_DPAD_3WIRESW_OUT=0
|
||||||
-DPINS_3WIRESW_IN1=16
|
-DPINS_DPAD_3WIRESW_IN1=16
|
||||||
-DPINS_3WIRESW_IN2=27
|
-DPINS_DPAD_3WIRESW_IN2=27
|
||||||
; -DFEATURE_ROTARY
|
; -DFEATURE_ROTARY
|
||||||
; -DPINS_ROTARY_CLK=16
|
; -DPINS_ROTARY_CLK=16
|
||||||
; -DPINS_ROTARY_DT=27
|
; -DPINS_ROTARY_DT=27
|
||||||
@@ -194,19 +192,11 @@ build_flags =
|
|||||||
${default_limits.build_flags}
|
${default_limits.build_flags}
|
||||||
-DDEVICE_PREFIX=bobbyquad
|
-DDEVICE_PREFIX=bobbyquad
|
||||||
-DFEATURE_WEBSERVER
|
-DFEATURE_WEBSERVER
|
||||||
; -DFEATURE_3WIRESW
|
|
||||||
; -DPINS_3WIRESW_OUT=0
|
|
||||||
; -DPINS_3WIRESW_IN1=16
|
|
||||||
; -DPINS_3WIRESW_IN2=27
|
|
||||||
-DFEATURE_DPAD
|
-DFEATURE_DPAD
|
||||||
-DPINS_DPAD_UP=32
|
-DPINS_DPAD_UP=32
|
||||||
-DPINS_DPAD_DOWN=22
|
-DPINS_DPAD_DOWN=22
|
||||||
-DPINS_DPAD_CONFIRM=23
|
-DPINS_DPAD_CONFIRM=23
|
||||||
-DPINS_DPAD_BACK=27
|
-DPINS_DPAD_BACK=27
|
||||||
; -DFEATURE_ROTARY
|
|
||||||
; -DPINS_ROTARY_CLK=16
|
|
||||||
; -DPINS_ROTARY_DT=27
|
|
||||||
; -DPINS_ROTARY_SW=0
|
|
||||||
-DDEFAULT_GASMIN=800
|
-DDEFAULT_GASMIN=800
|
||||||
-DDEFAULT_GASMAX=3700
|
-DDEFAULT_GASMAX=3700
|
||||||
-DDEFAULT_BREMSMIN=1300
|
-DDEFAULT_BREMSMIN=1300
|
||||||
@@ -214,54 +204,6 @@ build_flags =
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
[env:testbench_usb]
|
|
||||||
platform = ${common_env_data.platform}
|
|
||||||
board = ${common_env_data.board}
|
|
||||||
framework = ${common_env_data.framework}
|
|
||||||
board_build.partitions = bobbycar_noota.csv
|
|
||||||
lib_deps = ${common_env_data.lib_deps}
|
|
||||||
lib_compat_mode = ${common_env_data.lib_compat_mode}
|
|
||||||
build_unflags = ${common_env_data.build_unflags}
|
|
||||||
|
|
||||||
upload_port = /dev/ttyUSB*
|
|
||||||
upload_speed = 921600
|
|
||||||
|
|
||||||
build_flags =
|
|
||||||
${common_env_data.build_flags}
|
|
||||||
-DDEVICE_PREFIX=testbench
|
|
||||||
-DFEATURE_WEBSERVER
|
|
||||||
-DILI9341_DRIVER=1
|
|
||||||
-DTFT_MOSI=22
|
|
||||||
-DTFT_SCLK=21
|
|
||||||
-DTFT_CS=27
|
|
||||||
-DTFT_DC=32
|
|
||||||
-DTFT_RST=25
|
|
||||||
-DSPI_FREQUENCY=27000000
|
|
||||||
-DSPI_READ_FREQUENCY=20000000
|
|
||||||
-DSPI_TOUCH_FREQUENCY=2500000
|
|
||||||
-DDEFAULT_SWAPSCREENBYTES=false
|
|
||||||
-DPINS_RX1=18
|
|
||||||
-DPINS_TX1=19
|
|
||||||
-DPINS_RX2=23
|
|
||||||
-DPINS_TX2=34
|
|
||||||
-DPINS_GAS=35
|
|
||||||
-DPINS_BREMS=33
|
|
||||||
; -DFEATURE_3WIRESW
|
|
||||||
; -DPINS_3WIRESW_OUT=17
|
|
||||||
; -DPINS_3WIRESW_IN1=4
|
|
||||||
; -DPINS_3WIRESW_IN2=16
|
|
||||||
; -DFEATURE_ROTARY
|
|
||||||
; -DPINS_ROTARY_CLK=4
|
|
||||||
; -DPINS_ROTARY_DT=16
|
|
||||||
; -DPINS_ROTARY_SW=17
|
|
||||||
${default_limits.build_flags}
|
|
||||||
-DDEFAULT_GASMIN=0
|
|
||||||
-DDEFAULT_GASMAX=4095
|
|
||||||
-DDEFAULT_BREMSMIN=0
|
|
||||||
-DDEFAULT_BREMSMAX=4095
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[env:mickdermack_usb]
|
[env:mickdermack_usb]
|
||||||
platform = ${common_env_data.platform}
|
platform = ${common_env_data.platform}
|
||||||
board = ${common_env_data.board}
|
board = ${common_env_data.board}
|
||||||
@@ -279,7 +221,6 @@ build_flags =
|
|||||||
-DDEVICE_PREFIX=bobbyquad
|
-DDEVICE_PREFIX=bobbyquad
|
||||||
-DFEATURE_WEBSERVER
|
-DFEATURE_WEBSERVER
|
||||||
${default_limits.build_flags}
|
${default_limits.build_flags}
|
||||||
-DUSER_SETUP_LOADED=1
|
|
||||||
-DRPI_DISPLAY_TYPE
|
-DRPI_DISPLAY_TYPE
|
||||||
-DILI9486_DRIVER
|
-DILI9486_DRIVER
|
||||||
; TODO: TFT_MISO (touch MISO?)
|
; TODO: TFT_MISO (touch MISO?)
|
||||||
@@ -301,14 +242,6 @@ build_flags =
|
|||||||
-DPINS_TX2=34
|
-DPINS_TX2=34
|
||||||
-DPINS_GAS=35
|
-DPINS_GAS=35
|
||||||
-DPINS_BREMS=33
|
-DPINS_BREMS=33
|
||||||
; -DFEATURE_3WIRESW
|
|
||||||
; -DPINS_3WIRESW_OUT=17
|
|
||||||
; -DPINS_3WIRESW_IN1=4
|
|
||||||
; -DPINS_3WIRESW_IN2=16
|
|
||||||
; -DFEATURE_ROTARY
|
|
||||||
; -DPINS_ROTARY_CLK=4
|
|
||||||
; -DPINS_ROTARY_DT=16
|
|
||||||
; -DPINS_ROTARY_SW=17
|
|
||||||
-DDEFAULT_GASMIN=0
|
-DDEFAULT_GASMIN=0
|
||||||
-DDEFAULT_GASMAX=4095
|
-DDEFAULT_GASMAX=4095
|
||||||
-DDEFAULT_BREMSMIN=0
|
-DDEFAULT_BREMSMIN=0
|
||||||
|
48
src/dpad.h
48
src/dpad.h
@@ -7,19 +7,21 @@
|
|||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
using DPadState = std::tuple<bool, bool, bool, bool>;
|
namespace dpad
|
||||||
|
{
|
||||||
|
using State = std::tuple<bool, bool, bool, bool>;
|
||||||
|
|
||||||
template<pin_t IN1, pin_t IN2, pin_t IN3, pin_t IN4>
|
template<pin_t IN1, pin_t IN2, pin_t IN3, pin_t IN4>
|
||||||
class DPadHelper
|
class Helper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
DPadState read();
|
State read();
|
||||||
};
|
};
|
||||||
|
|
||||||
template<pin_t IN1, pin_t IN2, pin_t IN3, pin_t IN4>
|
template<pin_t IN1, pin_t IN2, pin_t IN3, pin_t IN4>
|
||||||
void DPadHelper<IN1, IN2, IN3, IN4>::begin()
|
void Helper<IN1, IN2, IN3, IN4>::begin()
|
||||||
{
|
{
|
||||||
pinMode(IN1, INPUT_PULLUP);
|
pinMode(IN1, INPUT_PULLUP);
|
||||||
pinMode(IN2, INPUT_PULLUP);
|
pinMode(IN2, INPUT_PULLUP);
|
||||||
@@ -28,7 +30,7 @@ void DPadHelper<IN1, IN2, IN3, IN4>::begin()
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<pin_t IN1, pin_t IN2, pin_t IN3, pin_t IN4>
|
template<pin_t IN1, pin_t IN2, pin_t IN3, pin_t IN4>
|
||||||
DPadState DPadHelper<IN1, IN2, IN3, IN4>::read()
|
State Helper<IN1, IN2, IN3, IN4>::read()
|
||||||
{
|
{
|
||||||
const bool result0 = digitalRead(IN1);
|
const bool result0 = digitalRead(IN1);
|
||||||
const bool result1 = digitalRead(IN2);
|
const bool result1 = digitalRead(IN2);
|
||||||
@@ -39,44 +41,48 @@ DPadState DPadHelper<IN1, IN2, IN3, IN4>::read()
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FEATURE_DPAD
|
#ifdef FEATURE_DPAD
|
||||||
DPadHelper<PINS_DPAD_UP, PINS_DPAD_DOWN, PINS_DPAD_CONFIRM, PINS_DPAD_BACK> dpad;
|
Helper<PINS_DPAD_UP, PINS_DPAD_DOWN, PINS_DPAD_CONFIRM, PINS_DPAD_BACK> helper;
|
||||||
|
State lastState;
|
||||||
|
|
||||||
DPadState dpadLastState;
|
void init()
|
||||||
void updateDpad()
|
|
||||||
{
|
{
|
||||||
const auto state = dpad.read();
|
helper.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void update()
|
||||||
|
{
|
||||||
|
const auto state = helper.read();
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
ButtonUp = 0
|
ButtonUp = 0,
|
||||||
ButtonDown = 1,
|
ButtonDown = 1,
|
||||||
ButtonConfirm = 2,
|
ButtonConfirm = 2,
|
||||||
ButtonBack = 3,
|
ButtonBack = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
if (std::get<ButtonUp>(dpadHackLastState) != std::get<ButtonUp>(state))
|
if (std::get<ButtonUp>(lastState) != std::get<ButtonUp>(state))
|
||||||
{
|
{
|
||||||
if (std::get<ButtonUp>(state))
|
if (std::get<ButtonUp>(state))
|
||||||
InputDispatcher::rotate(-1);
|
InputDispatcher::rotate(-1);
|
||||||
std::get<ButtonUp>(dpadHackLastState) = std::get<ButtonUp>(state);
|
std::get<ButtonUp>(lastState) = std::get<ButtonUp>(state);
|
||||||
}
|
}
|
||||||
if (std::get<ButtonDown>(dpadHackLastState) != std::get<ButtonDown>(state))
|
if (std::get<ButtonDown>(lastState) != std::get<ButtonDown>(state))
|
||||||
{
|
{
|
||||||
if (std::get<ButtonDown>(state))
|
if (std::get<ButtonDown>(state))
|
||||||
InputDispatcher::rotate(1);
|
InputDispatcher::rotate(1);
|
||||||
std::get<ButtonDown>(dpadHackLastState) = std::get<ButtonDown>(state);
|
std::get<ButtonDown>(lastState) = std::get<ButtonDown>(state);
|
||||||
}
|
}
|
||||||
if (std::get<ButtonConfirm>(dpadHackLastState) != std::get<ButtonConfirm>(state))
|
if (std::get<ButtonConfirm>(lastState) != std::get<ButtonConfirm>(state))
|
||||||
{
|
{
|
||||||
InputDispatcher::confirmButton(std::get<ButtonConfirm>(state));
|
InputDispatcher::confirmButton(std::get<ButtonConfirm>(state));
|
||||||
std::get<ButtonConfirm>(dpadHackLastState) = std::get<ButtonConfirm>(state);
|
std::get<ButtonConfirm>(lastState) = std::get<ButtonConfirm>(state);
|
||||||
}
|
}
|
||||||
if (std::get<ButtonBack>(dpadHackLastState) != std::get<ButtonBack>(state))
|
if (std::get<ButtonBack>(lastState) != std::get<ButtonBack>(state))
|
||||||
{
|
{
|
||||||
InputDispatcher::backButton(std::get<ButtonBack>(state));
|
InputDispatcher::backButton(std::get<ButtonBack>(state));
|
||||||
std::get<ButtonBack>(dpadHackLastState) = std::get<ButtonBack>(state);
|
std::get<ButtonBack>(lastState) = std::get<ButtonBack>(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
dpadLastState = state;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@@ -1,7 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <tuple>
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
@@ -9,9 +7,10 @@
|
|||||||
#include "dpad.h"
|
#include "dpad.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
namespace dpad3wire
|
||||||
|
{
|
||||||
template<pin_t OUT, pin_t IN1, pin_t IN2>
|
template<pin_t OUT, pin_t IN1, pin_t IN2>
|
||||||
class DPadHackHelper
|
class Helper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static constexpr auto OutPin = OUT;
|
static constexpr auto OutPin = OUT;
|
||||||
@@ -20,17 +19,17 @@ public:
|
|||||||
|
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
DPadState read();
|
dpad::State read();
|
||||||
};
|
};
|
||||||
|
|
||||||
template<pin_t OUT, pin_t IN1, pin_t IN2>
|
template<pin_t OUT, pin_t IN1, pin_t IN2>
|
||||||
void DPadHackHelper<OUT, IN1, IN2>::begin()
|
void Helper<OUT, IN1, IN2>::begin()
|
||||||
{
|
{
|
||||||
pinMode(OUT, OUTPUT);
|
pinMode(OUT, OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<pin_t OUT, pin_t IN1, pin_t IN2>
|
template<pin_t OUT, pin_t IN1, pin_t IN2>
|
||||||
DPadState DPadHackHelper<OUT, IN1, IN2>::read()
|
dpad::State Helper<OUT, IN1, IN2>::read()
|
||||||
{
|
{
|
||||||
digitalWrite(OUT, LOW);
|
digitalWrite(OUT, LOW);
|
||||||
|
|
||||||
@@ -55,13 +54,19 @@ DPadState DPadHackHelper<OUT, IN1, IN2>::read()
|
|||||||
return std::make_tuple(result0, result1, result2, result3);
|
return std::make_tuple(result0, result1, result2, result3);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FEATURE_3WIRESW
|
#ifdef FEATURE_DPAD_3WIRESW
|
||||||
DPadHackHelper<PINS_3WIRESW_OUT, PINS_3WIRESW_IN1, PINS_3WIRESW_IN2> dpadHack;
|
Helper<PINS_DPAD_3WIRESW_OUT, PINS_DPAD_3WIRESW_IN1, PINS_DPAD_3WIRESW_IN2> helper;
|
||||||
|
dpad::State lastState;
|
||||||
|
|
||||||
DPadState dpadHackLastState;
|
void init()
|
||||||
void updateDpadHack()
|
|
||||||
{
|
{
|
||||||
const auto state = dpadHack.read();
|
helper.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void update()
|
||||||
|
{
|
||||||
|
const auto state = helper.read();
|
||||||
|
const auto now = millis();
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
ButtonUp = 3,
|
ButtonUp = 3,
|
||||||
@@ -70,30 +75,31 @@ void updateDpadHack()
|
|||||||
ButtonBack = 2
|
ButtonBack = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
if (std::get<ButtonUp>(dpadHackLastState) != std::get<ButtonUp>(state))
|
if (std::get<ButtonUp>(lastState) != std::get<ButtonUp>(state))
|
||||||
{
|
{
|
||||||
if (std::get<ButtonUp>(state))
|
if (std::get<ButtonUp>(state))
|
||||||
InputDispatcher::rotate(-1);
|
InputDispatcher::rotate(-1);
|
||||||
std::get<ButtonUp>(dpadHackLastState) = std::get<ButtonUp>(state);
|
std::get<ButtonUp>(lastState) = std::get<ButtonUp>(state);
|
||||||
}
|
}
|
||||||
if (std::get<ButtonDown>(dpadHackLastState) != std::get<ButtonDown>(state))
|
if (std::get<ButtonDown>(lastState) != std::get<ButtonDown>(state))
|
||||||
{
|
{
|
||||||
if (std::get<ButtonDown>(state))
|
if (std::get<ButtonDown>(state))
|
||||||
InputDispatcher::rotate(1);
|
InputDispatcher::rotate(1);
|
||||||
std::get<ButtonDown>(dpadHackLastState) = std::get<ButtonDown>(state);
|
std::get<ButtonDown>(lastState) = std::get<ButtonDown>(state);
|
||||||
}
|
}
|
||||||
if (std::get<ButtonConfirm>(dpadHackLastState) != std::get<ButtonConfirm>(state))
|
if (std::get<ButtonConfirm>(lastState) != std::get<ButtonConfirm>(state))
|
||||||
{
|
{
|
||||||
InputDispatcher::confirmButton(std::get<ButtonConfirm>(state));
|
InputDispatcher::confirmButton(std::get<ButtonConfirm>(state));
|
||||||
std::get<ButtonConfirm>(dpadHackLastState) = std::get<ButtonConfirm>(state);
|
std::get<ButtonConfirm>(lastState) = std::get<ButtonConfirm>(state);
|
||||||
}
|
}
|
||||||
if (std::get<ButtonBack>(dpadHackLastState) != std::get<ButtonBack>(state))
|
if (std::get<ButtonBack>(lastState) != std::get<ButtonBack>(state))
|
||||||
{
|
{
|
||||||
InputDispatcher::backButton(std::get<ButtonBack>(state));
|
InputDispatcher::backButton(std::get<ButtonBack>(state));
|
||||||
std::get<ButtonBack>(dpadHackLastState) = std::get<ButtonBack>(state);
|
std::get<ButtonBack>(lastState) = std::get<ButtonBack>(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
dpadHackLastState = state;
|
lastState = state;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
}
|
14
src/main.cpp
14
src/main.cpp
@@ -12,7 +12,7 @@
|
|||||||
#include "modes/tempomatmode.h"
|
#include "modes/tempomatmode.h"
|
||||||
#include "screens.h"
|
#include "screens.h"
|
||||||
#include "dpad.h"
|
#include "dpad.h"
|
||||||
#include "dpadHack.h"
|
#include "dpad3wire.h"
|
||||||
#include "rotary.h"
|
#include "rotary.h"
|
||||||
#include "serialhandler.h"
|
#include "serialhandler.h"
|
||||||
#include "ota.h"
|
#include "ota.h"
|
||||||
@@ -46,11 +46,11 @@ void setup()
|
|||||||
initScreen();
|
initScreen();
|
||||||
|
|
||||||
#ifdef FEATURE_DPAD
|
#ifdef FEATURE_DPAD
|
||||||
dpad.begin();
|
dpad::init();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FEATURE_3WIRESW
|
#ifdef FEATURE_DPAD_3WIRESW
|
||||||
dpadHack.begin();
|
dpad3wire::init();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FEATURE_ROTARY
|
#ifdef FEATURE_ROTARY
|
||||||
@@ -139,11 +139,11 @@ void loop()
|
|||||||
const auto now = millis();
|
const auto now = millis();
|
||||||
|
|
||||||
#ifdef FEATURE_DPAD
|
#ifdef FEATURE_DPAD
|
||||||
updateDpad();
|
dpad::update();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FEATURE_3WIRESW
|
#ifdef FEATURE_DPAD_3WIRESW
|
||||||
updateDpadHack();
|
dpad3wire::update();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!lastModeUpdate)
|
if (!lastModeUpdate)
|
||||||
|
Reference in New Issue
Block a user