Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0264be3c5 | ||
|
|
4fb7a70e3c |
@@ -8,40 +8,23 @@
|
|||||||
/* Functions for access to data */
|
/* Functions for access to data */
|
||||||
extern volatile uint32_t system_Ticks;
|
extern volatile uint32_t system_Ticks;
|
||||||
void delayMs(uint32_t ticks);
|
void delayMs(uint32_t ticks);
|
||||||
extern volatile uint32_t lastKeyPress;
|
|
||||||
extern volatile uint32_t lastMovement;
|
extern volatile uint32_t lastMovement;
|
||||||
|
|
||||||
extern volatile uint8_t keyState;
|
|
||||||
extern volatile uint8_t rawKeys;
|
extern volatile uint8_t rawKeys;
|
||||||
|
|
||||||
inline uint32_t millis() {
|
inline uint32_t millis() {
|
||||||
return system_Ticks;
|
return system_Ticks;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint32_t getLastButtonPress() {
|
|
||||||
return lastKeyPress;
|
|
||||||
}
|
|
||||||
inline void resetLastButtonPress() {
|
|
||||||
lastKeyPress = millis();
|
|
||||||
|
|
||||||
}
|
|
||||||
inline void resetButtons() {
|
|
||||||
keyState = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline uint32_t getLastMovement() {
|
inline uint32_t getLastMovement() {
|
||||||
return lastMovement;
|
return lastMovement;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint16_t getButtons() {
|
uint8_t getButtons();
|
||||||
return keyState;
|
uint32_t getLastButtonPress();
|
||||||
}
|
|
||||||
inline uint16_t getRawButtons() {
|
inline uint16_t getRawButtons() {
|
||||||
return rawKeys;
|
return rawKeys;
|
||||||
}
|
}
|
||||||
inline void restoreButtons() {
|
|
||||||
keyState = getRawButtons();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*IRQ prototypes*/
|
/*IRQ prototypes*/
|
||||||
void NMI_Handler(void);
|
void NMI_Handler(void);
|
||||||
|
|||||||
@@ -3,9 +3,10 @@
|
|||||||
#include "I2C.h"
|
#include "I2C.h"
|
||||||
|
|
||||||
volatile uint32_t system_Ticks;
|
volatile uint32_t system_Ticks;
|
||||||
volatile uint32_t lastKeyPress; //millis() at the last button event
|
volatile uint32_t BkeyChange; //millis() at the last button event
|
||||||
volatile uint8_t keyState; //tracks the button status
|
volatile uint32_t AkeyChange;
|
||||||
volatile uint8_t rawKeys;
|
volatile uint8_t rawKeys;
|
||||||
|
volatile uint8_t LongKeys;
|
||||||
volatile uint32_t lastMovement; //millis() at last movement event
|
volatile uint32_t lastMovement; //millis() at last movement event
|
||||||
|
|
||||||
//Delay in milliseconds using systemTick
|
//Delay in milliseconds using systemTick
|
||||||
@@ -14,6 +15,89 @@ void delayMs(uint32_t ticks) {
|
|||||||
while (millis() < endtime)
|
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) {
|
void NMI_Handler(void) {
|
||||||
;
|
;
|
||||||
@@ -57,23 +141,19 @@ void EXTI9_5_IRQHandler(void) {
|
|||||||
//Line 5 == movement
|
//Line 5 == movement
|
||||||
if (EXTI_GetITStatus(EXTI_Line9) != RESET) {
|
if (EXTI_GetITStatus(EXTI_Line9) != RESET) {
|
||||||
if (GPIO_ReadInputDataBit(GPIOA, KEY_A) == SET) {
|
if (GPIO_ReadInputDataBit(GPIOA, KEY_A) == SET) {
|
||||||
keyState &= ~(BUT_A);
|
|
||||||
rawKeys &= ~BUT_A;
|
rawKeys &= ~BUT_A;
|
||||||
} else {
|
} else {
|
||||||
keyState |= BUT_A;
|
|
||||||
rawKeys |= BUT_A;
|
rawKeys |= BUT_A;
|
||||||
lastKeyPress = millis();
|
|
||||||
}
|
}
|
||||||
|
AkeyChange = millis();
|
||||||
EXTI_ClearITPendingBit(EXTI_Line9);
|
EXTI_ClearITPendingBit(EXTI_Line9);
|
||||||
} else if (EXTI_GetITStatus(EXTI_Line6) != RESET) {
|
} else if (EXTI_GetITStatus(EXTI_Line6) != RESET) {
|
||||||
if (GPIO_ReadInputDataBit(GPIOA, KEY_B) == SET) {
|
if (GPIO_ReadInputDataBit(GPIOA, KEY_B) == SET) {
|
||||||
keyState &= ~(BUT_B);
|
|
||||||
rawKeys &= ~BUT_B;
|
rawKeys &= ~BUT_B;
|
||||||
} else {
|
} else {
|
||||||
keyState |= BUT_B;
|
|
||||||
rawKeys |= BUT_B;
|
rawKeys |= BUT_B;
|
||||||
lastKeyPress = millis();
|
|
||||||
}
|
}
|
||||||
|
BkeyChange = millis();
|
||||||
EXTI_ClearITPendingBit(EXTI_Line6);
|
EXTI_ClearITPendingBit(EXTI_Line6);
|
||||||
} else if (EXTI_GetITStatus(EXTI_Line5) != RESET) { //Movement Event
|
} else if (EXTI_GetITStatus(EXTI_Line5) != RESET) { //Movement Event
|
||||||
lastMovement = millis();
|
lastMovement = millis();
|
||||||
|
|||||||
@@ -26,14 +26,7 @@ settingsPageEnum settingsPage;
|
|||||||
void ProcessUI() {
|
void ProcessUI() {
|
||||||
uint8_t Buttons = getButtons(); //read the buttons status
|
uint8_t Buttons = getButtons(); //read the buttons status
|
||||||
static uint32_t lastModeChange = 0;
|
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) {
|
switch (operatingMode) {
|
||||||
case STARTUP:
|
case STARTUP:
|
||||||
|
|||||||
@@ -141,6 +141,7 @@ void GPIO_Init_OLED(void) {
|
|||||||
Description: Initializes the Oled screen
|
Description: Initializes the Oled screen
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
void Init_Oled(uint8_t leftHanded) {
|
void Init_Oled(uint8_t leftHanded) {
|
||||||
|
|
||||||
currentOrientation = leftHanded;
|
currentOrientation = leftHanded;
|
||||||
u8 param_len;
|
u8 param_len;
|
||||||
OLED_RST();
|
OLED_RST();
|
||||||
@@ -148,11 +149,11 @@ void Init_Oled(uint8_t leftHanded) {
|
|||||||
OLED_ACT(); //Toggling reset to reset the oled
|
OLED_ACT(); //Toggling reset to reset the oled
|
||||||
delayMs(5);
|
delayMs(5);
|
||||||
param_len = 46;
|
param_len = 46;
|
||||||
if (leftHanded) {
|
if (leftHanded == 1) {
|
||||||
OLED_Setup_Array[11] = 0xC8;
|
OLED_Setup_Array[11] = 0xC8;
|
||||||
OLED_Setup_Array[19] = 0xA1;
|
OLED_Setup_Array[19] = 0xA1;
|
||||||
displayOffset = 0;
|
displayOffset = 0;
|
||||||
} else {
|
} else if (leftHanded == 0) {
|
||||||
OLED_Setup_Array[11] = 0xC0;
|
OLED_Setup_Array[11] = 0xC0;
|
||||||
OLED_Setup_Array[19] = 0x40;
|
OLED_Setup_Array[19] = 0x40;
|
||||||
displayOffset = 32;
|
displayOffset = 32;
|
||||||
@@ -284,6 +285,8 @@ void OLED_DrawSymbol(uint8_t x, uint8_t symbol) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OLED_SetOrientation(uint8_t ori) {
|
void OLED_SetOrientation(uint8_t ori) {
|
||||||
|
if (ori > 1)
|
||||||
|
return;
|
||||||
if (ori != currentOrientation) {
|
if (ori != currentOrientation) {
|
||||||
Init_Oled(ori);
|
Init_Oled(ori);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user