This commit is contained in:
hg 2015-03-11 22:32:15 +01:00
parent 337eaa98e7
commit 279e3fa1a8

View File

@ -15,6 +15,8 @@
#include "display.h"
class SwitchPort2 {
public:
SwitchPort2(uint16_t bit) : m_bit(bit), m_state(0), m_cnt(0) {
@ -62,41 +64,95 @@ private:
};
SwitchPort2 switch1 = SwitchPort2(BIT0);
SwitchPort2 switch2 = SwitchPort2(BIT1);
SwitchPort2 switch3 = SwitchPort2(BIT2);
SwitchPort2 switch4 = SwitchPort2(BIT3);
const uint8_t LED_RED_PIN = BIT5;
const uint8_t LED_GREEN_PIN = BIT4;
typedef enum { e_OFF, e_RED, e_GREEN } LedColor;
void hmiInit() {
P1DIR |= LED_RED_PIN | LED_GREEN_PIN;
P1OUT |= LED_RED_PIN | LED_GREEN_PIN;
spiInit();
dispInit();
}
void setLed(LedColor ledColor) {
switch (ledColor) {
case e_GREEN:
P1OUT |= LED_RED_PIN;
P1OUT &= ~LED_GREEN_PIN;
break;
case e_RED:
P1OUT |= LED_GREEN_PIN;
P1OUT &= ~LED_RED_PIN;
break;
case e_OFF:
default:
P1OUT |= LED_RED_PIN | LED_GREEN_PIN;
break;
}
}
void hmiExec() {
static float savedVoltage = 0.0;
static bool enabled = false;
static uint8_t dispState = 0;
const uint8_t MAX_DISP_STATE = 1;
if (switch1.get()) {
if (enabled) {
enabled = false;
setLed(e_OFF);
setUDes(0);
} else {
enabled = true;
setLed(e_GREEN);
setUDes(savedVoltage);
}
}
if (enabled && switch2.get()) {
savedVoltage = getUDes() - 1.0;
if (switch2.get()) {
savedVoltage -= 1.0;
if (enabled) {
setUDes(savedVoltage);
}
if (enabled && switch3.get()) {
savedVoltage = getUDes() + 1.0;
}
if (switch3.get()) {
savedVoltage += 1.0;
if (enabled) {
setUDes(savedVoltage);
}
}
// if (switch4.get()) {
// dispState++;
// if (dispState > MAX_DISP_STATE) {
// dispState = 0;
// }
// }
static uint32_t cnt = 0;
cnt++;
if (cnt >= 10000) {
dispSetFloat(0, getUCur());
dispSetFloat(1, getUDes());
float dispValue;
switch (dispState) {
case 0:
dispValue = savedVoltage;
break;
case 1:
dispValue = getDutyCycle();
break;
default:
dispValue = 99999; // illegal value
}
dispSetFloat(1, dispValue);
cnt = 0;
}
}