Updates to wire up 5 way switch to gui slice UI on config screen

This commit is contained in:
KemoNine 2020-09-11 00:35:56 -04:00
parent 3479fec85d
commit aabfb0bd6b

View file

@ -58,6 +58,7 @@ BBQ10Keyboard keyboard;
#define KBD_SW_LF 0x03 #define KBD_SW_LF 0x03
#define KBD_SW_RT 0x04 #define KBD_SW_RT 0x04
#define KBD_SW_OK 0x05 #define KBD_SW_OK 0x05
CircularBuffer<int16_t,8> uiKeyBuffer;
// Upstream keyboard definitions that will be really important later // Upstream keyboard definitions that will be really important later
#define _REG_CFG 2 #define _REG_CFG 2
@ -92,6 +93,10 @@ gslc_tsElemRef* m_pElemStatusText = NULL;
gslc_tsElemRef* m_pElemText = NULL; gslc_tsElemRef* m_pElemText = NULL;
//<Save_References !End!> //<Save_References !End!>
// Keyboard map related
#define MAX_INPUT_MAP 5
gslc_tsInputMap m_asInputMap[MAX_INPUT_MAP];
// Define debug message function // Define debug message function
static int16_t DebugOut(char ch) { if (ch == (char)'\n') Serial.println(""); else Serial.write(ch); return 0; } static int16_t DebugOut(char ch) { if (ch == (char)'\n') Serial.println(""); else Serial.write(ch); return 0; }
@ -115,10 +120,30 @@ static int16_t DebugOut(char ch) { if (ch == (char)'\n') Serial.println(""); els
//<Tick Callback !Start!> //<Tick Callback !Start!>
//<Tick Callback !End!> //<Tick Callback !End!>
// Keyboard Input polling callback function
bool CbKbdPoll(void* pvGui, int16_t* pnPinInd, int16_t* pnPinVal) {
// Check for new keyboard events just in case
handlerKeyboard();
// If the key buffer is empty no events to process
if (uiKeyBuffer.isEmpty()) {
return false;
}
// Process a key that's on the key buffer for the UI event(s)
*pnPinInd = uiKeyBuffer.pop();
*pnPinVal = 1;
return true;
}
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
// GUI Slice debugging
gslc_InitDebug(&DebugOut);
// Setup red LED to indicate device is on (in case we disable NeoPixel battery level later) // Setup red LED to indicate device is on (in case we disable NeoPixel battery level later)
pinMode(3, OUTPUT); pinMode(3, OUTPUT);
digitalWrite(3, HIGH); digitalWrite(3, HIGH);
@ -145,12 +170,21 @@ void setup() {
Wire.begin(); Wire.begin();
keyboard.begin(); keyboard.begin();
keyboard.writeRegister(_REG_CFG, CFG_OVERFLOW_INT | CFG_KEY_INT | CFG_USE_MODS | CFG_REPORT_MODS); keyboard.writeRegister(_REG_CFG, CFG_OVERFLOW_INT | CFG_KEY_INT | CFG_USE_MODS | CFG_REPORT_MODS);
keyboard.setBacklight(0.5f); keyboard.setBacklight(0.5f);
// GUI Slice (TFT is setup through GUI Slice) // Init GUI Slicle
gslc_InitDebug(&DebugOut);
InitGUIslice_gen(); InitGUIslice_gen();
// Set the pin poll callback function
gslc_SetPinPollFunc(&m_gui, CbKbdPoll);
// Create the GUI input mapping (pin event to GUI action)
gslc_InitInputMap(&m_gui, m_asInputMap, MAX_INPUT_MAP);
gslc_InputMapAdd(&m_gui, GSLC_INPUT_PIN_ASSERT, KBD_SW_UP, GSLC_ACTION_FOCUS_NEXT, 0);
gslc_InputMapAdd(&m_gui, GSLC_INPUT_PIN_ASSERT, KBD_SW_DN, GSLC_ACTION_FOCUS_PREV, 0);
gslc_InputMapAdd(&m_gui, GSLC_INPUT_PIN_ASSERT, KBD_SW_LF, GSLC_ACTION_FOCUS_NEXT, 0);
gslc_InputMapAdd(&m_gui, GSLC_INPUT_PIN_ASSERT, KBD_SW_RT, GSLC_ACTION_FOCUS_PREV, 0);
gslc_InputMapAdd(&m_gui, GSLC_INPUT_PIN_ASSERT, KBD_SW_OK, GSLC_ACTION_SELECT, 0);
} }
// ----------------------------------- // -----------------------------------
@ -170,6 +204,7 @@ void loop() {
if (textChanged) { if (textChanged) {
processRingBuffer(); processRingBuffer();
} }
gslc_Update(&m_gui); gslc_Update(&m_gui);
} }
@ -195,28 +230,37 @@ void handlerKeyboard() {
// Get keyboard event // Get keyboard event
const BBQ10Keyboard::KeyEvent key = keyboard.keyEvent(); const BBQ10Keyboard::KeyEvent key = keyboard.keyEvent();
// Add key code to display ring buffer *if* it's pressed ; no need for other events presently // Process key press events
if (key.state == BBQ10Keyboard::StatePress) { if (key.state == BBQ10Keyboard::StatePress) {
// Flip to config UI if the right most button is pressed when on home screen
if (gslc_GetPageCur(&m_gui) == E_PG_MAIN && key.key == KBD_BTN_4) {
if (gslc_GetPageCur(&m_gui) == E_PG_MAIN) {
gslc_SetPageCur(&m_gui,E_CONF_RPI); gslc_SetPageCur(&m_gui,E_CONF_RPI);
} }
else { // Flip to main screen if the right most button is pressed when in config UI
else if (gslc_GetPageCur(&m_gui) == E_CONF_RPI && key.key == KBD_BTN_4) {
gslc_SetPageCur(&m_gui,E_PG_MAIN); gslc_SetPageCur(&m_gui,E_PG_MAIN);
} }
// Add keys to the key buffer that are mapped to UI functions (only for config screens)
char output[28]; else if (key.key == KBD_SW_UP
snprintf(output, 28, "key: '%c' (dec %d, hex %02x)", key.key, key.key, key.key); || key.key == KBD_SW_DN
textChanged = true; || key.key == KBD_SW_LF
for (int i=0; i<sizeof(output); i++) { || key.key == KBD_SW_RT
char toPush = output[i]; || key.key == KBD_SW_OK) {
if (toPush != '\0') { uiKeyBuffer.push(key.key);
textBuffer.push(toPush); }
} // Process keys 'normally'
else if (toPush == '\0') { else {
textBuffer.push('\n'); char output[28];
break; snprintf(output, 28, "key: '%c' (dec %d, hex %02x)", key.key, key.key, key.key);
textChanged = true;
for (int i=0; i<sizeof(output); i++) {
char toPush = output[i];
if (toPush != '\0') {
textBuffer.push(toPush);
}
else if (toPush == '\0') {
textBuffer.push('\n');
}
} }
} }
} }