From 51dcc0128b6f21edf18cd9c9b7208866bd1b2ff9 Mon Sep 17 00:00:00 2001 From: Nick Reynolds Date: Sun, 2 Jan 2022 12:06:38 +0000 Subject: [PATCH] Add example for click callbacks. --- .../Example11_clickCallback.ino | 41 ++++++++++++++++++ examples/Example11_clickCallback/README.md | 5 +++ .../images/clickCallback.png | Bin 0 -> 7741 bytes 3 files changed, 46 insertions(+) create mode 100644 examples/Example11_clickCallback/Example11_clickCallback.ino create mode 100644 examples/Example11_clickCallback/README.md create mode 100644 examples/Example11_clickCallback/images/clickCallback.png diff --git a/examples/Example11_clickCallback/Example11_clickCallback.ino b/examples/Example11_clickCallback/Example11_clickCallback.ino new file mode 100644 index 0000000..c37e52f --- /dev/null +++ b/examples/Example11_clickCallback/Example11_clickCallback.ino @@ -0,0 +1,41 @@ +#include //Include terminal library +retroTerm terminal; //Create a terminal instance +uint8_t button1Id = 0; //Record the button ID globally +uint8_t button2Id = 0; //Record the button ID globally +uint8_t button3Id = 0; //Record the button ID globally +uint32_t numberOfClicks[3] = {1,1,1}; //Record the number of clicks + +void processClick(uint8_t widgetClicked) { + if(widgetClicked == button1Id) { + terminal.scroll("Button 1 click " + String(numberOfClicks[0]++)); //Print inside the scroll window + } else if(widgetClicked == button2Id) { + terminal.scroll("Button 2 click " + String(numberOfClicks[1]++)); //Print inside the scroll window + } else if(widgetClicked == button3Id) { + terminal.scroll("Button 3 click " + String(numberOfClicks[2]++)); //Print inside the scroll window + } else { + terminal.scroll("Unknown click"); //Print inside the scroll window + } +} + +void setup() { + Serial.begin(115200); //Initialise the Serial stream + terminal.begin(Serial); //Initialise the library + terminal.eraseScreen(); //Clear the screen + terminal.hideCursor(); //Hide the terminal cursor + terminal.enableMouse(); //Capture the mouse so it can be used with widgets + terminal.setScrollWindow(4,12); //Set up somewhere to show the events without disrupting the button + button1Id = terminal.newButton(1, 1, 15, 3, F("Button 1"), COLOUR_RED, OUTER_BOX | BOX_SINGLE_LINE); //Create a green button in a box + button2Id = terminal.newButton(16, 1, 15, 3, F("Button 2"), COLOUR_GREEN, OUTER_BOX | BOX_SINGLE_LINE); //Create a green button in a box + button3Id = terminal.newButton(31, 1, 15, 3, F("Button 3"), COLOUR_BLUE, OUTER_BOX | BOX_SINGLE_LINE); //Create a green button in a box + terminal.widgetShortcutKey(button1Id,f1Pressed); //Assign a shortcut key of F1 + terminal.widgetShortcutKey(button2Id,f2Pressed); //Assign a shortcut key of F2 + terminal.widgetShortcutKey(button3Id,f3Pressed); //Assign a shortcut key of F3 + terminal.showWidget(button1Id); //Make the button visible, all widgets start 'invisible' for later display + terminal.showWidget(button2Id); //Make the button visible, all widgets start 'invisible' for later display + terminal.showWidget(button3Id); //Make the button visible, all widgets start 'invisible' for later display + terminal.setClickCallback(processClick); //retroTerm callback for click events +} + +void loop() { + terminal.houseKeeping(); //You MUST run housekeeping to show/detect any changes or events +} diff --git a/examples/Example11_clickCallback/README.md b/examples/Example11_clickCallback/README.md new file mode 100644 index 0000000..6ce04a9 --- /dev/null +++ b/examples/Example11_clickCallback/README.md @@ -0,0 +1,5 @@ +# clickCallback.ino + +This example sketch shows how to use the callback function to register clicks from various widgets. As you click the buttons you should get output like this. + +![](images/clickCallback.png) \ No newline at end of file diff --git a/examples/Example11_clickCallback/images/clickCallback.png b/examples/Example11_clickCallback/images/clickCallback.png new file mode 100644 index 0000000000000000000000000000000000000000..d5708a4328aad92f9060eecc109fc17d016df1b1 GIT binary patch literal 7741 zcmeHsX;@QPw)R0Ru^gaMTB3|Cv|0)hEmTm3I7BE%6cG>ts3-^l0)hkyBve^Q6af{H zK|;!bMy5nWW=H^$Ip9DDQxfJ#APG|vGM;<5Uw7T^+h5;%f8XaOf7aP&J!kLzp0(b0 z?RD;*JL|Z9joumn0M?)Q8R-lFE7AZ!u5j!gvR9oZ3(CFrpsN@jKQ5!;;q zyzNqNs=e{bUzAI{F*0GTdcF=EQzWq~!%VFcjclW4`+QUE_@!|d#-#x_muT~Xu zK?$gwBqJ2_9dPv$Xks#|pQ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