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

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

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

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

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

|
||||
|
@ -51,8 +51,6 @@ build_flags =
|
||||
-DTFT_DC=12
|
||||
-DTFT_RST=2
|
||||
-DSPI_FREQUENCY=27000000
|
||||
-DSPI_READ_FREQUENCY=20000000
|
||||
-DSPI_TOUCH_FREQUENCY=2500000
|
||||
-DDEFAULT_SWAPSCREENBYTES=false
|
||||
-DPINS_RX1=4
|
||||
-DPINS_TX1=5
|
||||
@ -84,10 +82,10 @@ build_flags =
|
||||
${default_limits.build_flags}
|
||||
-DDEVICE_PREFIX=bobbyquad
|
||||
-DFEATURE_WEBSERVER
|
||||
-DFEATURE_3WIRESW
|
||||
-DPINS_3WIRESW_OUT=0
|
||||
-DPINS_3WIRESW_IN1=16
|
||||
-DPINS_3WIRESW_IN2=27
|
||||
-DFEATURE_DPAD_3WIRESW
|
||||
-DPINS_DPAD_3WIRESW_OUT=0
|
||||
-DPINS_DPAD_3WIRESW_IN1=16
|
||||
-DPINS_DPAD_3WIRESW_IN2=27
|
||||
; -DFEATURE_ROTARY
|
||||
; -DPINS_ROTARY_CLK=16
|
||||
; -DPINS_ROTARY_DT=27
|
||||
@ -194,19 +192,11 @@ build_flags =
|
||||
${default_limits.build_flags}
|
||||
-DDEVICE_PREFIX=bobbyquad
|
||||
-DFEATURE_WEBSERVER
|
||||
; -DFEATURE_3WIRESW
|
||||
; -DPINS_3WIRESW_OUT=0
|
||||
; -DPINS_3WIRESW_IN1=16
|
||||
; -DPINS_3WIRESW_IN2=27
|
||||
-DFEATURE_DPAD
|
||||
-DPINS_DPAD_UP=32
|
||||
-DPINS_DPAD_DOWN=22
|
||||
-DPINS_DPAD_CONFIRM=23
|
||||
-DPINS_DPAD_BACK=27
|
||||
; -DFEATURE_ROTARY
|
||||
; -DPINS_ROTARY_CLK=16
|
||||
; -DPINS_ROTARY_DT=27
|
||||
; -DPINS_ROTARY_SW=0
|
||||
-DDEFAULT_GASMIN=800
|
||||
-DDEFAULT_GASMAX=3700
|
||||
-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]
|
||||
platform = ${common_env_data.platform}
|
||||
board = ${common_env_data.board}
|
||||
@ -279,7 +221,6 @@ build_flags =
|
||||
-DDEVICE_PREFIX=bobbyquad
|
||||
-DFEATURE_WEBSERVER
|
||||
${default_limits.build_flags}
|
||||
-DUSER_SETUP_LOADED=1
|
||||
-DRPI_DISPLAY_TYPE
|
||||
-DILI9486_DRIVER
|
||||
; TODO: TFT_MISO (touch MISO?)
|
||||
@ -301,14 +242,6 @@ build_flags =
|
||||
-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
|
||||
-DDEFAULT_GASMIN=0
|
||||
-DDEFAULT_GASMAX=4095
|
||||
-DDEFAULT_BREMSMIN=0
|
||||
|
48
src/dpad.h
48
src/dpad.h
@ -7,19 +7,21 @@
|
||||
#include "globals.h"
|
||||
|
||||
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>
|
||||
class DPadHelper
|
||||
class Helper
|
||||
{
|
||||
public:
|
||||
void begin();
|
||||
|
||||
DPadState read();
|
||||
State read();
|
||||
};
|
||||
|
||||
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(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>
|
||||
DPadState DPadHelper<IN1, IN2, IN3, IN4>::read()
|
||||
State Helper<IN1, IN2, IN3, IN4>::read()
|
||||
{
|
||||
const bool result0 = digitalRead(IN1);
|
||||
const bool result1 = digitalRead(IN2);
|
||||
@ -39,44 +41,48 @@ DPadState DPadHelper<IN1, IN2, IN3, IN4>::read()
|
||||
}
|
||||
|
||||
#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 updateDpad()
|
||||
void init()
|
||||
{
|
||||
const auto state = dpad.read();
|
||||
helper.begin();
|
||||
}
|
||||
|
||||
void update()
|
||||
{
|
||||
const auto state = helper.read();
|
||||
|
||||
enum {
|
||||
ButtonUp = 0
|
||||
ButtonUp = 0,
|
||||
ButtonDown = 1,
|
||||
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))
|
||||
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))
|
||||
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));
|
||||
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));
|
||||
std::get<ButtonBack>(dpadHackLastState) = std::get<ButtonBack>(state);
|
||||
std::get<ButtonBack>(lastState) = std::get<ButtonBack>(state);
|
||||
}
|
||||
|
||||
dpadLastState = state;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <tuple>
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "globals.h"
|
||||
@ -9,9 +7,10 @@
|
||||
#include "dpad.h"
|
||||
|
||||
namespace {
|
||||
|
||||
namespace dpad3wire
|
||||
{
|
||||
template<pin_t OUT, pin_t IN1, pin_t IN2>
|
||||
class DPadHackHelper
|
||||
class Helper
|
||||
{
|
||||
public:
|
||||
static constexpr auto OutPin = OUT;
|
||||
@ -20,17 +19,17 @@ public:
|
||||
|
||||
void begin();
|
||||
|
||||
DPadState read();
|
||||
dpad::State read();
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@ -55,13 +54,19 @@ DPadState DPadHackHelper<OUT, IN1, IN2>::read()
|
||||
return std::make_tuple(result0, result1, result2, result3);
|
||||
}
|
||||
|
||||
#ifdef FEATURE_3WIRESW
|
||||
DPadHackHelper<PINS_3WIRESW_OUT, PINS_3WIRESW_IN1, PINS_3WIRESW_IN2> dpadHack;
|
||||
#ifdef FEATURE_DPAD_3WIRESW
|
||||
Helper<PINS_DPAD_3WIRESW_OUT, PINS_DPAD_3WIRESW_IN1, PINS_DPAD_3WIRESW_IN2> helper;
|
||||
dpad::State lastState;
|
||||
|
||||
DPadState dpadHackLastState;
|
||||
void updateDpadHack()
|
||||
void init()
|
||||
{
|
||||
const auto state = dpadHack.read();
|
||||
helper.begin();
|
||||
}
|
||||
|
||||
void update()
|
||||
{
|
||||
const auto state = helper.read();
|
||||
const auto now = millis();
|
||||
|
||||
enum {
|
||||
ButtonUp = 3,
|
||||
@ -70,30 +75,31 @@ void updateDpadHack()
|
||||
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))
|
||||
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))
|
||||
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));
|
||||
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));
|
||||
std::get<ButtonBack>(dpadHackLastState) = std::get<ButtonBack>(state);
|
||||
std::get<ButtonBack>(lastState) = std::get<ButtonBack>(state);
|
||||
}
|
||||
|
||||
dpadHackLastState = state;
|
||||
lastState = state;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
14
src/main.cpp
14
src/main.cpp
@ -12,7 +12,7 @@
|
||||
#include "modes/tempomatmode.h"
|
||||
#include "screens.h"
|
||||
#include "dpad.h"
|
||||
#include "dpadHack.h"
|
||||
#include "dpad3wire.h"
|
||||
#include "rotary.h"
|
||||
#include "serialhandler.h"
|
||||
#include "ota.h"
|
||||
@ -46,11 +46,11 @@ void setup()
|
||||
initScreen();
|
||||
|
||||
#ifdef FEATURE_DPAD
|
||||
dpad.begin();
|
||||
dpad::init();
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_3WIRESW
|
||||
dpadHack.begin();
|
||||
#ifdef FEATURE_DPAD_3WIRESW
|
||||
dpad3wire::init();
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_ROTARY
|
||||
@ -139,11 +139,11 @@ void loop()
|
||||
const auto now = millis();
|
||||
|
||||
#ifdef FEATURE_DPAD
|
||||
updateDpad();
|
||||
dpad::update();
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_3WIRESW
|
||||
updateDpadHack();
|
||||
#ifdef FEATURE_DPAD_3WIRESW
|
||||
dpad3wire::update();
|
||||
#endif
|
||||
|
||||
if (!lastModeUpdate)
|
||||
|
Reference in New Issue
Block a user