Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
e4712619bb | |||
8ed8b35d77 | |||
c9745484d2 | |||
85d4af6ac2 | |||
8d1b633928 | |||
0e062197c7 | |||
bad81e35c7 |
1
.hgtags
1
.hgtags
@ -1 +1,2 @@
|
|||||||
42344dc8fbe5f47bc1fd863ad662974432801791 WORKS_0
|
42344dc8fbe5f47bc1fd863ad662974432801791 WORKS_0
|
||||||
|
3bbe6390ccb3253431563b0bd4320478e893517b WORKS_0a
|
||||||
|
@ -34,3 +34,10 @@ void debugWrite(uint16_t o) {
|
|||||||
DEBUG_OUT_REG |= DEBUG_CS;
|
DEBUG_OUT_REG |= DEBUG_CS;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void debugWrite32(uint32_t o) {
|
||||||
|
uint16_t d1 = (uint16_t) (o & 0x0000ffff);
|
||||||
|
uint16_t d2 = (uint16_t) ((o & 0xffff0000) >> 16);
|
||||||
|
debugWrite(d1);
|
||||||
|
debugWrite(d2);
|
||||||
|
}
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
void debugInit();
|
void debugInit();
|
||||||
void debugWrite(uint16_t o);
|
void debugWrite(uint16_t o);
|
||||||
|
void debugWrite32(uint32_t o);
|
||||||
|
|
||||||
|
|
||||||
#endif /* DEBUG_H_ */
|
#endif /* DEBUG_H_ */
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
|
||||||
volatile uint32_t tickCnt = 0;
|
volatile uint32_t tickCnt = 0;
|
||||||
@ -106,23 +107,11 @@ bool engineDecPwmValue() {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool engineIncOffTime() {
|
|
||||||
offTime += STEP_100ms;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool engineIncOnTime() {
|
bool engineIncOnTime() {
|
||||||
return false;
|
|
||||||
onTime += STEP_100ms;
|
onTime += STEP_100ms;
|
||||||
}
|
debugWrite(0x0001);
|
||||||
|
debugWrite32(onTime);
|
||||||
bool engineDecOffTime() {
|
return false;
|
||||||
bool res = true;
|
|
||||||
if (offTime != 0) {
|
|
||||||
offTime -= STEP_100ms;
|
|
||||||
res = false;
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool engineDecOnTime() {
|
bool engineDecOnTime() {
|
||||||
@ -131,9 +120,30 @@ bool engineDecOnTime() {
|
|||||||
onTime -= STEP_100ms;
|
onTime -= STEP_100ms;
|
||||||
res = false;
|
res = false;
|
||||||
}
|
}
|
||||||
|
debugWrite(0x0002);
|
||||||
|
debugWrite32(onTime);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool engineIncOffTime() {
|
||||||
|
offTime += STEP_100ms;
|
||||||
|
debugWrite(0x0003);
|
||||||
|
debugWrite32(offTime);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool engineDecOffTime() {
|
||||||
|
bool res = true;
|
||||||
|
if (offTime != 0) {
|
||||||
|
offTime -= STEP_100ms;
|
||||||
|
res = false;
|
||||||
|
}
|
||||||
|
debugWrite(0x0004);
|
||||||
|
debugWrite32(offTime);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
uint32_t getMillis() {
|
uint32_t getMillis() {
|
||||||
return millis;
|
return millis;
|
||||||
}
|
}
|
||||||
|
90
src/hmi.cpp
90
src/hmi.cpp
@ -33,20 +33,20 @@ public:
|
|||||||
break;
|
break;
|
||||||
case STATE_BUTTON_RELEASED:
|
case STATE_BUTTON_RELEASED:
|
||||||
duration = getMillis() - m_timestamp;
|
duration = getMillis() - m_timestamp;
|
||||||
{
|
// {
|
||||||
uint16_t d1 = (uint16_t) (duration & 0x0000ffff);
|
// uint16_t d1 = (uint16_t) (duration & 0x0000ffff);
|
||||||
uint16_t d2 = (uint16_t) ((duration & 0xffff0000) >> 16);
|
// uint16_t d2 = (uint16_t) ((duration & 0xffff0000) >> 16);
|
||||||
debugWrite(d1);
|
// debugWrite(d1);
|
||||||
debugWrite(d2);
|
// debugWrite(d2);
|
||||||
}
|
// }
|
||||||
if ((duration >= LOWER_SHORT_TIME) && (duration <= UPPER_SHORT_TIME)) {
|
if ((duration >= LOWER_SHORT_TIME) && (duration <= UPPER_SHORT_TIME)) {
|
||||||
debugWrite(0x003);
|
// debugWrite(0x003);
|
||||||
m_state = STATE_SHORT;
|
m_state = STATE_SHORT;
|
||||||
} else if (duration > UPPER_SHORT_TIME) {
|
} else if (duration > UPPER_SHORT_TIME) {
|
||||||
debugWrite(0x004);
|
// debugWrite(0x004);
|
||||||
m_state = STATE_LONG;
|
m_state = STATE_LONG;
|
||||||
} else {
|
} else {
|
||||||
debugWrite(0x005);
|
// debugWrite(0x005);
|
||||||
m_state = STATE_IDLE;
|
m_state = STATE_IDLE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -77,9 +77,11 @@ class SwitchPort2 : public SwitchPort {
|
|||||||
public:
|
public:
|
||||||
SwitchPort2(uint16_t bit) : SwitchPort() {
|
SwitchPort2(uint16_t bit) : SwitchPort() {
|
||||||
m_bit = bit;
|
m_bit = bit;
|
||||||
P2REN |= bit;
|
|
||||||
P2DIR &= ~bit;
|
P2DIR &= ~bit;
|
||||||
|
P2REN |= bit;
|
||||||
|
P2OUT |= bit;
|
||||||
P2SEL &= ~bit;
|
P2SEL &= ~bit;
|
||||||
|
P2SEL2 &= ~bit;
|
||||||
};
|
};
|
||||||
virtual bool getSwitchState() {
|
virtual bool getSwitchState() {
|
||||||
bool a = P2IN & m_bit;
|
bool a = P2IN & m_bit;
|
||||||
@ -96,9 +98,11 @@ class SwitchPort1 : public SwitchPort {
|
|||||||
public:
|
public:
|
||||||
SwitchPort1(uint16_t bit) : SwitchPort() {
|
SwitchPort1(uint16_t bit) : SwitchPort() {
|
||||||
m_bit = bit;
|
m_bit = bit;
|
||||||
P1REN |= bit;
|
|
||||||
P1DIR &= ~bit;
|
P1DIR &= ~bit;
|
||||||
|
P1REN |= bit;
|
||||||
|
P1OUT |= bit;
|
||||||
P1SEL &= ~bit;
|
P1SEL &= ~bit;
|
||||||
|
P1SEL2 &= ~bit;
|
||||||
};
|
};
|
||||||
virtual bool getSwitchState() {
|
virtual bool getSwitchState() {
|
||||||
return P1IN & m_bit;
|
return P1IN & m_bit;
|
||||||
@ -121,33 +125,34 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
virtual void set(bool v) {};
|
virtual void set(bool v) {};
|
||||||
|
bool isIdle() { return m_state == STATE_IDLE; };
|
||||||
void exec() {
|
void exec() {
|
||||||
switch (m_state) {
|
switch (m_state) {
|
||||||
case STATE_IDLE:
|
case STATE_IDLE:
|
||||||
break;
|
break;
|
||||||
case STATE_START:
|
case STATE_START:
|
||||||
set(true);
|
set(true);
|
||||||
m_startTime = getMillis();
|
m_startTime = getMillis();
|
||||||
m_state = STATE_ON;
|
m_state = STATE_ON;
|
||||||
break;
|
break;
|
||||||
case STATE_ON:
|
case STATE_ON:
|
||||||
if (getMillis() > m_timeout + m_startTime) {
|
if (getMillis() > m_timeout + m_startTime) {
|
||||||
m_state = STATE_OFF;
|
m_state = STATE_OFF;
|
||||||
}
|
}
|
||||||
m_timeout--;
|
m_timeout--;
|
||||||
break;
|
break;
|
||||||
case STATE_OFF:
|
case STATE_OFF:
|
||||||
set(false);
|
set(false);
|
||||||
m_state = STATE_IDLE;
|
m_state = STATE_IDLE;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
m_state = STATE_IDLE;
|
m_state = STATE_IDLE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
static const uint32_t LED_WAIT_TIME_SHORT = 500;
|
static const uint32_t LED_WAIT_TIME_SHORT = 500;
|
||||||
static const uint32_t LED_WAIT_TIME_LONG = 5000;
|
static const uint32_t LED_WAIT_TIME_LONG = 50000;
|
||||||
enum e_state { STATE_IDLE, STATE_START, STATE_ON, STATE_OFF };
|
enum e_state { STATE_IDLE, STATE_START, STATE_ON, STATE_OFF };
|
||||||
e_state m_state;
|
e_state m_state;
|
||||||
uint32_t m_timeout;
|
uint32_t m_timeout;
|
||||||
@ -202,6 +207,27 @@ void hmiInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void hmiExec() {
|
void hmiExec() {
|
||||||
|
static bool starting = true;
|
||||||
|
if (starting) {
|
||||||
|
ledGreen.start(Led::FLASH_LONG);
|
||||||
|
while (! ledGreen.isIdle()) {
|
||||||
|
ledGreen.exec();
|
||||||
|
}
|
||||||
|
ledRed.start(Led::FLASH_LONG);
|
||||||
|
while (! ledRed.isIdle()) {
|
||||||
|
ledRed.exec();
|
||||||
|
}
|
||||||
|
ledGreen.start(Led::FLASH_LONG);
|
||||||
|
while (! ledGreen.isIdle()) {
|
||||||
|
ledGreen.exec();
|
||||||
|
}
|
||||||
|
ledRed.start(Led::FLASH_LONG);
|
||||||
|
while (! ledRed.isIdle()) {
|
||||||
|
ledRed.exec();
|
||||||
|
}
|
||||||
|
starting = false;
|
||||||
|
}
|
||||||
|
|
||||||
SwitchPort::e_switchResult switchResult = intensitySwitch.get();
|
SwitchPort::e_switchResult switchResult = intensitySwitch.get();
|
||||||
if (switchResult == SwitchPort::SWITCH_SHORT) {
|
if (switchResult == SwitchPort::SWITCH_SHORT) {
|
||||||
if (engineIncPwmValue()) {
|
if (engineIncPwmValue()) {
|
||||||
|
Reference in New Issue
Block a user