m5stack / M5Core2

M5Core2 Arduino Library
MIT License
267 stars 117 forks source link

TouchEvent Structures #120

Closed brianteeman closed 1 year ago

brianteeman commented 1 year ago

Describe the bug

Following the documented API at https://docs.m5stack.com/en/api/core2/touch

The example code for TouchEvent structures completely fails to compile

To reproduce

Create a new sketch with just the example code from the documentation

Expected behavior

Compiles without error

Screenshots

C:\Users\brian\AppData\Local\Temp\.arduinoIDE-unsaved2023026-25020-o099su.47rq\sketch_jan26b\sketch_jan26b.ino:3:1: error: 'TouchButton' does not name a type; did you mean 'Button'?
 TouchButton lt = TouchButton(0, 0, 160, 120, "left-top");
 ^~~~~~~~~~~
 Button
C:\Users\brian\AppData\Local\Temp\.arduinoIDE-unsaved2023026-25020-o099su.47rq\sketch_jan26b\sketch_jan26b.ino:4:1: error: 'TouchButton' does not name a type; did you mean 'Button'?
 TouchButton lb = TouchButton(0, 120, 160, 120, "left-bottom");
 ^~~~~~~~~~~
 Button
C:\Users\brian\AppData\Local\Temp\.arduinoIDE-unsaved2023026-25020-o099su.47rq\sketch_jan26b\sketch_jan26b.ino:5:1: error: 'TouchButton' does not name a type; did you mean 'Button'?
 TouchButton rt = TouchButton(160, 0, 160, 120, "right-top");
 ^~~~~~~~~~~
 Button
C:\Users\brian\AppData\Local\Temp\.arduinoIDE-unsaved2023026-25020-o099su.47rq\sketch_jan26b\sketch_jan26b.ino:6:1: error: 'TouchButton' does not name a type; did you mean 'Button'?
 TouchButton rb = TouchButton(160, 120, 160, 120, "right-bottom");
 ^~~~~~~~~~~
 Button
C:\Users\brian\AppData\Local\Temp\.arduinoIDE-unsaved2023026-25020-o099su.47rq\sketch_jan26b\sketch_jan26b.ino:9:19: error: variable or field 'eventDisplay' declared void
 void eventDisplay(TouchEvent& e) {
                   ^~~~~~~~~~
C:\Users\brian\AppData\Local\Temp\.arduinoIDE-unsaved2023026-25020-o099su.47rq\sketch_jan26b\sketch_jan26b.ino:9:19: error: 'TouchEvent' was not declared in this scope
C:\Users\brian\AppData\Local\Temp\.arduinoIDE-unsaved2023026-25020-o099su.47rq\sketch_jan26b\sketch_jan26b.ino:9:19: note: suggested alternative: 'TouchPoint'
 void eventDisplay(TouchEvent& e) {
                   ^~~~~~~~~~
                   TouchPoint
C:\Users\brian\AppData\Local\Temp\.arduinoIDE-unsaved2023026-25020-o099su.47rq\sketch_jan26b\sketch_jan26b.ino:9:31: error: 'e' was not declared in this scope
 void eventDisplay(TouchEvent& e) {
                               ^
C:\Users\brian\AppData\Local\Temp\.arduinoIDE-unsaved2023026-25020-o099su.47rq\sketch_jan26b\sketch_jan26b.ino:9:19: error: variable or field 'eventDisplay' declared void
 void eventDisplay(TouchEvent& e) {
                   ^~~~~~~~~~
C:\Users\brian\AppData\Local\Temp\.arduinoIDE-unsaved2023026-25020-o099su.47rq\sketch_jan26b\sketch_jan26b.ino:9:19: error: 'TouchEvent' was not declared in this scope
C:\Users\brian\AppData\Local\Temp\.arduinoIDE-unsaved2023026-25020-o099su.47rq\sketch_jan26b\sketch_jan26b.ino:9:19: note: suggested alternative: 'TouchPoint'
 void eventDisplay(TouchEvent& e) {
                   ^~~~~~~~~~
                   TouchPoint
C:\Users\brian\AppData\Local\Temp\.arduinoIDE-unsaved2023026-25020-o099su.47rq\sketch_jan26b\sketch_jan26b.ino:9:31: error: 'e' was not declared in this scope
 void eventDisplay(TouchEvent& e) {
                               ^
C:\Users\brian\AppData\Local\Temp\.arduinoIDE-unsaved2023026-25020-o099su.47rq\sketch_jan26b\sketch_jan26b.ino: In function 'void setup()':
C:\Users\brian\AppData\Local\Temp\.arduinoIDE-unsaved2023026-25020-o099su.47rq\sketch_jan26b\sketch_jan26b.ino:19:12: error: 'class M5Touch' has no member named 'addHandler'
   M5.Touch.addHandler(eventDisplay);
            ^~~~~~~~~~
C:\Users\brian\AppData\Local\Temp\.arduinoIDE-unsaved2023026-25020-o099su.47rq\sketch_jan26b\sketch_jan26b.ino:19:23: error: 'eventDisplay' was not declared in this scope
   M5.Touch.addHandler(eventDisplay);
                       ^~~~~~~~~~~~
C:\Users\brian\AppData\Local\Temp\.arduinoIDE-unsaved2023026-25020-o099su.47rq\sketch_jan26b\sketch_jan26b.ino:19:23: note: suggested alternative: 'M5Display'
   M5.Touch.addHandler(eventDisplay);
                       ^~~~~~~~~~~~
                       M5Display
Multiple libraries were found for "SD.h"
  Used: C:\Users\brian\AppData\Local\Arduino15\packages\m5stack\hardware\esp32\2.0.6\libraries\SD
  Not used: C:\Users\brian\AppData\Local\Arduino15\libraries\SD
exit status 1

Compilation error: 'TouchButton' does not name a type; did you mean 'Button'?

Environment

Windows11 Arduino IDE 2.0.3 M5Core2 v0.1.5 library

Additional context

A previous user reported this #90 but it was closed without a real answer

Issue checklist

Tinyu-Zhao commented 1 year ago

Sorry, the documentation on the official website has not yet been updated, please try using the following code.

#include <M5Core2.h>

Button lt(0, 0, 160, 120, "left-top");
Button lb(0, 120, 160, 120, "left-bottom");
Button rt(160, 0, 160, 120, "right-top");
Button rb(160, 120, 160, 120, "right-bottom");

  void colorButtons(Event& e) {
    Button& b = *e.button;
    M5.Lcd.fillRect(b.x, b.y, b.w, b.h, b.isPressed() ? WHITE : BLACK);
  }

  void dblTapped(Event& e) {
    Serial.println("--- TOP RIGHT BUTTON WAS DOUBLETAPPED ---");
  }

  void setup() {
    M5.begin();
    M5.Buttons.addHandler(colorButtons,  E_TOUCH + E_RELEASE);
    rt.addHandler(dblTapped, E_DBLTAP);
  }

  void loop() {
    M5.update();
  }