ESP_IOT v2.5
IOT ESP Coding
ButtonProcessing.cpp
Go to the documentation of this file.
1//! \link ButtonProcessing
2//
3// ButtonProcessing.c
4// M5Stick
5//
6// Created by Scott Moody on 3/9/22.
7//
8
9#include "ButtonProcessing.h"
10#ifdef USE_BUTTON_MODULE
11//@see https://github.com/m5stack/M5StickC-Plus
12//@see https://github.com/m5stack/M5StickC-Plus/blob/master/src/utility/Button.h
13
14//! 3.3.22 Using the new JSON library which is supposed to catch syntax errors without blowing up
15//https://arduinojson.org/?utm_source=meta&utm_medium=library.properties
16
17/**
18 class Button {
19 public:
20 Button(uint8_t pin, uint8_t invert, uint32_t dbTime);
21 uint8_t read();
22 */
23 /*----------------------------------------------------------------------*
24 * isPressed() and isReleased() check the button state when it was last *
25 * read, and return false (0) or true (!=0) accordingly. *
26 * These functions do not cause the button to be read. *
27 *----------------------------------------------------------------------*/
28/*
29 uint8_t isPressed();
30 uint8_t isReleased();
31 */
32/*----------------------------------------------------------------------*
33 * wasPressed() and wasReleased() check the button state to see if it *
34 * changed between the last two reads and return false (0) or *
35 * true (!=0) accordingly. *
36 * These functions do not cause the button to be read. *
37 *----------------------------------------------------------------------*/
38/*
39 uint8_t wasPressed();
40 uint8_t wasReleased();
41 */
42 /*----------------------------------------------------------------------*
43 * pressedFor(ms) and releasedFor(ms) check to see if the button is *
44 * pressed (or released), and has been in that state for the specified *
45 * time in milliseconds. Returns false (0) or true (1) accordingly. *
46 * These functions do not cause the button to be read. *
47 *----------------------------------------------------------------------*/
48
49/*
50 uint8_t pressedFor(uint32_t ms);
51 uint8_t releasedFor(uint32_t ms);
52 uint8_t wasReleasefor(uint32_t ms);
53 */
54 /*----------------------------------------------------------------------*
55 * lastChange() returns the time the button last changed state, *
56 * in milliseconds. *
57 *----------------------------------------------------------------------*/
58/*
59 uint32_t lastChange();
60 */
61/*
62class Button {
63public:
64 Button(uint8_t pin, uint8_t invert, uint32_t dbTime);
65 uint8_t read();
66 uint8_t isPressed();
67 uint8_t isReleased();
68 uint8_t wasPressed();
69 uint8_t wasReleased();
70 uint8_t pressedFor(uint32_t ms);
71 uint8_t releasedFor(uint32_t ms);
72 uint8_t wasReleasefor(uint32_t ms);
73 uint32_t lastChange();
74 */
75
76#ifdef ESP_M5
77#include <M5StickCPlus.h>
78#endif
79
80#ifdef ESP_M5_TRY
81//!https://docs.m5stack.com/en/api/stickc/pwm
82//!
83int _freq = 1800;
84int _channelBuzzer = 0;
85int _channelREDLED = 1;
86
87int _resolution_bits = 8;
88int _buzzerPin = 2;
89int _LEDPin = 10;
90#endif
91
92//**** Delay Methods*******
93#define SINGLE_DELAY
94#ifdef SINGLE_DELAY
95//https://www.forward.com.au/pfod/ArduinoProgramming/TimingDelaysInArduino.html
96//! the time the delay started
98//! true if still waiting for delay to finish
100//! length of delay
102//!init the delay
104{
105 SerialCall.printf("startDelay_ButtonProcessing: %d\n", seconds);
106
107 _delayStart_ButtonProcessing = millis(); // start delay
108 _delayRunning_ButtonProcessing = true; // not finished yet
110
111}
112//!if finished..
114{
116 {
118 SerialCall.println("delayFinished_ButtonProcessing..");
119 return true;
120 }
121 return false;
122}
123
124//!stop the delay
126{
127 SerialCall.println("stopDelay_ButtonProcessing _delayRunning=false");
128
130}
131
132//!get the delay values
134{
136}
137
138//!set when any button touched..
140{
142}
143
144//! called by the feed operation to say the device is still running.. and count it as a button click.
146{
147 SerialLots.println("refreshDelayButtonTouched_ButtonProcessing");
148 //! call the local implementation
150}
151
152
153//!checks delay
155{
157 {
159 {
160 SerialMin.printf("GATEWAY so no poweroff, but %d seconds with no buttons/feed\n", getDelayNoClickPoweroffSetting());
161 }
163 {
164 SerialMin.printf("User set no poweroff, but %d seconds with no buttons/feed\n", getDelayNoClickPoweroffSetting());
165 }
166 else
167 {
168
169 //let others know what's happening..
170 sendMessageString_mainModule((char*)"NoButtonActivity.. poweroff");
171
172 SerialMin.printf("buttonProcessor invoking poweroff after %d seconds with no buttons\n", getDelayNoClickPoweroffSetting());
173 // poweroff.. but send MQTT first..
175 }
176
177 }
178}
179
180#endif //SINGLE_DELAY
181
182/**
183 Idea for the 2 buttons: (the side button is the 'select' button, which changes the "state" of the M5. Then the
184 top button is the 'select' on the state. So if the state was "feed" then the top button would be feed.
185
186 But since their are many options for the device, th
187 */
188
189//defaults (mode is incremented on waking)
190char _smMessage[30];
191
192//!toggle the showing of the SemanticMarker and the ZOOM version
194{
196 //now redraw the semantic marker (zoomed or not zoomed)
198}
199
200//!invokes the semantic marker (which changes the display), this uses the getCurrentSMMode_mainModule()
202{
203
204#ifdef USE_MQTT_NETWORKING
205 //! Ths processJSONMessageMQTT( with cmd:smN } will trigger displaying the SemanticMarker for that page, etc.
206 //!
208 //sends message internally in JSON format.. (same as if message came from MQTT via node-red,
209 // which is where the SemanticMarkers are linked to .. the node-red backend (LinkAndSync)
211#else
212 //display something
214#endif
215}
216
217//!calls the resetFeed after we figure out the max
219{
221}
222
223//!process the current command (from some button combination) This is the LONG press on the Big button A
225{
226#ifdef ESP_M5
227
228 //! long press. This will "select" the mode we are in..
229 //! short press = always feed..
230
231 //!send the async FEED. The logic there determines if BLE or MQTT
232 //! dispatches a call to the command specified. This is run on the next loop()
233 boolean justWakeup = isBlankScreen_displayModule();
234
235 //!debug
236 SerialCall.print("performProcessCurrentMode: blank:");
237 SerialCall.println(justWakeup);
238
239 //!whether screen is blank (so the button can be a wake, vs action..)
240 if (!justWakeup)
241 {
242 SerialTemp.print("currentSMMode: ");
243 SerialTemp.println(getCurrentSMMode_mainModule());
244
245 int currentSMMode = getCurrentSMMode_mainModule();
246 //! see if there is a model..
248 if (model)
249 {
250 //print the model..
251
252 //invoke the operation.. the selection (wrapping around)
253 boolean modelChanged = invokeMenuState(model->modelKindEnum);
254 SerialTemp.printf("modelChanged(%d)\n", modelChanged);
255 //set based on modelChanged
256 int startFlag = modelChanged?START_NEW:KEEP_SAME;
257 //!redraws the Semantic Marker image..
258 // redrawSemanticMarker_displayModule(KEEP_SAME);
259
260 int currentSMModeNow = getCurrentSMMode_mainModule();
261
262 //!basically some of the invocation changes the pages, so if it's different, invoke the current one..
263 SerialTemp.printf("SMmode=%d, now=%d\n", currentSMMode,currentSMModeNow);
264 if (currentSMMode != currentSMModeNow)
266 else
268
269 return;
270 }
271
272 ///the mode is executable now..
274 {
275 case SM_home_simple:
276 SerialCall.println("SM_home_simple");
277
279
280 //long press == tilt toggle..
283
284 break;
285 case SM_home_simple_1:
286 SerialCall.println("SM_home_simple_1");
287
289#ifdef USE_BLE_CLIENT_NETWORKING
290 //!optimized to not send the wrapper around the message
291 // need to send B or b .. depending on result
294 else
296
297#endif
299
300 //long press == buzz toggle..
301 break;
302 case SM_home_simple_2:
303 {
304 SerialCall.println("SM_home_simple_2");
305
306 //!calls the resetFeed after we figure out the max
308
309 //togglePreferenceBoolean_mainModule(PREFERENCE_STEPPER_BUZZER_VALUE);
311 }
312 //long press == buzz toggle..
313 break;
314 case SM_home_simple_3: //trying to mimick the HELP ...
315 //new for the simple homepages..
316 SerialCall.println("SM_home_simple_3");
317 //togglePreferenceBoolean_mainModule(PREFERENCE_IS_MINIMAL_MENU_SETTING);
319
320 //also change to the next item, maybe anothertime popup a message stating what's happening..
323
324 break;
325 //!home page, long pr3ess will be MQTT feed message
327#ifdef USE_MQTT_NETWORKING
328 ///feed always (done after the code below..)
329// main_dispatchAsyncCommand(ASYNC_SEND_MQTT_FEED_MESSAGE);
330 sendMessageMQTT((char*)"#FEED");
331#endif
332 break;
333
334 //!guest page. Long press sends our WIFI credentials over BLE to the server (like a feeder)
335 case SM_guest_page:
336 {
337 //!grab the WIFI credentials in JSON format
338 char *credentials = main_JSONStringForWIFICredentials();
339 //!send over BLE
340 //!send an async call with a string parameter. This will set store the value and then async call the command (passing the parameter)
341 //!These are the ASYNC_CALL_PARAMETERS_MAX
342 //!since cannot send over 13 characters lets just sent the swap of network
344 }
345 break;
346 case SM_guest_feed: //guest feed
347 //NO-OP in zoom mode, the SemanticMarker shows the guest feed ..
348 // or make it just feed?
349#ifdef USE_MQTT_NETWORKING
350 //!create a device name feeding message
351 //!send this as a message, not this tacks on the # in front and other after
352 sendMessageString_mainModule((char*)"FEED");
353#endif
354 break;
355 //guest feed and wifi ssid both change the credentials..
356 case SM_WIFI_ssid:
357 {
358 //NOTE: this might be where we toggle credentials?? TODO
359 //found other one..
360 char *credentials = main_nextJSONWIFICredential();
361#ifdef USE_MQTT_NETWORKING
362
363 //!These are the ASYNC_CALL_PARAMETERS_MAX
364 //!NO: just change our credentials ...
365 //send to
366 //main_dispatchAsyncCommandWithString(ASYNC_CALL_BLE_CLIENT_PARAMETER, credentials);
368#endif
369 //redraw window..
371
372 }
373 break;
374
375 case SM_pair_dev: //pair device
376 {
378#ifdef USE_MQTT_NETWORKING
379 //!create a device name feeding message
380 sprintf(_smMessage,"FEED {'deviceName':'%s'}",pairDevice);
381 //!send this as a message, not this tacks on the # in front and other after
383#endif
384 }
385 break;
386 case SM_status: //status
387 {
388 //send this onto the DOCFollow message
391#ifdef USE_MQTT_NETWORKING
392 //!also send a #STATUS
393 sendMessageMQTT((char*)"#STATUS");
394#endif
395
396 }
397 break;
398 case SM_help: //help
399 {
400 //!and print any preferences to show
402#ifdef CHANGED_TO_JUST_MIN_MAX
403 //new logic: long press big buton ButA
404 // if in zoomed -- then go to unzoomed (which shows semantic marker)
405 // in unzoomed, also show all the marker (so Min = false)
407 //now what will it be..
409
410 SerialCall.print("Setting MINIMAL_MENU: ");
411 SerialCall.println(isZoomed?"ZOOMED":"UNZOOMED");
412
413 // if zoomed in (then use the short or min setting
415#endif
417
418 //a!lso change to the next item, maybe anothertime popup a message stating what's happening..
421 }
422 break;
423 case SM_ap_mode: //AP MODE
424 //send the async FEED
425 //! dispatches a call to the command specified. This is run on the next loop()
427 break;
428
429 case SM_doc_follow:
430 {
431 //The long press will send A semanticMarker of some kind onto the network..
432 // The getSM is already being shown..
433
434 //This is where options occur.. what to send out?
435 /// FOR NOW lets sed the dynamic status message..
436 //send this onto the DOCFollow message
437 //const char* sm = currentSemanticMarkerAddress_displayModule();
438 char *statusURL = main_currentStatusURL();
439
440 SerialTemp.print("SM_doc_follow: ");
441 SerialTemp.println(statusURL);
443
444 }
445 break;
446 case SM_reboot:
447 {
448 SerialMin.println("rebooting..");
450
451 return;
452 }
453 break;
454 default:
455 //these will be just SemanticMarkers to scan..
456 break;
457 } //switch
458 }
459 else
460 {
461 SerialCall.print("currentSMMode: ");
462 SerialCall.println(getCurrentSMMode_mainModule());
463 }
464 //now redraw the semantic marker (zoomed or not zoomed)
466
467#endif
468}
469
470//!invokes a buzzer sound on the M5
472{
473#ifdef ESP_M5_NOT_NOW
474 //!buzz the M5 (super complicated...)
475 M5.Beep.beep();
476
477#endif
478
479#ifdef ESP_M5_TRY
480
481 //!try the RED LED TOO .. turns it on but not off...
482 ledcSetup(_channelREDLED, _freq, _resolution_bits);
483 ledcAttachPin(_LEDPin, _channelREDLED);
484
485 // ledcWrite(_channelBuzzer, 128);
486 ledcWrite(_channelBuzzer, 300);
487 delay(200);
488 ledcWrite(_channelBuzzer, 0);
489
490 // ledcWrite(_channelBuzzer, 128);
491// ledcWrite(_channelREDLED, 300);
492// delay(200);
493 ledcWrite(_channelREDLED, 0);
494
495// ledcSetup(_channelREDLED, 0, 0);
496// ledcAttachPin(_LEDPin, _channelREDLED);
497
498#endif
499}
500//!defines M5 info: https://docs.rs-online.com/e4eb/A700000008182827.pdf
501
502//!long press on buttonA (top button)
504{
505 SerialCall.println("long press.. processMode");
506
507 //!long press
509 //! buzz
511
512}
513
514
515//!short press on buttonA (top button)
517{
518 // always feed..
519 SerialLots.println("buttonA_ShortPress");
520
521 //! see if there is a model..
523 if (model)
524 {
525 boolean justWakeup = isBlankScreen_displayModule();
526 if (justWakeup)
527 {
528 //!redraws the Semantic Marker image..
530 }
531 else
532 {
533 //increment the selection (wrapping around)
535
536 //!redraws the Semantic Marker image..
538 }
539
540 //!no more action .. like no feed
541 return;
542 }
543
544 ///feed always (done after the code below..)
546
547#ifdef USE_MQTT_NETWORKING
548 //!unfortunately, the incrementFeedCount() is AFTER the redrawSemanticMarker..
549 /// This sets the semantic marker .. which is current SM
551 // processJSONMessageMQTT(charSMMode_mainModule(getCurrentSMMode_mainModule()), TOPIC_TO_SEND);
553
554#endif
555 //!redraws the Semantic Marker image..
557
558 //shows that we clicked the button... (vs waiting for another to show it..)
559 showText_displayModule("FEED..");
560}
561
562//!big button on front of M5StickC Plus
564{
565 boolean buttonTouched = true;
566#ifdef ESP_M5
567 //was 1000
568 if (M5.BtnA.wasReleasefor(500))
569 {
571 }
572 else if (M5.BtnA.wasReleased())
573 {
575 }
576 else
577 {
578 buttonTouched = false;
579 }
580 //if a button was touched, update the delay since no touch..
581 if (buttonTouched)
582 {
584 }
585
586
587
588#endif //ESP_M5
589}
590
591//!the long press of the side button
593{
594#ifdef ESP_M5
595
596 SerialCall.println("B.long press.. toggleZoom or incrementColor");
597
599 {
600 case SM_home_simple:
601 case SM_home_simple_1:
602 case SM_home_simple_2:
603 case SM_ap_mode: //AP MODE
604
605 //! for now, the color is incremented in the displayModule
607 //now redraw the semantic marker (zoomed or not zoomed)
609 break;
610 case SM_home_simple_3:
611 // send a STATUS message
612#ifdef USE_MQTT_NETWORKING
613 //!also send a #STATUS
614 sendMessageMQTT((char*)"#STATUS");
615#endif
616 break;
617 default:
618 //long press
619 //!toggle the showing of the SemanticMarker and the ZOOM version
621 break;
622 }
623
624
626
627#endif
628}
629
630//!the short press of the side button
632{
633 //!and print any preferences to show
634 //printPreferenceValues_mainModule();
635
636#ifdef ESP_M5
637 //!side button.. cycles through choices..
638 //!NOW: for
639
640 boolean justWakeup = isBlankScreen_displayModule();
641 //!whether screen is blank (so the button can be a wake, vs action..)
642 if (!justWakeup)
643 {
644#define NEW_VERSION
645#ifdef NEW_VERSION
647 {
648 // set back to the SM_HOME_SIMPLE_LAST = table of contents..
650 }
651 else
652#endif
654 SerialCall.print("current mode:");
655 SerialCall.println(getCurrentSMMode_mainModule());
656 //not used right now.. min and max are same ..
657
658 }
659
660 //NOTE: starting at SM5, these are groups of 2 (on/off) and the drawing of the semantic marker
662
663#endif
664}
665//!small button on right side of M5StickC Plus
667{
668 //SerialTemp.println("checkButtonB_ButtonProcessing");
669 boolean buttonTouched = true;
670#ifdef ESP_M5
671
672 //was 1000
673 if (M5.BtnB.wasReleasefor(500))
674 {
675 SerialCall.println("buttonB_LongPress");
676
678 }
679 //side button.. cycles through choices..
680 else if (M5.BtnB.wasReleased())
681 {
682 SerialCall.println("buttonB_ShortPress");
683
685 }
686 else
687 {
688
689 buttonTouched = false;
690 }
691 //if a button was touched, update the delay since no touch..
692 if (buttonTouched)
693 {
694 SerialLots.println(" .. buttonB .. calling refresh");
696 }
697#endif // ESP_M5
698
699}
700
701
702
703#define SENSORS_MOTION_PIR
704#ifdef SENSORS_MOTION_PIR
705#define PIR_PIN 36 //passive IR Hat
706const uint32_t SLEEP_DURATION = 1 * 1000000;
707
708unsigned long _PrevSampleTime = 0;
709unsigned long _PrevTriggerTime = 0;
710unsigned long _InactivityTimeOut = 0;
711
712#define Elapsed3secs 3000
713#define Elapsed4secs 4000
714
715#define Elapsed3mins 180000 // 3 minutes in milliseconds
717{
718 float accX = 0.0F;
719 float accY = 0.0F;
720 float accZ = 0.0F;
721 float diffX = 0.0F;
722 float diffY = 0.0F;
723 float diffZ = 0.0F;
724 float diffXYZ = 0.0F;
725 float prevX = 0.0F;
726 float prevY = 0.0F;
727 float prevZ = 0.0F;
728#ifdef GYRO
729 float gyroX = 0.0F;
730 float gyroY = 0.0F;
731 float gyroZ = 0.0F;
732#endif
733#ifdef PITCH_ROLL
734 float pitch = 0.0F;
735 float roll = 0.0F;
736 float yaw = 0.0F;
737#endif
738 float TILT_SENSITIVITY = 0.5;
740
741
742//!Return "true" on PIR (over sensitivity) and false otherwise
743//!This is just a sensor (if plugged in) - so any timing is on the caller of this
745{
746// if (!getPreferenceBoolean_mainModule(PREFERENCE_SENSOR_PIR_VALUE))
747// return false;
748
749 boolean triggeredPIR = digitalRead(PIR_PIN);
750 if (triggeredPIR)
751 {
752 if ((millis()-_PrevTriggerTime)>Elapsed4secs)
753 {
754 triggeredPIR = true;
755 _PrevTriggerTime = millis();
756 SerialLots.println("triggeredPIR = true");
757 }
758 else
759 triggeredPIR = false;
760 }
761 return triggeredPIR;
762}
763
764//!looks at M5.IMU sensor to see if changed since last time..
765//!Return "true" on motion (over sensitivity) and false otherwise
767{
768#ifndef ESP_M5
769 return false;
770#endif
771 //! if the TILT isn't an option.. then never return true ..
773 {
774 return false;
775 }
776 else
777 {
778// main_printModuleConfiguration();
779// SerialTemp.println("**** SENSOR TILT IS ON");
780// main_printModuleConfiguration();
781 }
782
783 // 100ms sample interval
784 if ( (millis() - _PrevSampleTime) >100)
785 {
786 //update for next sample point
787 _PrevSampleTime = millis();
788#ifdef ESP_M5
789 // M5.IMU.getGyroData(&_IMU.gyroX,&_IMU.gyroY,&_IMU.gyroZ);
790
791 M5.IMU.getAccelData(&_IMU.accX,&_IMU.accY,&_IMU.accZ);
792 // M5.IMU.getAhrsData(&_IMU.pitch,&_IMU.roll,&_IMU.yaw);
793
794 //debug print
795 //SerialTemp.printf("%5.2f %5.2f %5.2f \n\r", _IMU.accX, _IMU.accY, _IMU.accZ);
796// SerialTemp.printf("%5.2f %5.2f %5.2f \n\r", _IMU.gyroX, _IMU.gyroY, _IMU.gyroZ);
797// SerialTemp.printf("%5.2f %5.2f %5.2f \n\r", _IMU.pitch, _IMU.roll, _IMU.yaw);
798
799#endif
800 _IMU.diffX = abs(_IMU.prevX - _IMU.accX);
801 _IMU.diffY = abs(_IMU.prevY - _IMU.accY);
802 _IMU.diffZ = abs(_IMU.prevZ - _IMU.accZ);
804
805 //save x,y,z from this cycle for next cycle
806
810 }
811 //if the movement is above threshold sensitivity then broadcast and start IGNORE time
813 {
814 _PrevTriggerTime = millis();
815 SerialLots.printf("diff: %.2f \r\n", _IMU.diffXYZ);
816 // TILT has exceed threshold
817 return true;
818 }
819 else
820 {
821 //movement does not exceed threshold
822 return false;
823 }
824} // end of CheckMotion
825#endif // SENSORS_MOTION_PIR
826
827
828//!the setup for buttonProcessing (extension of ButtonModule)
829//! 在 M5StickC Plus 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。
831{
833
834#ifdef ESP_M5
835 //!setup the plugin PIR (if there..)
836 pinMode(PIR_PIN,INPUT_PULLUP);
837
838 //M5.begin(); already called..
839 //Init IMU. 初始化IMU
840
841 M5.Imu.Init();
842 M5.Axp.begin();
844
845 //!https://docs.m5stack.com/en/api/stickc/pwm
846 //!
847// ledcSetup(_channelBuzzer, _freq, _resolution_bits);
848// ledcAttachPin(_buzzerPin, _channelBuzzer);
849 // M5.Beep.begin();
850
851
852#endif
853}
854
855boolean _firstLoopProcessing = true;
856//!the loop for buttonProcessing (extension of ButtonModule)
858{
859 //not sure if MQTT or other running .. but seems like a try
861 {
863 _firstLoopProcessing = false;
864 }
865
866#ifdef ESP_M5
867 M5.update(); //Read the press state of the key. ONLY call once per loop or the status of B button is lost
868#endif
869
870
871
872#ifdef LATER
873 if ( (millis() - PrevTriggerTime) > InactivityTimeOut) {
874 M5.Axp.PowerOff(); // shutoff after no activity
875 }
876#endif
877
878 //try..
879
880 // check for tilt etc..
882 {
883 SerialTemp.println("motion detected");
884 sendMessageString_mainModule((char*)"TiltDetected");
885
886 //This (in mainModule) will look if connected so sends over BLE, otherwise MQTT (if connected)
888 }
889
890 // check for PIR etc..
892 {
893 SerialTemp.println("PIR detected");
894 sendMessageString_mainModule((char*)"PIRDetected");
895
896 //This (in mainModule) will look if connected so sends over BLE, otherwise MQTT (if connected)
898 }
899
900 //checkBothPressed_ButtonProcessing();
903
904 //see if the time is up..
906}
907
908#endif //USE_BUTTON_MODULE
void sendCommandBLEClient_13orLess(String cmdString)
send a string of 13 characters or less
void loop_ButtonProcessing()
the loop for buttonProcessing (extension of ButtonModule)
int _delaySeconds_ButtonProcessing
length of delay
boolean _delayRunning_ButtonProcessing
true if still waiting for delay to finish
void checkButtonA_ButtonProcessing()
big button on front of M5StickC Plus
void buttonB_ShortPress()
the short press of the side button
void performProcessCurrentMode()
process the current command (from some button combination) This is the LONG press on the Big button A
#define PIR_PIN
void resetFeedCount()
calls the resetFeed after we figure out the max
void buzzerM5_buttonModule()
invokes a buzzer sound on the M5
unsigned long _InactivityTimeOut
bool checkPIR_ButtonProcessing()
unsigned long _PrevSampleTime
void refreshDelayButtonTouched_ButtonProcessing()
called by the feed operation to say the device is still running.. and count it as a button click.
void startDelay_ButtonProcessing(int seconds)
init the delay
unsigned long _delayStart_ButtonProcessing
the time the delay started
#define Elapsed4secs
int getDelayNoClickPoweroffSetting()
get the delay values
const uint32_t SLEEP_DURATION
boolean delayFinished_ButtonProcessing()
if finished..
char _smMessage[30]
void stopDelay_ButtonProcessing()
stop the delay
void setup_ButtonProcessing()
#define Elapsed3mins
void buttonA_LongPress()
defines M5 info: https://docs.rs-online.com/e4eb/A700000008182827.pdf
struct IMUVariables _IMU
unsigned long _PrevTriggerTime
void refreshDelayButtonTouched()
set when any button touched..
void checkButtonB_ButtonProcessing()
small button on right side of M5StickC Plus
void buttonB_LongPress()
the long press of the side button
void buttonA_ShortPress()
short press on buttonA (top button)
void invokeCurrentSemanticMarker()
invokes the semantic marker (which changes the display), this uses the getCurrentSMMode_mainModule()
bool checkMotion_ButtonProcessing()
boolean _firstLoopProcessing
void checkDelaySinceButtonTouched()
checks delay
void toggleSM_Zoomed()
toggle the showing of the SemanticMarker and the ZOOM version
void incrementScreenColor_displayModule()
boolean isBlankScreen_displayModule()
whether screen is blank (so the button can be a wake, vs action..)
void showText_displayModule(String text)
void redrawSemanticMarker_displayModule(boolean startNew)
redraws the Semantic Marker image..
const char * currentSemanticMarkerAddress_displayModule()
returns the current semantic marker (eg. guest page)
#define START_NEW
Definition: DisplayModule.h:53
#define KEEP_SAME
Definition: DisplayModule.h:54
void sendMessageMQTT(char *message)
boolean processJSONMessageMQTT(char *ascii, char *topic)
process the JSON message (looking for FEED, etc). Note: topic can be nil, or if not,...
void sendSemanticMarkerDocFollow_mainModule(const char *SMDocFollowAddress)
sends the SM on the DOCFOLLOW channel (publish it..)
char * charSMMode_mainModule(int whichSMMode)
returns string form whichSMMode, sg "sm0", sm1 ...
char * main_currentStatusURL()
returns a string in in URL so: status?battery=84'&buzzon='off' } .. etc
char * main_JSONStringForWIFICredentials()
retrieve a JSON string for the ssid and ssid_password: {'ssid':<ssid>,'ssidPassword':<pass>"}
Definition: MainModule.cpp:663
void main_dispatchAsyncCommandWithString(int asyncCallCommand, char *parameter)
Definition: MainModule.cpp:807
int getCurrentSMMode_mainModule()
returns the current SM Mode
void resetFeedCount_mainModule()
sets the feed count max
Definition: MainModule.cpp:190
void sendMessageString_mainModule(char *messageString)
adding a synchronous call to send a message over the network (assuming MQTT but not specified),...
void setCurrentSMMode_mainModule(int whichSMMode)
sets the current screen mode .. which can be used by Button and Display processing
void main_dispatchAsyncCommand(int asyncCallCommand)
checks if any async commands are in 'dispatch' mode, and if so, invokes them, and sets their flag to ...
Definition: MainModule.cpp:789
char * main_nextJSONWIFICredential()
! cycle through the next WIFI saved credential
Definition: MainModule.cpp:669
void incrementSMMode_mainModule()
increment the currentSMMode, wrapping and using the max menu
#define SM_home_simple
Definition: MainModule.h:284
#define SM_pair_dev
guest feed device
Definition: MainModule.h:308
#define ASYNC_REBOOT
sets the GATEWAY mode off
Definition: MainModule.h:163
#define ASYNC_CALL_BLE_CLIENT_PARAMETER
these are the async with a string parameter. This sends a BLE command
Definition: MainModule.h:179
#define SM_guest_feed
guest feed
Definition: MainModule.h:306
#define SM_guest_page
guest page
Definition: MainModule.h:299
#define NO_POWEROFF_AMOUNT_MAIN
10000 == no poweroff
Definition: MainModule.h:44
#define ASYNC_SEND_MQTT_FEED_MESSAGE
sends a message (like FEED) on the users topic
Definition: MainModule.h:153
#define SM_HOME_SIMPLE_LAST
Definition: MainModule.h:288
#define SM_home_simple_1
Definition: MainModule.h:285
#define SM_home_simple_2
Definition: MainModule.h:286
#define SM_status
//status
Definition: MainModule.h:295
#define ASYNC_CALL_CLEAN_CREDENTIALS
cleans out the credentials and restarts in AP (Access Point) mode.
Definition: MainModule.h:143
#define SM_reboot
REboot.
Definition: MainModule.h:317
#define SM_help
HELP.
Definition: MainModule.h:310
#define ASYNC_POWEROFF
sets the GATEWAY mode off
Definition: MainModule.h:165
#define SM_home_simple_3
Definition: MainModule.h:287
#define SM_doc_follow
docfollow
Definition: MainModule.h:313
#define SM_smart_clicker_homepage
//! homepage
Definition: MainModule.h:293
#define TOPIC_TO_SEND
Definition: MainModule.h:41
#define SM_WIFI_ssid
WIFI ssid.
Definition: MainModule.h:297
#define SM_ap_mode
AP MODE.
Definition: MainModule.h:302
void incrementMenuState(ModelKindEnum modelKind)
increments the device states deviceState (wrapping around)
boolean invokeMenuState(ModelKindEnum modelKind)
invokes the menu state, return true if the model state has change enough to refreesh your View (such ...
ModelStateStruct * hasModelForSM_Mode(int SM_Mode)
retrieves the state model for the SM_Mode (SM_0 .. SM_LAST) null if none
void savePreferenceBoolean_mainModule(int preferenceID, boolean flag)
save a boolean preference
boolean getPreferenceBoolean_mainModule(int preferenceID)
called to set a preference (which will be an identifier and a string, which can be converted to a num...
void togglePreferenceBoolean_mainModule(int preferenceID)
toggles a preference boolean
int getPreferenceInt_mainModule(int preferenceID)
called to set a preference (which will be an identifier and a string, which can be converted to a num...
char * getPreferenceString_mainModule(int preferenceID)
returns the preference but in it's own string buffer. As long as you use it before calling getPrefere...
void printPreferenceValues_mainModule()
print the preferences to SerialDebug
#define PREFERENCE_SENSOR_TILT_VALUE
Sensor preferences.
#define PREFERENCE_NO_BUTTON_CLICK_POWEROFF_SETTING
#define PREFERENCE_SEMANTIC_MARKER_ZOOMED_VALUE
Display preferences (SemanticMarker etc) - boolean.
#define PREFERENCE_PAIRED_DEVICE_SETTING
the paired device for guest device feeding (6.6.22)
#define PREFERENCE_STEPPER_BUZZER_VALUE
stepper preferences
#define PREFERENCE_IS_MINIMAL_MENU_SETTING
sets the max temp for a poweroff
#define PREFERENCE_MAIN_GATEWAY_VALUE
the struct for the models. Since this isn't straight OO, we are overlaying information....
ModelKindEnum modelKindEnum
What kind of model.