works better now, not perfect

This commit is contained in:
hg 2016-02-15 22:43:12 +01:00
parent a57b0bdb03
commit 1d8c17b264
2 changed files with 37 additions and 8 deletions

View File

@ -53,5 +53,16 @@
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="refreshScope"/>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets">
<buildTargets>
<target name="build" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>${MSP430MAKE}</buildCommand>
<buildArguments/>
<buildTarget>build</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
</buildTargets>
</storageModule>
</cproject>

View File

@ -15,7 +15,7 @@ public:
enum e_switchResult { SWITCH_IDLE, SWITCH_SHORT, SWITCH_LONG };
SwitchPort() : m_state(STATE_IDLE) {
};
virtual bool getSwitchState() { return false; };
virtual bool getSwitchState() { debugWrite(0x009); return false; };
e_switchResult get() {
e_switchResult result = SWITCH_IDLE;
bool inValue = getSwitchState();
@ -23,22 +23,33 @@ public:
switch (m_state) {
case STATE_IDLE:
if (inValue == false) {
// debugWrite(0x001);
m_state = STATE_BUTTON_PRESSED;
m_timestamp = getMillis();
}
break;
case STATE_BUTTON_PRESSED:
if (inValue == true) {
// debugWrite(0x002);
m_state = STATE_BUTTON_RELEASED;
}
break;
case STATE_BUTTON_RELEASED:
duration = m_timestamp - getMillis();
duration = getMillis() - m_timestamp;
// {
// uint16_t d1 = (uint16_t) (duration & 0x0000ffff);
// uint16_t d2 = (uint16_t) ((duration & 0xffff0000) >> 16);
// debugWrite(d1);
// debugWrite(d2);
// }
if ((duration >= LOWER_SHORT_TIME) && (duration <= UPPER_SHORT_TIME)) {
// debugWrite(0x003);
m_state = STATE_SHORT;
} else if (duration > UPPER_SHORT_TIME) {
// debugWrite(0x004);
m_state = STATE_LONG;
} else {
// debugWrite(0x005);
m_state = STATE_IDLE;
}
break;
@ -65,16 +76,22 @@ private:
class SwitchPort2 : public SwitchPort {
public:
SwitchPort2(uint16_t bit) : SwitchPort(), m_bit(bit) {
SwitchPort2(uint16_t bit) : SwitchPort() {
m_bit = bit;
P2REN |= bit;
P2DIR &= ~bit;
P2SEL &= ~bit;
};
virtual bool getSwitchState() {
return P2IN & m_bit;
bool a = P2IN & m_bit;
// if (a)
// debugWrite(0x00A);
// else
// debugWrite(0x00B);
return a;
};
private:
bool m_bit;
uint16_t m_bit;
};
class SwitchPort1 : public SwitchPort {
public:
@ -87,7 +104,7 @@ public:
return P1IN & m_bit;
};
private:
bool m_bit;
uint16_t m_bit;
};
@ -129,7 +146,7 @@ void hmiExec() {
engineSetPwmValue(intensity);
}
/*
if (onTimeSwitch.get() == SwitchPort::SWITCH_SHORT) {
engineIncOnTime();
} else if (onTimeSwitch.get() == SwitchPort::SWITCH_LONG) {
@ -141,4 +158,5 @@ void hmiExec() {
} else if (onTimeSwitch.get() == SwitchPort::SWITCH_LONG) {
engineDecOffTime();
}
*/
}