seems to work now

This commit is contained in:
hg
2015-03-14 19:10:15 +01:00
parent 279e3fa1a8
commit 1a850d01b5

View File

@ -17,15 +17,24 @@
class SwitchPort2 { class SwitchPort {
public: public:
SwitchPort2(uint16_t bit) : m_bit(bit), m_state(0), m_cnt(0) { SwitchPort(uint16_t bit, uint16_t inRegister) : m_bit(bit), m_state(0), m_cnt(0), m_inRegister(inRegister) {
P2REN |= m_bit;
}; };
bool get() { bool get() {
bool result = false; bool result = false;
bool inValue = false;
switch (m_inRegister) {
case 1:
inValue = P1IN & m_bit;
break;
case 2:
inValue = P2IN & m_bit;
break;
}
switch (m_state) { switch (m_state) {
case 0: case 0:
if (P2IN & m_bit) { if (P2IN & m_bit) {
m_cnt = 0; m_cnt = 0;
} else { } else {
@ -61,14 +70,30 @@ private:
uint16_t m_bit; uint16_t m_bit;
uint8_t m_state; uint8_t m_state;
uint16_t m_cnt; uint16_t m_cnt;
uint8_t m_inRegister;
}; };
class SwitchPort2 : public SwitchPort {
public:
SwitchPort2(uint16_t bit) : SwitchPort(bit, 2) {
P2REN |= bit;
P2DIR &= ~bit;
P2SEL &= ~bit;
};
};
class SwitchPort1 : public SwitchPort {
public:
SwitchPort1(uint16_t bit) : SwitchPort(bit, 1) {
P1REN |= bit;
P1DIR &= ~bit;
P1SEL &= ~bit;
};
};
SwitchPort switch1 = SwitchPort2(BIT0);
SwitchPort2 switch1 = SwitchPort2(BIT0); SwitchPort switch2 = SwitchPort2(BIT1);
SwitchPort2 switch2 = SwitchPort2(BIT1); SwitchPort switch3 = SwitchPort2(BIT2);
SwitchPort2 switch3 = SwitchPort2(BIT2); SwitchPort switch4 = SwitchPort2(BIT3);
SwitchPort2 switch4 = SwitchPort2(BIT3);
const uint8_t LED_RED_PIN = BIT5; const uint8_t LED_RED_PIN = BIT5;
@ -130,16 +155,16 @@ void hmiExec() {
setUDes(savedVoltage); setUDes(savedVoltage);
} }
} }
// if (switch4.get()) { if (switch4.get()) {
// dispState++; dispState++;
// if (dispState > MAX_DISP_STATE) { if (dispState > MAX_DISP_STATE) {
// dispState = 0; dispState = 0;
// } }
// } }
static uint32_t cnt = 0; static uint32_t cnt = 0;
cnt++; cnt++;
if (cnt >= 10000) { if (cnt >= 5000) {
dispSetFloat(0, getUCur()); dispSetFloat(0, getUCur());
float dispValue; float dispValue;
switch (dispState) { switch (dispState) {