separation of concerns
This commit is contained in:
61
src/hmi.cpp
61
src/hmi.cpp
@ -6,9 +6,6 @@
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
const uint32_t LOWER_SHORT_TIME = 100;
|
||||
const uint32_t UPPER_SHORT_TIME = 300;
|
||||
const uint32_t LED_WAIT_TIME = 500;
|
||||
|
||||
class SwitchPort {
|
||||
public:
|
||||
@ -69,6 +66,8 @@ public:
|
||||
return result;
|
||||
};
|
||||
private:
|
||||
static const uint32_t LOWER_SHORT_TIME = 100;
|
||||
static const uint32_t UPPER_SHORT_TIME = 300;
|
||||
enum e_state { STATE_IDLE, STATE_BUTTON_PRESSED, STATE_BUTTON_RELEASED, STATE_SHORT, STATE_LONG };
|
||||
e_state m_state;
|
||||
uint32_t m_timestamp;
|
||||
@ -146,6 +145,8 @@ public:
|
||||
}
|
||||
}
|
||||
private:
|
||||
static const uint32_t LED_WAIT_TIME_SHORT = 500;
|
||||
static const uint32_t LED_WAIT_TIME_LONG = 1000;
|
||||
enum e_state { STATE_IDLE, STATE_START, STATE_ON, STATE_OFF };
|
||||
e_state m_state;
|
||||
uint32_t m_timeout;
|
||||
@ -194,50 +195,52 @@ SwitchPort2 offTimeSwitch = SwitchPort2(BIT3);
|
||||
Led1 ledGreen = Led1(BIT5);
|
||||
Led1 ledRed = Led1(BIT4);
|
||||
|
||||
uint16_t intensity = 0;
|
||||
uint16_t maxIntensity = 0;
|
||||
uint16_t intensityStep = 0;
|
||||
const uint16_t intensityStepCnt = 16;
|
||||
|
||||
|
||||
void hmiInit() {
|
||||
maxIntensity = engineMaxPwmValue();
|
||||
intensityStep = maxIntensity / intensityStepCnt;
|
||||
}
|
||||
|
||||
void hmiExec() {
|
||||
if (intensitySwitch.get() == SwitchPort::SWITCH_SHORT) {
|
||||
intensity += intensityStep;
|
||||
if (intensity > maxIntensity) {
|
||||
intensity = maxIntensity;
|
||||
if (engineIncPwmValue()) {
|
||||
ledGreen.start(Led::FLASH_SHORT);
|
||||
} else {
|
||||
ledGreen.start(Led::FLASH_LONG);
|
||||
}
|
||||
ledGreen.start(Led::FLASH_SHORT);
|
||||
debugWrite(intensity);
|
||||
engineSetPwmValue(intensity);
|
||||
} else if (intensitySwitch.get() == SwitchPort::SWITCH_LONG) {
|
||||
if (intensity != 0) {
|
||||
intensity -= intensityStep;
|
||||
if (engineDecPwmValue()) {
|
||||
ledRed.start(Led::FLASH_SHORT);
|
||||
} else {
|
||||
ledRed.start(Led::FLASH_LONG);
|
||||
}
|
||||
ledRed.start(Led::FLASH_SHORT);
|
||||
debugWrite(intensity);
|
||||
engineSetPwmValue(intensity);
|
||||
}
|
||||
|
||||
|
||||
if (onTimeSwitch.get() == SwitchPort::SWITCH_SHORT) {
|
||||
engineIncOnTime();
|
||||
ledGreen.start(Led::FLASH_SHORT);
|
||||
if (engineIncOnTime()) {
|
||||
ledGreen.start(Led::FLASH_SHORT);
|
||||
} else {
|
||||
ledGreen.start(Led::FLASH_LONG);
|
||||
}
|
||||
} else if (onTimeSwitch.get() == SwitchPort::SWITCH_LONG) {
|
||||
engineDecOnTime();
|
||||
ledRed.start(Led::FLASH_SHORT);
|
||||
if (engineDecOnTime()) {
|
||||
ledRed.start(Led::FLASH_SHORT);
|
||||
} else {
|
||||
ledRed.start(Led::FLASH_LONG);
|
||||
}
|
||||
}
|
||||
|
||||
if (offTimeSwitch.get() == SwitchPort::SWITCH_SHORT) {
|
||||
engineIncOffTime();
|
||||
ledGreen.start(Led::FLASH_SHORT);
|
||||
if (engineIncOffTime()) {
|
||||
ledGreen.start(Led::FLASH_SHORT);
|
||||
} else {
|
||||
ledGreen.start(Led::FLASH_LONG);
|
||||
}
|
||||
} else if (onTimeSwitch.get() == SwitchPort::SWITCH_LONG) {
|
||||
engineDecOffTime();
|
||||
ledRed.start(Led::FLASH_SHORT);
|
||||
if (engineDecOffTime()) {
|
||||
ledRed.start(Led::FLASH_SHORT);
|
||||
} else {
|
||||
ledRed.start(Led::FLASH_LONG);
|
||||
}
|
||||
}
|
||||
|
||||
ledRed.exec();
|
||||
|
Reference in New Issue
Block a user