|
| 1 | +/* |
| 2 | + gob_unifiedButton example |
| 3 | + customButton for CoreS3 |
| 4 | + */ |
| 5 | +#include <M5Unified.h> |
| 6 | +#include <gob_unifiedButton.hpp> |
| 7 | + |
| 8 | +goblib::UnifiedButton unifiedButton; // gob_unifiedButton instance |
| 9 | + |
| 10 | +void setup() |
| 11 | +{ |
| 12 | + M5.begin(); |
| 13 | + unifiedButton.begin(&M5.Display, goblib::UnifiedButton::appearance_t::custom); |
| 14 | + M5.Display.clear(TFT_DARKGREEN); |
| 15 | + |
| 16 | + // Customize buttons |
| 17 | + // see also https://github.com/m5stack/M5GFX/blob/master/src/lgfx/v1/LGFX_Button.hpp |
| 18 | + auto btnA = unifiedButton.getButtonA(); |
| 19 | + assert(btnA); |
| 20 | + btnA->initButton(unifiedButton.gfx(), |
| 21 | + M5.Display.width()/2, M5.Display.height()/8, M5.Display.width(), M5.Display.height()/4, |
| 22 | + TFT_ORANGE, TFT_WHITE, TFT_BLUE, "A Button", 2.0f, 4.0f); |
| 23 | + |
| 24 | + auto btnB = unifiedButton.getButtonB(); |
| 25 | + assert(btnB); |
| 26 | + btnB->initButton(unifiedButton.gfx(), |
| 27 | + M5.Display.width()/4, M5.Display.height()/8*5, M5.Display.width()/2, M5.Display.height()*3/4, |
| 28 | + TFT_LIGHTGRAY, TFT_DARKGRAY, TFT_BLACK, " Btn-B", 4.0f, 6.0f); |
| 29 | + |
| 30 | + auto btnC = unifiedButton.getButtonC(); |
| 31 | + assert(btnC); |
| 32 | + btnC->initButtonUL(unifiedButton.gfx(), |
| 33 | + M5.Display.width()/2, M5.Display.height()/4, M5.Display.width()/2, M5.Display.height()*3/4, |
| 34 | + TFT_CYAN, TFT_MAGENTA, TFT_RED, " CCC", 3.0f, 3.0f); |
| 35 | + |
| 36 | +} |
| 37 | + |
| 38 | +void loop() |
| 39 | +{ |
| 40 | + M5.update(); |
| 41 | + unifiedButton.update(); |
| 42 | + |
| 43 | + // Core/Core2/CoreS3 Can work with common code. |
| 44 | + if(M5.BtnA.wasHold()) |
| 45 | + { |
| 46 | + M5_LOGI("A button was hold"); |
| 47 | + } |
| 48 | + else if(M5.BtnA.wasClicked()) |
| 49 | + { |
| 50 | + M5_LOGI("A button was clicked"); |
| 51 | + } |
| 52 | + |
| 53 | + if(M5.BtnB.pressedFor(1000)) |
| 54 | + { |
| 55 | + M5_LOGI("B button pressed for 1000 ms"); |
| 56 | + } |
| 57 | + |
| 58 | + if(M5.BtnC.wasReleased()) |
| 59 | + { |
| 60 | + M5_LOGI("C button was released"); |
| 61 | + } |
| 62 | + |
| 63 | + unifiedButton.draw(); |
| 64 | +} |
0 commit comments