From aabfb0bd6b5f35fa761417b73f4523e4da4e002d Mon Sep 17 00:00:00 2001 From: KemoNine Date: Fri, 11 Sep 2020 00:35:56 -0400 Subject: [PATCH] Updates to wire up 5 way switch to gui slice UI on config screen --- hardware/_controller/_controller.ino | 84 +++++++++++++++++++++------- 1 file changed, 64 insertions(+), 20 deletions(-) diff --git a/hardware/_controller/_controller.ino b/hardware/_controller/_controller.ino index 9b57465..122fd10 100644 --- a/hardware/_controller/_controller.ino +++ b/hardware/_controller/_controller.ino @@ -58,6 +58,7 @@ BBQ10Keyboard keyboard; #define KBD_SW_LF 0x03 #define KBD_SW_RT 0x04 #define KBD_SW_OK 0x05 +CircularBuffer uiKeyBuffer; // Upstream keyboard definitions that will be really important later #define _REG_CFG 2 @@ -92,6 +93,10 @@ gslc_tsElemRef* m_pElemStatusText = NULL; gslc_tsElemRef* m_pElemText = NULL; // +// Keyboard map related +#define MAX_INPUT_MAP 5 +gslc_tsInputMap m_asInputMap[MAX_INPUT_MAP]; + // Define debug message function 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 // // +// 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() { 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) pinMode(3, OUTPUT); digitalWrite(3, HIGH); @@ -145,12 +170,21 @@ void setup() { Wire.begin(); keyboard.begin(); keyboard.writeRegister(_REG_CFG, CFG_OVERFLOW_INT | CFG_KEY_INT | CFG_USE_MODS | CFG_REPORT_MODS); - keyboard.setBacklight(0.5f); - // GUI Slice (TFT is setup through GUI Slice) - gslc_InitDebug(&DebugOut); + // Init GUI Slicle 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) { processRingBuffer(); } + gslc_Update(&m_gui); } @@ -195,28 +230,37 @@ void handlerKeyboard() { // Get keyboard event 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 (gslc_GetPageCur(&m_gui) == E_PG_MAIN) { + // 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) { 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); } - - char output[28]; - snprintf(output, 28, "key: '%c' (dec %d, hex %02x)", key.key, key.key, key.key); - textChanged = true; - for (int i=0; i