diff options
author | Ben V. Brown <[email protected]> | 2017-07-30 21:25:27 +1000 |
---|---|---|
committer | Ben V. Brown <[email protected]> | 2017-07-30 21:25:27 +1000 |
commit | b0264be3c556a73ea4d8ffabd161e799bfcad109 (patch) | |
tree | 1546b92f73a8bcbfab43c907011c1c9fa285fc82 | |
parent | 4fb7a70e3cb04c9be1b65c4e68285171674e5eca (diff) | |
download | IronOS-1.16.2.tar.gz IronOS-1.16.2.zip |
Better button auto-repeatv1.16.2
-rw-r--r-- | workspace/ts100/inc/Interrupt.h | 21 | ||||
-rw-r--r-- | workspace/ts100/src/Interrupt.c | 96 | ||||
-rw-r--r-- | workspace/ts100/src/Modes.c | 9 |
3 files changed, 91 insertions, 35 deletions
diff --git a/workspace/ts100/inc/Interrupt.h b/workspace/ts100/inc/Interrupt.h index 84464bba..e66cdb0c 100644 --- a/workspace/ts100/inc/Interrupt.h +++ b/workspace/ts100/inc/Interrupt.h @@ -8,40 +8,23 @@ /* Functions for access to data */
extern volatile uint32_t system_Ticks;
void delayMs(uint32_t ticks);
-extern volatile uint32_t lastKeyPress;
extern volatile uint32_t lastMovement;
-extern volatile uint8_t keyState;
extern volatile uint8_t rawKeys;
inline uint32_t millis() {
return system_Ticks;
}
-inline uint32_t getLastButtonPress() {
- return lastKeyPress;
-}
-inline void resetLastButtonPress() {
- lastKeyPress = millis();
-
-}
-inline void resetButtons() {
- keyState = 0;
-}
-
inline uint32_t getLastMovement() {
return lastMovement;
}
-inline uint16_t getButtons() {
- return keyState;
-}
+uint8_t getButtons();
+uint32_t getLastButtonPress();
inline uint16_t getRawButtons() {
return rawKeys;
}
-inline void restoreButtons() {
- keyState = getRawButtons();
-}
/*IRQ prototypes*/
void NMI_Handler(void);
diff --git a/workspace/ts100/src/Interrupt.c b/workspace/ts100/src/Interrupt.c index 0786aefa..bbe34e86 100644 --- a/workspace/ts100/src/Interrupt.c +++ b/workspace/ts100/src/Interrupt.c @@ -3,9 +3,10 @@ #include "I2C.h"
volatile uint32_t system_Ticks;
-volatile uint32_t lastKeyPress; //millis() at the last button event
-volatile uint8_t keyState; //tracks the button status
+volatile uint32_t BkeyChange; //millis() at the last button event
+volatile uint32_t AkeyChange;
volatile uint8_t rawKeys;
+volatile uint8_t LongKeys;
volatile uint32_t lastMovement; //millis() at last movement event
//Delay in milliseconds using systemTick
@@ -14,6 +15,89 @@ void delayMs(uint32_t ticks) { while (millis() < endtime)
;
}
+uint32_t getLastButtonPress() {
+ if (BkeyChange > AkeyChange)
+ return BkeyChange;
+ return AkeyChange;
+}
+uint8_t getButtons() {
+ //We want to check the times for the lat buttons & also the rawKeys state
+ //If a key has just gone down, rawKeys & KEY ==1
+ uint8_t out = 0;
+ if (millis() - AkeyChange > 30) {
+ if (LongKeys & BUT_A) {
+ if (rawKeys & BUT_A) {
+ if (millis() - AkeyChange > 800) {
+ out |= BUT_A;
+ AkeyChange = millis();
+ LongKeys &= ~BUT_A;
+
+ LongKeys |= (BUT_A << 2);
+ }
+ } else {
+ LongKeys &= ~BUT_A;
+ LongKeys &= ~(BUT_A << 2);
+ }
+
+ } else if (LongKeys & (BUT_A << 2)) {
+ if (rawKeys & BUT_A) {
+ if (millis() - AkeyChange > 300) {
+ out |= BUT_A;
+ AkeyChange = millis();
+ }
+ } else {
+ LongKeys &= ~BUT_A;
+ LongKeys &= ~(BUT_A << 2);
+ }
+ } else {
+ if (rawKeys & BUT_A) {
+ //The key is down
+ out |= BUT_A;
+ LongKeys |= BUT_A;
+ } else {
+ //The key has been lifted
+ LongKeys &= ~BUT_A;
+ LongKeys &= ~(BUT_A << 2);
+ }
+ }
+ }
+ if (millis() - BkeyChange > 30) {
+ if (LongKeys & BUT_B) {
+ if (rawKeys & BUT_B) {
+ if (millis() - BkeyChange > 800) {
+ out |= BUT_B;
+ BkeyChange = millis();
+ LongKeys |= (BUT_B << 2);
+ LongKeys &= ~BUT_B;
+ }
+ } else {
+ LongKeys &= ~BUT_B;
+ LongKeys &= ~(BUT_B << 2);
+ }
+ } else if (LongKeys & (BUT_B << 2)) {
+ if (rawKeys & BUT_B) {
+ if (millis() - BkeyChange > 300) {
+ out |= BUT_B;
+ BkeyChange = millis();
+ }
+ } else {
+ LongKeys &= ~BUT_B;
+ LongKeys &= ~(BUT_B << 2);
+ }
+ } else {
+ if (rawKeys & BUT_B) {
+ //The key is down
+ out |= BUT_B;
+ LongKeys |= BUT_B;
+ } else {
+ //The key has been lifted
+ LongKeys &= ~BUT_B;
+ LongKeys &= ~(BUT_B << 2);
+ }
+ }
+ }
+ return out;
+}
void NMI_Handler(void) {
;
@@ -57,23 +141,19 @@ void EXTI9_5_IRQHandler(void) { //Line 5 == movement
if (EXTI_GetITStatus(EXTI_Line9) != RESET) {
if (GPIO_ReadInputDataBit(GPIOA, KEY_A) == SET) {
- keyState &= ~(BUT_A);
rawKeys &= ~BUT_A;
} else {
- keyState |= BUT_A;
rawKeys |= BUT_A;
- lastKeyPress = millis();
}
+ AkeyChange = millis();
EXTI_ClearITPendingBit(EXTI_Line9);
} else if (EXTI_GetITStatus(EXTI_Line6) != RESET) {
if (GPIO_ReadInputDataBit(GPIOA, KEY_B) == SET) {
- keyState &= ~(BUT_B);
rawKeys &= ~BUT_B;
} else {
- keyState |= BUT_B;
rawKeys |= BUT_B;
- lastKeyPress = millis();
}
+ BkeyChange = millis();
EXTI_ClearITPendingBit(EXTI_Line6);
} else if (EXTI_GetITStatus(EXTI_Line5) != RESET) { //Movement Event
lastMovement = millis();
diff --git a/workspace/ts100/src/Modes.c b/workspace/ts100/src/Modes.c index ec90e4b2..6d9588d4 100644 --- a/workspace/ts100/src/Modes.c +++ b/workspace/ts100/src/Modes.c @@ -26,14 +26,7 @@ settingsPageEnum settingsPage; void ProcessUI() { uint8_t Buttons = getButtons(); //read the buttons status static uint32_t lastModeChange = 0; - if (getRawButtons() && ((millis() - getLastButtonPress()) > 1000)) { - lastKeyPress = millis() - 700; - Buttons = getRawButtons(); - } else if (millis() - getLastButtonPress() < 100) { - Buttons = 0; - } else if (Buttons != 0) { - resetButtons(); - } + switch (operatingMode) { case STARTUP: |