ESP_IOT v2.5
IOT ESP Coding
PreferencesController.cpp
Go to the documentation of this file.
1
2#include "../../Defines.h"
4//! PREFERENCES for the main module
5//1075325 vs 1074301
6//1075781 after refactor (removed stpper preferences)
7//1075833
8
9//!for returning a 'String" NOTE: THIS IS NOT GREAT .. as if you don't grab it before another query, and use it -- the result might be 1 instead of deviceName..
11//!buffer for the string
13
14//! 1.27.26 Chain Buttons .. which non-chain can use too
15//! storage tor a message
17
18//! 8.2.24 includeGroups
19//! 8.2.24 break up the list..
20#define NUMBER_GROUPS 4
21#define STRING_MAX_SIZE 40
23//!resulting group names
25
26
27//!Issue #103
28//!NOTE: the EPROM space might be limiting: https://github.com/espressif/arduino-esp32/blob/master/tools/partitions/default.csv
29//!to 4KB .. https://www.esp32.com/viewtopic.php?t=9136
30//! So we should start limiting our use, and start with these string indexes..
31//! main module preferences
32//! gateway is on THESE MUST ALL BE UNIQUE
33#define EPROM_MAIN_GATEWAY_VALUE "1gt"
34//!BLEServer mode
35#define EPROM_MAIN_BLE_SERVER_VALUE "2bs"
36//!BLEClient mode
37#define EPROM_MAIN_BLE_CLIENT_VALUE "3bc"
38
39//!buzzer on or off
40#define EPROM_STEPPER_BUZZER_VALUE "4bz"
41//! single feed mode
42#define EPROM_STEPPER_SINGLE_FEED_VALUE "5sf"
43//!auto feed
44#define EPROM_STEPPER_AUTO_FEED_VALUE "6af"
45//!jackpot feed
46#define EPROM_STEPPER_JACKPOT_FEED_VALUE "7jf"
47//! the step kind
48#define EPROM_STEPPER_KIND_VALUE "8sk"
49//num feeds in jackpot mode
50#define EPROM_STEPPER_FEEDS_PER_JACKPOT_VALUE "9jp"
51//! sensor preferences for tilt on or off
52#define EPROM_SENSOR_TILT_VALUE "TILT_10" //10tt"
53 //!proximity PIR
54#define EPROM_SENSOR_PIR_VALUE "11pr"
55//! display preferences zoomed or not zoomed
56#define EPROM_SEMANTIC_MARKER_ZOOMED_VALUE "12sz"
57
58//! Display preferences - show messages on blank screen- boolean
59#define EPROM_DISPLAY_ON_BLANK_SCREEN_VALUE "13bk"
60//! sets the timeout value
61#define EPROM_DISPLAY_SCREEN_TIMEOUT_VALUE "14to"
62//! sets the max temp for a poweroff
63#define EPROM_HIGH_TEMP_POWEROFF_VALUE "15pw"
64//!whether to show the minimal or expanded menu
65#define EPROM_IS_MINIMAL_MENU_SETTING "16mm"
66//! sets stepper angle, a floating point number
67#define EPROM_STEPPER_ANGLE_FLOAT_SETTING "17sa"
68
69//! sets screentimeout if not button clicks (set,noclick,val,seconds)
70#define EPROM_NO_BUTTON_CLICK_POWEROFF_SETTING "18po"
71
72//!for now, save 2 WIFI Credentials
73#define EPROM_WIFI_CREDENTIAL_1_SETTING "19w1"
74//!second wifi credential
75#define EPROM_WIFI_CREDENTIAL_2_SETTING "20w2"
76
77//! the guest device paired with this M5 device (or NONE)
78#define EPROM_PAIRED_DEVICE_SETTING "21pd"
79
80//! the device name
81#define EPROM_DEVICE_NAME_SETTING "22dn"
82
83//!a firsttime feature flag (only 1 per build) 7.12.22 defaulting to TRUE
84#define EPROM_FIRST_TIME_FEATURE_SETTING "23fs"
85
86//! if true, only BLEClient connect to GEN3 feeders..
87#define EPROM_ONLY_GEN3_CONNECT_SETTING "23gs"
88
89//!color of the M5 screen
90#define EPROM_SCREEN_COLOR_SETTING "24sc"
91
92//!if set, the BLE Server (like PTFeeder) will tack on the device name (or none if not defined).
93#define EPROM_BLE_SERVER_USE_DEVICE_NAME_SETTING "25bs"
94//!if set, the BLE Client will look for its service base name (PTFeeder or PTClicker), but if that name
95//!also has an extension (:ScoobyDoo), and this is set, it will only connect if the PREFERENCE_PAIRED_DEVICE_SETTING has the same device name in the discovered name
96#define EPROM_BLE_USE_DISCOVERED_PAIRED_DEVICE_SETTING "26bd"
97//!NOTE: these EPROM have to be lockstep the same as the PREFERENCE definitions in MainModule.h
98
99#define EPROM_USE_DOC_FOLLOW_SETTING "27df"
100
101//! 8.17.22 to turn on/off subscribing to the dawgpack topic
102#define EPROM_SUB_DAWGPACK_SETTING "28dg"
103
104//! 8.22.22 to turn on/off SPIFF use
105#define EPROM_USE_SPIFF_SETTING "29sf"
106
107//! 9.3.22 eprom of the Address of desired BLE
108#define EPROM_PAIRED_DEVICE_ADDRESS_SETTING "30da"
109
110//!retreives the motor direction| true default, clockwise; false = REVERSE, counterclockwise 9.8.22
111//! false = reverse == counterclockwise
112//! true = default
113#define EPROM_STEPPER_FACTORY_CLOCKWISE_MOTOR_DIRECTION_SETTING "31md"
114
115//!send WIFI to all except our device (and our paired) when
116#define EPROM_SENDWIFI_WITH_BLE "32wb"
117
118//! starts the BLE Discovery notification process - which might be internal or externa (via messages).
119#define EPROM_NOTIFY_BLE_DISCOVERY "33bd"
120
121//! the preference timer
122#define EPROM_PREFERENCE_TIMER_INT_SETTING "34tm"
123
124//! the preference for supporting GROUPS (*default true)*
125#define EPROM_PREFERENCE_SUPPORT_GROUPS_SETTING "35g"
126
127//! the preference setting group names to subscribe (but empty or # go to wildcard, this also supports wildcard in the future)
128#define EPROM_PREFERENCE_GROUP_NAMES_SETTING "36g"
129
130//! a place to put some kind of Last Will of what went wrong .. for now (> max tries)
131#define EPROM_PREFERENCE_DEBUG_INFO_SETTING "37db"
132
133
134//!9.28.23 #272 only show Semantic Markers that are sent directly to the device
135#define EPROM_DEV_ONLY_SM_SETTING "38dsm"
136
137//! 11.29.23 add the max time .. so a random can be used
138#define EPROM_PREFERENCE_TIMER_MAX_INT_SETTING "39x"
139
140//! 1.1.24 the preference for all the ATOM plugs (format: atomType:value} .. for now just use socket:on
141#define EPROM_PREFERENCE_ATOMS_SETTING "40a"
142
143//!1.4.24 What kind of ATOM plug (set, M5AtomKind, val= {M5AtomSocket, M5AtomScanner}
144#define EPROM_PREFERENCE_ATOM_KIND_SETTING "41Atom"
145
146//! 1.10.24 Flag on whether a Semantic Marker command is sent on PIR, and the Command to send
147#define EPROM_PREFERENCE_SM_ON_PIR_SETTING "42pir"
148//! 1.10.24 The Semantic Marker command is sent on PIR, and the Command to send
149#define EPROM_PREFERENCE_SM_COMMAND_PIR_SETTING "43pir"
150//! 1.11.24 The Semantic Marker command is sent on PIR, and the Command to send
151#define EPROM_PREFERENCE_SM_COMMAND_PIR_OFF_SETTING "44pir"
152//! 1.12.24 Whether the AtomSocket accepts global on/off messages
153#define EPROM_PREFERENCE_ATOM_SOCKET_GLOBAL_ONOFF_SETTING "45sock"
154
155//! 4.4.24 for MQTT use of spiff (or not)
156#define EPROM_USE_SPIFF_MQTT_SETTING "46spiff"
157//! 4.4.24 for QRATOM use of spiff (or not)
158#define EPROM_USE_SPIFF_QRATOM_SETTING "47spiff"
159
160//! 8.2.24 to let older Tumbler NOT do the auto direction (back and forth)
161//! Isue #332
162//! it will set via message: autoMotorDirection
163//! {"set":"autoMotorDirection","val":"true"}
164#define EPROM_STEPPER_AUTO_MOTOR_DIRECTION_SETTING "48a"
165
166//! include these topics groups..
167#define EPROM_INCLUDE_GROUP_NAMES_SETTING "49e"
168
169//!retreives the FACTORY motor direction| true default, clockwise; false = REVERSE, counterclockwise 9.8.22
170//! false = reverse == counterclockwise
171//! true = default
172#define EPROM_STEPPER_CLOCKWISE_MOTOR_DIRECTION_SETTING "50sf"
173
174
175//! issue #338 sensor definition (in work)
176//! This will be a string in JSON format with various PIN and BUS information
177#define EPROM_SENSOR_PLUGS_SETTING "51sp"
178
179//!5.14.25 Dead 5.14.74 Montana
180//! issue #365 Object Oriented Sensors as well
181//! define the sensors (not sensorPlugs). MQTT: set:sensor, set:sensors
182#define EPROM_SENSORS_SETTING "52sensors"
183
184//!8.14.25 Dead Movie from 10.19.1974 tonight..
185//! issue #394 stepperRPM
186//! stepper RPM
187#define EPROM_STEPPER_RPM_SETTING "53sRPM"
188
189//! 9.3.25 back from LA, Horses out. Tyler on lap. Europe next week
190//! sets the 2feed option (go back and forth)
191#define EPROM_STEPPER_2FEED_SETTING "542feed"
192
193//!12.21.25 Winter Solstice party ..
194//! issue #365 Object Oriented Sensors as well
195//! define the sensors (not sensorPlugs). MQTT: set:sensor, set:sensors
196#define EPROM_CHAIN_SENSORS_SETTING "6Chain5snsors"
197
198
199//!the EPROM is in preferences.h
200#include <Preferences.h>
201//!name of main prefs eprom
202#define PREFERENCES_EPROM_MAIN_NAME "MainPrefs"
203
204
205
206//! preferences for MAIN
208//!array of preference names (those used in process()
210//!array of default values to store in the EPROM if not defined..
212//!initialize the _preferencesMainLookup with EPROM lookup names
214
215//!Cache for heavy hitter boolean values (those referenced every loop.. seems to be hard on the EPROM to keep up:
216//! This array will only have the Boolean values set.. the 'save' will fill them, and the 'get' will return
218
219//!array of boolean if the ID is cached..
221
222//! another cache for the Int values..
224
225//!array of boolean if the ID is cached..
227
228//! 8.2.24 retrieve the includeGroup
229//! really ask a topic if it's in the include group
230//! modifies the _
231boolean topicInIncludeGroup(char *topic)
232{
233 // for now just see if topc in groups..
234 //! 8.2.24 just string match for now..
235 //! NOTE: topic is a full path .. but
236 //! MessageArrived: '#FEED {'deviceName':'MaggieMae'}', onTopic=usersP/groups/atlasDogs
237 boolean found = false;
238
239 //! find the topic (eg. usersP/groups/atlasDogs , is atlasDogs
240 char *topicName = rindex(topic,'/');
241 //! go past the "/"
242 topicName++;
243
244 //! go through list..
245 for (int i=0; i< _includeGroupLen; i++)
246 {
247 char *group = _includeGroupsStringArray[i];
248 if (group && strlen(group) == 0)
249 {
250 //!empty is a find .. not specified
251 found = true;
252 break;
253 }
254 //! note "group" the short name is 2nd so it's asking if "/userP/groups/atlasDogs contains string atlasDogs
255 //! that way the topic doesn't need to be parsed.. (although it could be wrong :eg atlas also matches..
256 //if (containsSubstring(topic, group))
257 SerialTemp.printf("compare: %s to %s\n", topicName, group);
258 if (strcmp(topicName, group) == 0)
259 {
260 found = true;
261 break;
262 }
263 }
264 if (_includeGroupLen == 0)
265 {
266 found = true;
267 }
268
269 SerialTemp.printf("topicInIncludeGroup(%s) =%d\n", topicName, found);
270 return found;
271}
272
273//! 8.2.24 set the include group (and cache it), called (indirectly from MQTT via setIncludeGroups
274void parseIncludeGroups(char *groups)
275{
276 SerialTemp.printf("parseIncludeGroups %s\n", groups);
277
278 //! parse the groups (if nothing, then it's ok if no "," use full string)
279 /**
280 The strtok_r() function is a reentrant version strtok(). The saveptr argument is a pointer to a char * variable that is used internally by strtok_r() in order to maintain context between successive calls that parse the same string.
281 On the first call to strtok_r(), str should point to the string to be parsed, and the value of saveptr is ignored. In subsequent calls, str should be NULL, and saveptr should be unchanged since the previous call.
282
283 char *strtok_r(char *str, const char *delim, char **saveptr);
284 @see https://www.tutorialspoint.com/c_standard_library/c_function_strtok.htm
285 @see https://linux.die.net/man/3/strtok_r
286 */
287
289 if (!index(groups,','))
290 {
291 //!no comma
294 SerialTemp.printf("Add Group[%d] %s\n", _includeGroupLen, groups);
295 }
296 else
297 {
298 char *str = groups;
299 char *rest = NULL;
300 char *token;
301 for (token = strtok_r(str,",",&rest); token != NULL; token = strtok_r(NULL, ",", &rest))
302 {
304 SerialTemp.printf("Add Group[%d] %s\n", _includeGroupLen, _includeGroupsStringArray[_includeGroupLen]);
306
307 }
308 }
309}
310
311//! 8.2.24 set the include group (and cache it), called from MQTT
312void setIncludeGroups(char *groups)
313{
314 //!process the groups..
315 parseIncludeGroups(groups);
316
317 //!save persistently
319}
320
321//! called to set a preference (which will be an identifier and a string, which can be converted to a number or boolean)
322void savePreference_mainModule(int preferenceID, String preferenceValue)
323{
324#ifdef NOT_NOW
325 if (preferenceID != PREFERENCE_DEBUG_INFO_SETTING)
326 SerialTemp.printf("savePreference .. %d = '%s'\n", preferenceID, preferenceValue.c_str());
327#endif
328 // cannot invoke the preference, as this would be an infinite loop back to here..
329
330 //save in EPROM
331 _preferencesMainModule.begin(PREFERENCES_EPROM_MAIN_NAME, false); //readwrite..
332 _preferencesMainModule.putString(_preferenceMainModuleLookupEPROMNames[preferenceID], preferenceValue);
333
334 // Close the Preferences
336
337}
338
339//! special preference string for saving and printing back later..
340#define MAX_APPEND 1500
341//!storage for the appending string
343//! called to init the preference. This won't save anything until storePreference called
345{
347}
348
349//! called to init the preference. This won't save anything until storePreference called
351{
353}
354//! called to append to a a preference (which will be an identifier and a string, which can be converted to a number or boolean)
355void appendPreference_mainModule(int preferenceID, String preferenceValue)
356{
358 {
359 SerialDebug.println(" *** preference > max, emptying .. ");
361 }
362 _appendingPreferenceString += "\n" + preferenceValue;
363}
364//! called to append to a a preference (which will be an identifier and a string, which can be converted to a number or boolean)
365void storePreference_mainModule(int preferenceID, String preferenceValue)
366{
367#ifdef AP_DEBUG_MODE
368
369 appendPreference_mainModule(preferenceID, preferenceValue);
370 // SerialDebug.printf("storePref(%d): %s\n", _appendingPreferenceString.length(), _appendingPreferenceString.c_str());
372#else
373 //!turn AP_DEBUG_MODe off for now...
374 //!1.1.24 seems the append is goofing things..
375 savePreference_mainModule(preferenceID, preferenceValue);
376
377#endif
378}
379
380//! called to reset to blank a preference (which will be an identifier and a string, which can be converted to a number or boolean)
381void resetPreference_mainModule(int preferenceID)
382{
383#ifdef DO_ERASE
384 savePreference_mainModule(preferenceID,"");
386#endif
387}
388
389
390//!sets an int preference
391void savePreferenceInt_mainModule(int preferenceID, int val)
392{
393 if (_isCachedPreferenceInt[preferenceID])
394 {
395 //! CACHE SETTINGS 1
396 _cachedPreferenceIntValues[preferenceID] = val;
397 }
398
399 //!convert to a string..
400 char str[20];
401 sprintf(str,"%d",val);
402 savePreference_mainModule(preferenceID, str);
403}
404
405//!sets an int, but only if a valid integer, and no signs. If bad, then a 0 is stored
406void savePreferenceIntFromString_mainModule(int preferenceID, char* val)
407{
408 //This function returns the converted integral number as an int value. If no valid conversion could be performed, it returns zero.
409 int num = atoi(val);
410 savePreferenceInt_mainModule(preferenceID, num);
411}
412
413//!toggles a preference boolean
415{
416 boolean val = getPreferenceBoolean_mainModule(preferenceID);
417 val = !val;
418 savePreferenceBoolean_mainModule(preferenceID, val);
419}
420
421
422
423//! called to get a preference (which will be an identifier and a string, which can be converted to a number or boolean)
424//! Note: no CACHE is looked at here. It's up to the Boolean or Int to do that..
425char* getPreference_mainModule(int preferenceID)
426{
427 // cannot invoke the preference, as this would be an infinite loop back to here..
428
429 //!get from EPROM
431
432 strcpy(_preferenceBuffer, _preferencesMainModule.getString( _preferenceMainModuleLookupEPROMNames[preferenceID]).c_str());
433#define TOOMUCH
434#ifdef TOOMUCH
435 SerialLots.printf("getPreference_mainModule[%d] = %s\n", preferenceID, _preferenceBuffer);
436#endif
437 // Close the Preferences
439 return _preferenceBuffer;
440}
441
442
443//! called to set a preference (which will be an identifier and a string, which can be converted to a number or boolean)
444boolean getPreferenceBoolean_mainModule(int preferenceID)
445{
446 boolean valBool;
447 // check some of the boolean ones
448 if (_isCachedPreferenceBoolean[preferenceID])
449 {
450 //! CACHE SETTINGS 5
451 valBool = _cachedPreferenceBooleanValues[preferenceID];
452#ifdef TOOMUCH
453 SerialLots.print(" CACHE preference = ");
454 SerialLots.printf(" [%d] = ",preferenceID);
455 SerialLots.println(valBool);
456#endif
457 }
458 else
459 {
460 char* val = getPreference_mainModule(preferenceID);
461#ifdef TOOMUCH
462 SerialLots.print(" preference = ");
463 SerialLots.printf(" [%d] = ",preferenceID);
464 SerialLots.println(val);
465#endif
466 valBool = (strcmp(val,"1")==0)?true:false;
467 }
468 return valBool;
469}
470
471//! save a boolean preference
472void savePreferenceBoolean_mainModule(int preferenceID, boolean flag)
473{
474 if (_isCachedPreferenceBoolean[preferenceID])
475 {
476 //! CACHE SETTINGS 5
477 _cachedPreferenceBooleanValues[preferenceID] = flag;
478
479 SerialLots.print(" set CACHE preference");
480 SerialLots.printf(" [%d] = ",preferenceID);
481 SerialLots.println(flag);
482 }
483
484 savePreference_mainModule(preferenceID, flag?(char*)"1":(char*)"0");
485}
486
487
488
489//!returns the preference but in it's own string buffer. As long as you use it before calling getPreferenceString again, it won't be overwritten
490char* getPreferenceString_mainModule(int preferenceID)
491{
494}
495//! called to set a preference (which will be an identifier and a string, which can be converted to a number or boolean)
496int getPreferenceInt_mainModule(int preferenceID)
497{
498 int ival = 0;
499 if (_isCachedPreferenceInt[preferenceID])
500 {
501 ival = _cachedPreferenceIntValues[preferenceID];
502 }
503 else
504 {
505 ival = atoi(getPreference_mainModule(preferenceID));
506 }
507
508 return ival;
509}
510
511//! called to set a preference (which will be an identifier and a string, which can be converted to a number or boolean)
512float getPreferenceFloat_mainModule(int preferenceID)
513{
514 //!TODO: 8.18.24 add a cache for floats ..
515 //!actially cache the string value??
516 char* val = getPreference_mainModule(preferenceID);
517 float fval = atof(val);
518 return fval;
519}
520//! called to set a preference (which will be an identifier and a string, which can be converted to a number or boolean)
521void savePreferenceFloat_mainModule(int preferenceID, float val)
522{
523 //!convert to a string..
524 char str[20];
525 sprintf(str,"%2f",val);
526 savePreference_mainModule(preferenceID, str);
527}
528
529//! clean the preferencesMainModule in EPROM
531{
532 _preferencesMainModule.begin(PREFERENCES_EPROM_MAIN_NAME, false); //readwrite..
535}
536
537//!set some defaults on boot - that override EPROM
538//!This is also called when going back tot he MAIN menu (HOME SCREEN)
540{
541 SerialTemp.println("setOnBootPreferences_mainModule");
542 //!set zoomed = true (no semantic marker)
544
545 //!use the minimal menu on boot
547
548
549}
550
551//! reads the preferences. Save is everytime the savePreference is called
552//! 5.14.25 (Dead 5.14.74 3rd Wall of Sound)
553//! add the Sensors as well..
555{
556 SerialDebug.printf("readPreferences_mainModule(%s)\n",PREFERENCES_EPROM_MAIN_NAME);
557
558 //!clean the cached, and initialize what are cached..
559 for (int i = 0; i < MAX_MAIN_PREFERENCES; i++)
560 {
564 _isCachedPreferenceInt[i] = false;
565 }
566
567 //!intiialize the preferences arrays from EPROM. This also updates the defaults
568 //! BUT: the caches below are from the value retrieved (and defult if need be)
570
571 //! try this 7.25.26 TDF 2nd last stage.. Laura/Paul at Dysney land
572 if (false)
573 {
574 SerialDebug.println(" **** SETTING SOME PREFES for PTStepper ****");
577 savePreference_mainModule(PREFERENCE_SENSORS_SETTING, "BuzzerSensorClass,-1,21");
578
579 }
580
581 //!start the read-write of the EPROM
582 _preferencesMainModule.begin(PREFERENCES_EPROM_MAIN_NAME, false); //readwrite..
583
584 for (int i = 0; i < MAX_MAIN_PREFERENCES; i++)
585 {
586 String preferenceValue;
587 int preferenceID = i;
588 preferenceValue = _preferencesMainModule.getString(_preferenceMainModuleLookupEPROMNames[preferenceID]);
589 //SerialLots.printf("preverenceValue[%s] = %s\n", _preferenceMainModuleLookupEPROMNames[preferenceID], preferenceValue);
590 if (preferenceValue && preferenceValue.length() > 0)
591 {
592 // already set
593 SerialLots.printf(" *** alreadySet %s\n",_preferenceMainModuleLookupEPROMNames[preferenceID] );
594 }
595 else
596 {
597 //otherwise go to the preference defaults
598 preferenceValue = _preferenceMainModuleLookupDefaults[i];
599 _preferencesMainModule.putString(_preferenceMainModuleLookupEPROMNames[preferenceID], preferenceValue);
600 }
601 SerialLots.printf("Preference[%s] = ",_preferenceMainModuleLookupEPROMNames[preferenceID]);
602 SerialLots.println(preferenceValue);
603
604 //! check some of the boolean ones to cache .. so don't have to go to the EPROM everytime..
605 switch (i)
606 {
607 //! 9.4.25 STRANGE: the BOOLEAN aren't working too good
608 //! so removing CLOCKWISE and STEPPER_2FEED
609 //!**** NOTE: THis is where whether things are cached or not is set! Eventually all boolean and int could be cached..
610 //! CACHE SETTINGS (boolean)
620 //!8.2.24
622 //! 9.3.25 strange wasn't working ... if in cache..
623 // case PREFERENCE_STEPPER_2FEED_SETTING:
624 // case PREFERENCE_STEPPER_CLOCKWISE_MOTOR_DIRECTION_SETTING:
625
626 //SerialLots.printf("setting Cached[%d] = %s\n", i, preferenceValue);
628 _cachedPreferenceBooleanValues[i] = (preferenceValue.compareTo("1")==0)?true:false;
629 break;
630 //! CACHE SETTINGS (int)
635
636 _isCachedPreferenceInt[i] = true;
637 _cachedPreferenceIntValues[i] = atoi(&preferenceValue[0]);
638 break;
639
640 //! 8.2.24 set the includeGroups
642 //! grab the state at the start, then it's only modified from a MQTT message
643 {
645 //!save
646 //! parse (do it this way, instead of setIncludeGroups (as that stored in eprom again)
647 parseIncludeGroups(groups);
648 }
649 break;
650#ifdef TODO_THIS_CACHE
651 //! 8.18.24 figure this out ..
652 //! the UNO is not using this .. so let's not worry about it for now ... only Tumbler.
654 {
655 //! do this in the "string" part, not the float part..
656 break;
657 }
658#endif
659 default:
660 break;
661 }
662 }
663 //! Close the Preferences
665
666 //! set onbootPreferences
668
669 //! 5.14.25 (Dead 5.14.74 3rd Wall of Sound)
670 //! add the Sensors as well..
672
673#pragma mark CHAIN
674 //! 1.23.26 do the same for chain
675 //! 1.30.26 THIS is done whether we have the actual buttons or not,
676 //! that is defined which SensorClass -- ChainButtonClassType
678
679}
680
681//!initialize the _preferencesMainLookup with EPROM lookup names
682//!BUT these are not stored in EPROM. The next method
684{
685 SerialDebug.println("***initPreferencesMainModule");
686#ifdef AP_DEBUG_MODE
687#else
688 // savePreference_mainModule(PREFERENCE_DEBUG_INFO_SETTING,"");
690#endif
691
692 strcpy(_preferenceBufferString,(char*)"");
693 strcpy(_preferenceBuffer,(char*)"");
694
695 //! 9.4.25 NOTE: tese are in case the EPROM wasn't set. So the EPROM is used over these values..
696 for (int i = 0; i < MAX_MAIN_PREFERENCES; i++)
697 {
698 switch (i)
699 {
703#ifdef ESP_M5
704 //! 12.27.23 ON for all M5 (the reason is credentials ...)
705#ifdef ESP_M5_CAMERA
706 //!default on for the M5 Camera (but it can be turned on later..)
708#else
709#ifdef ATOM_QRCODE_MODULE
710 //! 12.8.22 default back TRUE
711 //!default off for the M5 (but it can be turned on later..)
713#else
714 //! 12.8.22 default back TRUE
715 //!default off for the M5 (but it can be turned on later..)
717#endif //ATOM
718#endif //ESP_M5_CAMERA
719#else
720 //! 12.8.22 default back TRUE
721 //!default off for the M5 (but it can be turned on later..)
723#endif //ESP_M5
724 SerialLots.printf(" **** setting PREFERENCE_MAIN_BLE_SERVER_VALUE[%d]: %s\n", i,_preferenceMainModuleLookupDefaults[i]);
725 break;
728#ifdef ESP_M5
729 //! 12.27.23 ON for most M5 , but off for the SOCKET
730#ifdef ATOM_SOCKET_MODULE
731 //! only the SOCKET will be off by default for now...
733#else
735#endif
736
737#else
739#endif
740 break;
741 //! Sensor preferences
745 break;
750 break;
751 //!used for first time features..
755 //! This is a feeder that gateways to a GEN3
756#ifdef ESP_32_FEEDER_BLE_GEN3
758#else
759 //! This is a feeder that gateways to a GEN3
761#endif
762 break;
763
764 //INT SETTINGS..
769 break;
770
771
772 //! REST ARE NOT CACHED
773 //These are hard coded default values for the preferences
777 break;
778
779 //! STEPPER preferences (no ifdef.. )
783 break;
787 break;
791 break;
793 /*
794 per issue @269, stepper angle default = 45 (which it has been for awhile)
795 */
798#ifdef ESP_M5
799 //! 5.2.25 default 0.5 SECONDS (not angle for the HDriver
800 _preferenceMainModuleLookupDefaults[i] = (char*)"1.25";
801#else
802 _preferenceMainModuleLookupDefaults[i] = (char*)"22.5";
803#endif
804 break;
807 //! 3.28.23 change default to 5 (from 30)
809 break;
812 //! 11.29.23 add a max so random can be used
814 break;
817 /*
818 #define STEPPER_IS_UNO 1
819 #define STEPPER_IS_MINI 2
820 #define STEPPER_IS_TUMBLER 3
821 per issue @269, default is now Tumbler
822 */
824 break;
827 //! 8.15.26 default to the buzzer OFF
829 break;
833 break;
834
838 break;
842 break;
846 break;
849 _preferenceMainModuleLookupDefaults[i] = (char*)"480";
850 break;
854 break;
859 break;
863 _preferenceMainModuleLookupDefaults[i] = (char*)"NONE";
864 break;
868 _preferenceMainModuleLookupDefaults[i] = (char*)"NONE";
869 break;
873 _preferenceMainModuleLookupDefaults[i] = (char*)"NONE";
874 break;
878# ifdef ESP_M5_CAMERA
879 _preferenceMainModuleLookupDefaults[i] = (char*)"M5Camera";
880# elif defined(ESP_M5_ATOM_S3)
881 _preferenceMainModuleLookupDefaults[i] = (char*)"M5AtomS3";
882# elif defined(ESP_M5_ATOM_LITE)
883 _preferenceMainModuleLookupDefaults[i] = (char*)"M5AtomLite";
884# elif defined(ESP_M5)
886#else
887 _preferenceMainModuleLookupDefaults[i] = (char*)"ESP32";
888#endif
889 break;
890
891 //!set with message: set:bleusedevicename,val:on/off
894 //! 8.18.26 set default OFF
895#define DEFAULT_OFF_BLE_NAME
896#ifdef DEFAULT_OFF_BLE_NAME
898
899#else
900 //! 12.8.22 setting to TRUE as default
902#ifdef ESP_M5
903 //! 1.6.23 .. PetTutor Blue app still not always discovering new syntax
905#else
906 //! 3.24.25 use the BLE name in the feeder too..
908 //_preferenceMainModuleLookupDefaults[i] = (char*)"0";
909
910#endif
911#endif
912 break;
913 //!set with message: set:bleusepaireddevicename,val:on/off
917 break;
918
922 break;
923 //!used for first time features..
928 break;
929
930 //! 8.17.22 to turn on/off subscribing to the dawgpack topic
934#ifdef ESP_M5
936#else
938#endif
939 break;
940
941 //!//! 8.22.22 to turn on/off SPIFF use (not cached yet as it's an infrequent event)
945#ifdef ESP_M5_CAMERA
947#else
949
950#endif
951 break;
952
953 //!the paired device for guest device feeding (6.6.22) .. but the Address 9.3.22
958
959 break;
960
961 ///!retreives the motor direction| 0 (false) = default, clockwise; 1 (true) = REVERSE, counterclockwise 9.8.22
962 //! TRUE = reverse == counterclockwise
963 //! FALSE = default
968
969 break;
970 //! 8.18.24 the factory setting
971 ///!retreives the motor direction| 0 (false) = default, clockwise; 1 (true) = REVERSE, counterclockwise 9.8.22
972 //! TRUE = reverse == counterclockwise
973 //! FALSE = default
978
979 break;
980
981 //! 10.4.22
986
987 break;
988
989 //! 11.1.22 TODO.. messages for this..
994 break;
995
996 //! 7.26.23 added group message support (or turn it off)
997 //! PREFERENCE_SUPPORT_GROUPS_SETTING
998 //! default OFF 1.15.24
999 //! @see https://github.com/konacurrents/ESP_IOT/issues/300
1004 break;
1005
1006 //! 7.26.23 added group message support (or turn it off)
1007 //! PREFERENCE_GROUP_NAMES_SETTING
1008 //! the preference setting group names to subscribe (but empty or # go to wildcard, this also supports wildcard in the future)
1013 break;
1014
1015 //! a place to put some kind of Last Will of what went wrong .. for now (> max tries)
1016 //! 9.16.23
1020 _preferenceMainModuleLookupDefaults[i] = (char*)"none";
1021 break;
1022
1023 //! 9.28.23 #272 only show Semantic Markers that are sent directly to the device, default OFF
1028 break;
1029
1030 //! 1.1.24 first version of preferences for the ATOMs depending on which ATOM kind
1031 //! first version, only the socket and the value is on/off
1032 //! syntaxURL socket=off&smscanner=on
1036 _preferenceMainModuleLookupDefaults[i] = (char*)"socket=off";
1037 break;
1038
1039 //!1.4.24 What kind of ATOM plug (set, M5AtomKind, val= {M5AtomSocket, M5AtomScanner}
1043 _preferenceMainModuleLookupDefaults[i] = (char*)"M5AtomScanner";
1044 break;
1045
1046 //! 1.10.24 The Semantic Marker command is sent on PIR, and the Command to send
1051 break;
1052
1053 //! 1.10.24 The Semantic Marker command is sent on PIR, and the Command to send
1057 _preferenceMainModuleLookupDefaults[i] = (char*)"{'set':'socket','val':'on'}";
1058 break;
1059 //! 1.11.24 The Semantic Marker command is sent on PIR, and the Command to send for OFF
1063 _preferenceMainModuleLookupDefaults[i] = (char*)"{'set':'socket','val':'off'}";
1064 break;
1065
1066 //! 1.12.24 whether global on/off is allowed. Default on..
1071 break;
1072
1073 //!//! 4.4.24 to turn on/off SPIFF use (not cached yet as it's an infrequent event)
1077#ifdef USE_SPIFF_MQTT_SETTING
1079#endif //USE_SPIFF_MQTT_SETTING
1080 break;
1081 //!//! 4.4.24 to turn on/off SPIFF use (not cached yet as it's an infrequent event)
1085#ifdef USE_SPIFF_QRATOM_SETTING
1087#endif //USE_SPIFF_QRATOM_SETTING
1088 break;
1089
1090
1091 //! 8.2.24 to let older Tumbler NOT do the auto direction (back and forth)
1092 //! Isue #332
1093 //! it will set via message: autoMotorDirection
1094 //! {"set":"autoMotorDirection","val":"true"}
1099 break;
1100
1101 //! 8.2.24 include these groups (or none)
1102 //! {"set":"includeGroups","val":"group1,group2"}
1107 break;
1108
1109 //! issue #338 sensor definition (in work)
1110 //! This will be a string in JSON format with various PIN and BUS information
1114 _preferenceMainModuleLookupDefaults[i] = (char*)"L9110S_DCStepperClass";
1115 break;
1116
1117 //! 12.21.25 Winter Solstice, Eagles, Party,
1118 //! these are the CHAIN_SENSORS
1123 break;
1124
1125 //!5.14.25 Dead 5.14.74 Montana
1126 //! issue #365 Object Oriented Sensors as well
1127 //! define the sensors (not sensorPlugs). MQTT: set:sensor, set:sensors
1128 //! 7.9.25 default to BuzzerSensorClass and L9110S_DCStepperClass
1131 (char*)EPROM_SENSORS_SETTING;
1132 _preferenceMainModuleLookupDefaults[i] = (char*)"BuzzerSensorClass,23,33,L9110S_DCStepperClass,21,25";
1133 break;
1134
1135
1136 //!8.14.25 Dead Movie from 10.19.1974 tonight..
1137 //! issue #394 stepperRPM
1138 //! stepper RPM
1142 _preferenceMainModuleLookupDefaults[i] = (char*)"15.0";
1143 break;
1144
1145 //!9.3.25 Dead Movie.. let it grow
1146 //!
1151 SerialLots.println(" ** setting PREFERENCE_STEPPER_2FEED_SETTING = 0");
1152 break;
1153
1154
1155 default:
1156 SerialError.printf(" ** NO default for preference[%d]\n", i);
1157 }
1158 SerialLots.printf("** setting [%d] = %s\n", i, _preferenceMainModuleLookupDefaults[i]);
1159 }
1160}
1161
1162#ifdef NOT_USED
1163//! 7.9.25 reset SENSORS to default
1164//! "BuzzerSensorClass,23,33,L9110S_DCStepperClass,21,25"
1165void resetSensorToDefault_mainModule()
1166{
1167 setSensorsString_mainModule((char*)"BuzzerSensorClass,23,33,L9110S_DCStepperClass,21,25");
1168}
1169#endif
1170
1171//!print the preferences to SerialDebug
1173{
1174 //!this inits the string to the EPROM value
1176
1177#ifdef SERIAL_DEBUG_TEMP
1178 SerialTemp.println("******************");
1179 SerialTemp.println(VERSION);
1180 SerialTemp.printf("CHIP_ID: %s\n", getChipIdString());
1181 SerialTemp.printf("PREFERENCE_DEVICE_NAME_SETTING: %s\n", getPreference_mainModule(PREFERENCE_DEVICE_NAME_SETTING));
1182 {
1183 const char *BLEDeviceName = connectedBLEDeviceName_mainModule()?connectedBLEDeviceName_mainModule():"none";
1184
1185 SerialTemp.printf("CONNECTED_BLE_DEVICE: %s\n", BLEDeviceName);
1186 }
1187 //! 12.24.25 return the username and password, Kevin feature .. he was setting to WIFI acidently. I updated APP to make that harder
1188 //! note on reboot this won't be set until later, so do another ""
1189 SerialTemp.printf("USERNAME: %s\n", main_getUsername());
1190 SerialTemp.printf("PASSWORD: %s\n", main_getPassword());
1191
1192 //ouch.. this sets 2 values ..
1193 // readPreferences_mainModule();
1194 SerialTemp.printf("STEPPER_KIND: %d 1=UNO,2=MINI,3=TUMBLER\n", getPreferenceInt_mainModule(PREFERENCE_STEPPER_KIND_VALUE));
1195 SerialTemp.printf("PREFERENCE_TIMER_INT_SETTING: %d\n", getPreferenceInt_mainModule(PREFERENCE_TIMER_INT_SETTING));
1196 SerialTemp.printf("STEPPER_AUTO_FEED: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_STEPPER_AUTO_FEED_VALUE));
1197 SerialTemp.printf("STEPPER_JACKPOT_FEED: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_STEPPER_JACKPOT_FEED_VALUE));
1198 SerialTemp.printf("PREFERENCE_STEPPER_ANGLE_FLOAT_SETTING: %f\n", getPreferenceFloat_mainModule(PREFERENCE_STEPPER_ANGLE_FLOAT_SETTING));
1199 SerialTemp.printf("STEPPER_FEEDS_PER_JACKPOT: %d\n", getPreferenceInt_mainModule(PREFERENCE_STEPPER_FEEDS_PER_JACKPOT));
1200 SerialTemp.printf("DISPLAY_SCREEN_TIMEOUT: %d\n", getPreferenceInt_mainModule(PREFERENCE_DISPLAY_SCREEN_TIMEOUT_VALUE));
1201 SerialTemp.printf("PREFERENCE_STEPPER_BUZZER_VALUE: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_STEPPER_BUZZER_VALUE));
1202
1203 SerialTemp.printf("PREFERENCE_HIGH_TEMP_POWEROFF_VALUE: %d\n", getPreferenceInt_mainModule(PREFERENCE_HIGH_TEMP_POWEROFF_VALUE));
1204 SerialTemp.printf("PREFERENCE_IS_MINIMAL_MENU_SETTING: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_IS_MINIMAL_MENU_SETTING));
1205 SerialTemp.printf("PREFERENCE_SEMANTIC_MARKER_ZOOMED_VALUE: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_SEMANTIC_MARKER_ZOOMED_VALUE));
1206 SerialTemp.printf("PREFERENCE_NO_BUTTON_CLICK_POWEROFF_SETTING: %d\n", getPreferenceInt_mainModule(PREFERENCE_NO_BUTTON_CLICK_POWEROFF_SETTING));
1207 SerialTemp.printf("PREFERENCE_MAIN_GATEWAY_VALUE: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_MAIN_GATEWAY_VALUE));
1208 SerialTemp.printf("PREFERENCE_SENSOR_TILT_VALUE: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_SENSOR_TILT_VALUE));
1209 SerialTemp.printf("WIFI_CREDENTIAL_1: %s\n", getPreference_mainModule(PREFERENCE_WIFI_CREDENTIAL_1_SETTING));
1210 SerialTemp.printf("WIFI_CREDENTIAL_2: %s\n", getPreference_mainModule(PREFERENCE_WIFI_CREDENTIAL_2_SETTING));
1211 SerialTemp.printf("PREFERENCE_PAIRED_DEVICE_SETTING: %s\n", getPreference_mainModule(PREFERENCE_PAIRED_DEVICE_SETTING));
1212 SerialTemp.printf("PREFERENCE_PAIRED_DEVICE_ADDRESS_SETTING: %s\n", getPreference_mainModule(PREFERENCE_PAIRED_DEVICE_ADDRESS_SETTING));
1213 SerialTemp.printf("PREFERENCE_BLE_SERVER_USE_DEVICE_NAME_SETTING: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_BLE_SERVER_USE_DEVICE_NAME_SETTING));
1214
1215 SerialTemp.printf("PREFERENCE_MAIN_BLE_CLIENT_VALUE: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_MAIN_BLE_CLIENT_VALUE));
1216 SerialTemp.printf("PREFERENCE_MAIN_BLE_SERVER_VALUE: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_MAIN_BLE_SERVER_VALUE));
1217
1218#ifdef TOO_SOON
1219 //! DARN: the class hasn't been instantiated yet ...
1220 //! 10.10.25 #405 #406
1221 //! see if the device is a PTClicker if the M5Atom class is one..
1222 //! return the service name: PTClicker or PTFeeder
1223 SerialTemp.printf("PREFERENCE_BLE_SERVER_NAME: %s:%s\n", getServerServiceName_mainModule(),getPreference_mainModule(PREFERENCE_DEVICE_NAME_SETTING));
1224#endif
1225 SerialTemp.printf("PREFERENCE_FIRST_TIME_FEATURE_SETTING: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_FIRST_TIME_FEATURE_SETTING));
1226 SerialTemp.printf("PREFERENCE_SCREEN_COLOR_SETTING: %d\n", getPreferenceInt_mainModule(PREFERENCE_SCREEN_COLOR_SETTING));
1227
1228 SerialTemp.printf("PREFERENCE_SUB_DAWGPACK_SETTING: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_SUB_DAWGPACK_SETTING));
1229 SerialTemp.printf("PREFERENCE_STEPPER_CLOCKWISE_MOTOR_DIRECTION_SETTING: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_STEPPER_CLOCKWISE_MOTOR_DIRECTION_SETTING));
1230 SerialTemp.printf("PREFERENCE_STEPPER_FACTORY_CLOCKWISE_MOTOR_DIRECTION_SETTING: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_STEPPER_FACTORY_CLOCKWISE_MOTOR_DIRECTION_SETTING));
1231 SerialTemp.printf("AUTO_MOTOR_DIRECTION: %d 1=reverseEachTime,2=dont\n", getPreferenceBoolean_mainModule(PREFERENCE_STEPPER_AUTO_MOTOR_DIRECTION_SETTING));
1232 //! don't change subscription but include these groups (eg. safeHouse,atlasDogs)
1233 SerialTemp.printf("PREFERENCE_INCLUDE_GROUP_NAMES_SETTING: %s\n", getPreference_mainModule(PREFERENCE_INCLUDE_GROUP_NAMES_SETTING));
1234 SerialTemp.printf("PREFERENCE_SENDWIFI_WITH_BLE: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_SENDWIFI_WITH_BLE));
1235 SerialTemp.printf("PREFERENCE_ONLY_GEN3_CONNECT_SETTING: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_ONLY_GEN3_CONNECT_SETTING));
1236 SerialTemp.printf("PREFERENCE_SUPPORT_GROUPS_SETTING: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_SUPPORT_GROUPS_SETTING));
1237 SerialTemp.printf("PREFERENCE_GROUP_NAMES_SETTING: %s\n", getPreference_mainModule(PREFERENCE_GROUP_NAMES_SETTING));
1238 SerialTemp.printf("PREFERENCE_DEV_ONLY_SM_SETTING: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_DEV_ONLY_SM_SETTING));
1239
1240 SerialTemp.printf("PREFERENCE_ATOMS_SETTING: %s\n", getPreference_mainModule(PREFERENCE_ATOMS_SETTING));
1241 SerialTemp.printf("PREFERENCE_ATOM_KIND_SETTING (M5AtomClassType): %s\n", getPreference_mainModule(PREFERENCE_ATOM_KIND_SETTING));
1242
1243 //! 1.10.24 Flag on whether a Semantic Marker command is sent on PIR, and the Command to send
1244 SerialTemp.printf("PREFERENCE_SM_ON_PIR_SETTING: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_SM_ON_PIR_SETTING));
1245 //! 1.10.24 The Semantic Marker command is sent on PIR, and the Command to send
1246 SerialTemp.printf("PREFERENCE_SM_COMMAND_PIR_SETTING: %s\n", getPreference_mainModule(PREFERENCE_SM_COMMAND_PIR_SETTING));
1247 //! 1.11.24 The Semantic Marker command is sent on PIR, and the Command to send
1248 SerialTemp.printf("PREFERENCE_SM_COMMAND_PIR_OFF_SETTING: %s\n", getPreference_mainModule(PREFERENCE_SM_COMMAND_PIR_OFF_SETTING));
1249 //! 1.12.24 The Semantic Marker command is sent on PIR, and the Command to send
1250 SerialTemp.printf("PREFERENCE_ATOM_SOCKET_GLOBAL_ONOFF_SETTING: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_ATOM_SOCKET_GLOBAL_ONOFF_SETTING));
1251
1252 SerialTemp.printf("PREFERENCE_SENSOR_PLUGS_SETTING (MotorStepperClassType): %s\n", getPreference_mainModule(PREFERENCE_SENSOR_PLUGS_SETTING));
1253
1254 //! 5.14.25
1255 SerialTemp.printf("PREFERENCE_SENSORS_SETTING: %s\n", getPreference_mainModule(PREFERENCE_SENSORS_SETTING));
1256
1257 //! 12.21.25
1258 //! 5.14.25
1259 SerialTemp.printf("PREFERENCE_CHAIN_SENSORS_SETTING: %s\n", getPreference_mainModule(PREFERENCE_CHAIN_SENSORS_SETTING));
1260
1261 //!8.14.25 Dead Movie from 10.19.1974 tonight..
1262 //! issue #394 stepperRPM
1263 //! stepper RPM
1264 SerialTemp.printf("PREFERENCE_STEPPER_RPM_SETTING: %s\n", getPreference_mainModule(PREFERENCE_STEPPER_RPM_SETTING));
1265
1266 //! 9.3.25 back from LA, Horses out. Tyler on lap. Europe next week
1267 //! sets the 2feed option (go back and forth)
1268 SerialTemp.printf("PREFERENCE_STEPPER_2FEED_SETTING: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_STEPPER_2FEED_SETTING));
1269
1270
1271#ifdef M5CORE2_MODULE
1272 SerialTemp.printf("PREFERENCE_M5Core2_SETTING:\n");
1273#endif
1274#if (SERIAL_DEBUG_CALL)
1275 // this is many lines long .. so only show in the CALL settting..
1276 SerialTemp.printf("PREFERENCE_DEBUG_INFO_SETTING: %s\n", getPreference_mainModule(PREFERENCE_DEBUG_INFO_SETTING));
1277#endif
1278
1279
1280 SerialTemp.printf("WIFI_CREDENTIAL: %s\n", main_JSONStringForWIFICredentials());
1281 //!retrieve a JSON string for the ssid and ssid_password: {'ssid':<ssid>,'ssidPassword':<pass>"}
1282
1283 //! 5.14.25 also print out the sensors
1284 //! print sensors
1286
1287 //! 4.28.26 home alone with Tyler and Spike. Kids Q&A comming over for Spaghetti
1288 //! print the
1289 ///! retrieve the Configuration JSON string in JSON format..
1290 String JSONConfigString = getJSONConfigString();
1291 SerialTemp.println("");
1292 SerialTemp.print("JSONconfig: ");
1293 SerialTemp.print(JSONConfigString);
1294 SerialTemp.println("");
1295 SerialTemp.println("");
1296
1297
1298 if (false)
1299 //! 1.24.26 Clear day .. 2 eagles again on walk
1301
1302 if (false)
1303 {
1304
1305 //! 7.31.25
1306 SerialTemp.println(" *** Example JSON messages you can modify and paste into serial monitor, no DEV required");
1307 //! TODO: add preference to not support this??
1308 //! show example JSON (break up as getPreference re-uses same string...
1309 SerialTemp.printf("{\"set\":\"sensors\",\"val\":\"%s\"}", (char*)"BuzzerSensorClass,19,22,L9110S_DCStepperClass,21,25");
1310 SerialTemp.println();
1311 // SerialTemp.printf("{\"set\":\"sensors\",\"val\":\"%s\"}", (char*)"BuzzerSensorClass,21,25,ULN2003_StepperClass,23,33");
1312 // SerialTemp.println();
1313 SerialTemp.printf("{\"set\":\"sensors\",\"val\":\"%s\"}", (char*)"PIRSensorClass,23,33");
1314 SerialTemp.println();
1315 SerialTemp.printf("{\"set\":\"sensorPlugs\",\"val\":\"L9110S_DCStepperClass\"}");
1316 SerialTemp.println();
1317 SerialTemp.printf("{\"set\":\"M5AtomKind\",\"val\":\"M5HDriver\"}");
1318 SerialTemp.println();
1319 // SerialTemp.printf("{\"set\":\"stepperAngle\",\"val\":\"0.25\"} ");
1320 // SerialTemp.println();
1321 // SerialTemp.printf("{\"set\":\"stepperRPM\",\"val\":\"15.0\"}");
1322 // SerialTemp.println();
1323 // SerialTemp.printf("{\"set\":\"stepperAngle\",\"val\":\"2048.0\"}");
1324 // SerialTemp.println();
1325 SerialTemp.printf("{\"set\":\"stepperAngle\",\"val\":\"250\"} --new Feeder");
1326 SerialTemp.println();
1327
1328
1329 SerialDebug.println("{\"ssid\":\"Bob\", \"ssidPassword\":\"scott\"}");
1330 //SerialDebug.println("{\"set\":\"2feed\", \"val\":\"1\"}");
1331 SerialDebug.println("{\"set\":\"BLEUseDeviceName\", \"val\":\"off\"}");
1332 SerialDebug.println("FEED ALL");
1333 SerialDebug.println("{\"cmd\":\"feed\"}");
1334
1335 }
1336
1337 //! 7.31.25 PIN USE
1338 PinUseStruct* pinUseStruct = getPinUseStruct_mainModule();
1339 SerialTemp.printf(" *** PIN USE (%d) .. check for duplicated done next .. look for 'ERROR' \n", pinUseStruct->pinUseCount);
1340
1341 for (int i=0; i< pinUseStruct->pinUseCount; i++)
1342 {
1343 SerialTemp.println(pinUseStruct->pinUseArray[i]);
1344 }
1345 SerialLots.printf(" *** PIN Count = %d\n", pinUseStruct->pinUseCount);
1346
1347 //! this needs to have a long pin in the array as well
1348 //! 8.30.25 check if duplicates
1349 //! @see https://stackoverflow.com/questions/8199403/how-to-check-if-an-array-has-any-duplicates
1350 int count = pinUseStruct->pinUseCount;
1351 boolean duplicatePins = false;
1352
1353 for (int i = 0; i < count - 1; i++)
1354 {
1355 for (int j = i + 1; j < count; j++)
1356 {
1357 long pin1 = pinUseStruct->pinNumArray[i];
1358 long pin2 = pinUseStruct->pinNumArray[j];
1359 if (pin1 == pin2)
1360 {
1361 // do whatever you do in case of a duplicate
1362 duplicatePins = true;
1363 SerialError.printf("*** ERROR: DUPLICATE PIN: %d, (%s) == (%s)\n",pin1, pinUseStruct->pinUseArray[i], pinUseStruct->pinUseArray[j]);
1364 }
1365 }
1366 }
1367
1368#endif
1369}
1370
1371
1372//!resets preferences.. Currently only reset all, but eventually reset(groups..)
1374{
1375// savePreferenceBoolean_mainModule(PREFERENCE_SENDWIFI_WITH_BLE, false);
1376// savePreferenceInt_mainModule(PREFERENCE_TIMER_INT_SETTING, 30);
1377
1378 SerialLots.println("Clean EPROM.. ");
1379 //! dispatches a call to the command specified. This is run on the next loop()
1381
1382}
1383
1384boolean _DiscoverM5PTClicker = false;
1385//!transient for now... 10.4.22
1386//! set the M5 PTClicker discovery option..
1387void setDiscoverM5PTClicker(boolean flag)
1388{
1389 SerialTemp.println("Setting _DiscoverM5PTClicker");
1390 _DiscoverM5PTClicker = flag;
1391}
1392//! get option
1394{
1395 return _DiscoverM5PTClicker;
1396}
1397
1398
1399//! if the preference was retrieved..
1400boolean _firstTimeAtomKind = true;
1402//!returned from mainModule
1403//#define ATOM_KIND_M5_SCANNER 0
1404//#define ATOM_KIND_M5_SOCKET 1
1405//! new 1.4.24 setting ATOM kind (eg. M5AtomSocket, M5AtomScanner)
1406//! 1.5.24 also set the initial atom storage
1407//! Then the device reboots.. so setup() and loop() are for the correct ATOM
1409{
1410 SerialDebug.printf("M5AtomKind = %s\n", value.c_str());
1411 _firstTimeAtomKind = true;
1413
1414 //! 1.5.24 also set the initial atom storage
1415 //! 1.4.24 use the _atomKind (which CAN change)
1416 switch (getM5ATOMKind_MainModule())
1417 {
1419 //! 8.1.23 for the ATOM Lite QRCode Reader
1421 break;
1423 //! 12.26.23 for the ATOM Socket Power
1425 break;
1426 }
1427
1428}
1429//! new 1.4.24 setting ATOM kind (eg. M5AtomSocket, M5AtomScanner)
1431{
1433 return atomKind;
1434}
1435
1436//! new 1.4.24 setting ATOM kind (eg. ATOM_KIND_M5_SCANNER, ATOM_KIND_M5_SOCKET)
1437//! sets global _ATOM_KIND
1439{
1440 //! optimize to only call this retrieval from EPROM 1 time.. unless changing the ATOMKind
1442 {
1443 char *atomKind = getPreferenceATOMKind_MainModule();
1444 if (strcasecmp(atomKind,"M5AtomScanner")==0)
1445 {
1447 }
1448 else if (strcasecmp(atomKind,"M5AtomSocket")==0)
1449 {
1451 }
1452 _firstTimeAtomKind = false;
1453 }
1454 return _ATOM_KIND;
1455}
1456
1457#define NEW_SENSORS_PREFERENCE
1458//! 5.14.25 Hanging with Tyler,
1459//! Dead Montana 5.14.74 great stuff
1460//! add the Sensors Preference .. first the parsing
1461//! 10.26.25 Power Out, Wind Storm, Tyler handing ..
1462//! remove the PRINT
1463
1464//! the memory for the sensorsEPROM
1465#ifdef ESP_M5_ATOM_S3
1466//! 7.12.26 lots of room
1467char _sensorsEPROM[1000];
1468#else
1469char _sensorsEPROM[500];
1470#endif
1471
1472
1473//! array of sensorStruct
1475
1476//! return array of SensorsStruct after parsing string syntax: {SENSOR,pin1,pin2}
1478
1479
1480
1481//! print sensor
1483{
1484 if (sensor)
1485 SerialDebug.printf("SENSOR: %s,%d,%d\n", sensor->sensorName, sensor->pin1, sensor->pin2);
1486 else
1487 SerialDebug.printf("SENSOR: **** Null sensor ***\n");
1488}
1489
1490
1491//! print sensors, passing in a struct
1493{
1494 int count = sensors->count;
1495 SerialDebug.printf("DEFINED_SENSORS SensorClassType (%ld):\n", count);
1496 SerialDebug.printf(" ******** \n");
1497 for (int i=0; i< count; i++)
1498 {
1499 SerialDebug.println(" print sensor 1");
1500 printSensor_mainModule(&sensors->sensors[i]);
1501 SerialDebug.println(" DONE print sensor 1");
1502
1503 }
1504 SerialDebug.printf(" ******** \n");
1505}
1506
1507//! return the sensors defined
1509{
1511}
1512
1513//! return the sensor specified or null
1515{
1516 SensorStruct *sensor = NULL;
1518 {
1519 SerialDebug.println(" **** sensorsStructs_mainModule NULL ****");
1520 return NULL;
1521 }
1522
1523 int count = _sensorsStructs_mainModule->count;
1524 for (int i=0; i< count; i++)
1525 {
1526 if (strcmp(_sensorsStructs_mainModule->sensors[i].sensorName, sensorName) == 0)
1527 {
1528 sensor = &_sensorsStructs_mainModule->sensors[i];
1529 break;
1530 }
1531 }
1532// if (!sensor)
1533// SerialDebug.printf("*** No sensor: %s\n", sensorName);
1534 return sensor;
1535}
1536
1537//! Only 1 setSensorsString now .. will always append
1538//! unless a null or blank "" string
1539//! set a sensor val (array of sensor,pin,pin,sensor,pin,pin...)
1540void setSensorsString_mainModule(char *sensorsString)
1541{
1542 //! for now .. resetting
1543 //! 5.17.25
1544 strcpy(_sensorsEPROM, "");
1545
1546 SerialDebug.printf("setSensorsString_mainModule(%s)\n", sensorsString);
1547 //! init EPROM
1548 if (!sensorsString || strlen(sensorsString)==0)
1549 strcpy(_sensorsEPROM, "");
1550 else if (strlen(_sensorsEPROM) > 0)
1551 {
1552 // add a ','
1553 strcat(_sensorsEPROM, ",");
1554 }
1555 strcat(_sensorsEPROM, sensorsString);
1556
1557 //! store in EPROM
1559
1560 //! Parse to the global..
1562 SerialDebug.printf("setSensors:_sensorsStructs_mainModule = %d\n", _sensorsStructs_mainModule);
1563}
1564
1565//! init the sensorString from EPROM
1566//!PREFERENCE_SENSOR_PLUGS_SETTING
1568{
1569 SerialDebug.println("**** initSensorStringsFromEPROM_mainModule ****");
1571 //! Parse to the global..
1573 SerialDebug.printf("initSensors:_sensorsStructs_mainModule = %d\n", _sensorsStructs_mainModule);
1574
1575}
1576
1577
1578//! copy string
1580{
1581 char *copy = strdup(str);
1582 return copy;
1583}
1584
1585
1586//! 3.29.25 Raiiiinier Beeer movie last night
1587//! 5.13.25 Home with Tyler, Mom in LA
1588//! Foundation triligy..
1589//! parseSensorString_mainModule the string
1591{
1592 //! result
1593 SensorsStruct *sensors;
1594 //! default create memory for the SensorsStruct which holds all the sensors..
1595 //! the array will be created on the 2nd pass
1596 sensors = (SensorsStruct*) calloc(1,sizeof(SensorsStruct));
1597 sensors->count = 0;
1598 sensors->sensors = NULL;
1599
1600 //! syntax: sensor,pin1,pin2
1601 SerialDebug.printf("*** parseSensorString_mainModule: %s\n", sensorsString);
1602
1603 if (!sensorsString || strlen(sensorsString)==0)
1604 {
1605 SerialDebug.println("parseSensorString_mainModule: *** No Sensors or string **");
1606 return sensors;
1607 }
1608
1609 char *rest = NULL;
1610 char *token;
1611 int arrayIndex = 0;
1612
1613 //! needed to copy sensorsString.. as the code below broke the callers' value to "https:" .. SIDE EFFECT
1614 char str[300];
1615 char strCopy[300];
1616 strcpy(str,sensorsString);
1617 strcpy(strCopy,sensorsString);
1618
1619 //! resulting array
1620 SensorStruct *sensorItems;
1621
1622 //! number of sensors
1623 int numSensors;
1624
1625 //! 2 pass
1626 for (int whichPass = 0; whichPass<2; whichPass++)
1627 {
1628#define secondPass (whichPass == 1)
1629 int max = 3;
1630
1631 if (secondPass)
1632 {
1633 numSensors = arrayIndex / max;
1634 strcpy(str,strCopy);
1635 SerialDebug.printf(" ** Create sensors %d\n", numSensors);
1636 sensorItems= (SensorStruct*) calloc(numSensors,sizeof(SensorStruct));
1637 }
1638
1639 //! reset arrayIndex (which will be increments of 3)
1640 arrayIndex = 0;
1641
1642 //! 2 pass, first count, 2nd parseSensorString_mainModule
1643
1644 //! look for tokens, comma seperated
1645 //! 7.14.26 nice day. almost 45th wedding anniversery with Laura Babe.. 18th.
1646 //! this will support ,-1,32 (the -1 syntax)
1647 for (char *token= strtok(str,","); token!= NULL; token= strtok(NULL, ","))
1648 {
1649 int indexInSensor = arrayIndex / max;
1650 int indexInArray = arrayIndex % max;
1651 //SerialDebug.printf("%d Token[%d] = %s\n",indexInArray, indexInSensor, token);
1652
1653 //! which of the max is this..
1654 switch (indexInArray)
1655 {
1656 case 0:
1657 {
1658 if (secondPass)
1659 {
1660 //SerialDebug.printf("Sensor = %s\n", token);
1661 sensorItems[indexInSensor].sensorName = copyString_mainModule(token);
1662
1663 //! empty the class
1664 sensorItems[indexInSensor].sensorClassType = NULL;
1665
1666 }
1667 break;
1668 }
1669 case 1:
1670 {
1671 if (secondPass)
1672 {
1673 //! 7.14.26 this should work with -1 (which we are using for 1 pin is PWR)
1674 int pin = atoi(token);
1675#ifdef ESP_M5_ATOM_S3
1676#else
1677 if (pin == 16 || pin == 17)
1678 {
1679 //!@see https://www.reddit.com/r/arduino/comments/1g89dlo/esp32_crashing_due_to_pinmode_and_fastled/
1680 SerialDebug.printf("*** BAD PIN: %d, setting to 22 ***\n", pin);
1681 pin = 22;
1682 }
1683#endif
1684 //SerialDebug.printf("Pin1= %d\n", pin);
1685 sensorItems[indexInSensor].pin1= pin;
1686 }
1687 break;
1688 }
1689 case 2:
1690 {
1691 if (secondPass)
1692 {
1693 //! 7.14.26 this should work with -1 (which we are using for 1 pin is PWR)
1694 int pin = atoi(token);
1695#ifdef ESP_M5_ATOM_S3
1696#else
1697 if (pin == 16 || pin == 17)
1698 {
1699 SerialDebug.printf("*** BAD PIN: %d, setting to 22 ***\n", pin);
1700 pin = 22;
1701 }
1702#endif
1703 //SerialDebug.printf("Pin2= %d\n", pin);
1704 sensorItems[indexInSensor].pin2= pin;
1705 }
1706 break;
1707 }
1708 }
1709 //! only incremnet arrayIndex when
1710 arrayIndex++;
1711 }
1712 }
1713
1714 //! update the result (storage already created)
1715 sensors->count = numSensors;
1716 sensors->sensors = sensorItems;
1717
1718 SerialDebug.printf("parseSensorString_mainModule: ** sensors->count = %ld\n", sensors->count);
1719 return sensors;
1720}
1721
1722#pragma mark CHAIN
1723
1724#pragma mark CHAIN_STRUCT
1725/**
1726
1727 typedef struct {
1728 //! number of chain
1729 int chainUseCount;
1730 //! the buton numbers
1731 int buttonNumberArray[PIN_USE_MAX];
1732 //! the set strings, val strings, device strings
1733 char *setStringArray[PIN_USE_MAX];
1734 //! val strings
1735 char *valStringArray[PIN_USE_MAX];
1736 //! the device strings
1737 char *deviceStringArray[PIN_USE_MAX];
1738
1739 } ChainUseStruct;
1740 */
1741
1742//! global for use. This is an object (not a pointer) and has all the storage created statically
1744//! get the pin use array
1746{
1747 return _chainUseStruct;
1748}
1749
1750
1751//! 1.23.26 storage for the chain sensors EPROM value ..
1752//! the memory for the chainSensorsEPROM
1754//! 1.23.26 Cold, Clear, Mt Nice ... need to use the version above with 5 items ..
1755//! pointer to the ChainSensors
1756//! return array of ChainUseStruct after parsing string syntax: {SENSOR,pin1,pin2}
1758{
1759 //! syntax: sensor,pin1,pin2
1760 SerialDebug.printf("*** parseChainSensorString_mainModule: %s\n", chainUseString);
1761
1762 //! result
1763 ChainUseStruct *chainUseStruct = (ChainUseStruct*) calloc(1,sizeof(ChainUseStruct));
1764 //! default
1765 chainUseStruct->chainUseCount = 0;
1766 //! create memory.. (the 2nd pass would do this in the future ...)
1767 chainUseStruct->chainButtonStructArray = (ChainButtonStruct*) calloc(CHAIN_USE_MAX, sizeof(ChainButtonStruct));
1768
1769 //! TEMP .. until parse working ... will do the same as registerChain does..
1770
1771 return chainUseStruct;
1772}
1773
1774//! 1.23.26 Cold, Clear, Mt Nice ... need to use the version above with 5 items ..
1775//! pointer to the ChainSensors
1776//! return array of ChainUseStruct after parsing string syntax: {SENSOR,pin1,pin2}
1778{
1779 //! syntax: sensor,pin1,pin2
1780 SerialDebug.printf("*** parseChainSensorString_mainModuleNEW:\n%s\n", chainUseString);
1781
1782 //! result
1783 ChainUseStruct *chainUseStruct = (ChainUseStruct*) calloc(1,sizeof(ChainUseStruct));
1784 //! default
1785 chainUseStruct->chainUseCount = 0;
1786
1787 if (!chainUseString || strlen(chainUseString)==0)
1788 {
1789 SerialDebug.println("parseSensorString_mainModule: *** No chainUseString or string **");
1790 return chainUseStruct;
1791 }
1792
1793 char *rest = NULL;
1794 char *token;
1795 int arrayIndex = 0;
1796
1797 //! needed to copy sensorsString.. as the code below broke the callers' value to "https:" .. SIDE EFFECT
1798 //! upded length 8.8.26 after Bike Ride, Less Smoke,
1799#define MAX_CHAIN_STRING 600
1800 char str[MAX_CHAIN_STRING];
1801 char strCopy[MAX_CHAIN_STRING];
1802 if (strlen(chainUseString) > MAX_CHAIN_STRING)
1803 {
1804 SerialDebug.printf("ChainUseString length too big %d\n", strlen(chainUseString));
1805 return NULL;
1806 }
1807 strcpy(str,chainUseString);
1808 strcpy(strCopy,chainUseString);
1809
1810 //! resulting array
1811 ChainButtonStruct *chainButtonStructs;
1812
1813 //! number of sensors
1814 int numChainStructs;
1815
1816 //char *str = "BC,1,1,feed,,$localhost,
1817 // BC,1,2,feed,,,
1818 // BC,2,2,SM_Matrix,6,$dev,
1819 // BC,2,3, togglesocket,,M5AtomSocket,
1820 //! 2 pass
1821 for (int whichPass = 0; whichPass<2; whichPass++)
1822 {
1823#define secondPass (whichPass == 1)
1824 //! for this we have MAX = 6
1825 int max = 6;
1826
1827 if (secondPass)
1828 {
1829 //! create the storage
1830 numChainStructs = arrayIndex / max;
1831 strcpy(str,strCopy);
1832 SerialLots.printf(" ** Create sensors %d\n", numChainStructs);
1833 chainButtonStructs= (ChainButtonStruct*) calloc(numChainStructs,sizeof(ChainButtonStruct));
1834 chainUseStruct->chainButtonStructArray = chainButtonStructs;
1835
1836 }
1837
1838 //! reset arrayIndex (which will be increments of 3)
1839 arrayIndex = 0;
1840
1841 //! 2 pass, first count, 2nd parseSensorString_mainModule
1842
1843 //! look for tokens, comma seperated (SEEMS cannot be null or empty .. ?? eg ,,,,
1844 for (char *token= strtok(str,","); token!= NULL; token= strtok(NULL, ","))
1845 {
1846 int indexInSensor = arrayIndex / max;
1847 int indexInArray = arrayIndex % max;
1848 SerialLots.printf("%d Token[%d] = %s\n",indexInArray, indexInSensor, token);
1849
1850 if (!secondPass)
1851 {
1852 //! continut loop .. but increment (since code below wont' increment)
1853 arrayIndex++;
1854 continue;
1855
1856 }
1857
1858 //! which of the max is this..
1859 //! "BC,1,1,feed,,$localhost, <string> <int> <int> <string> <string> <string>
1860 switch (indexInArray)
1861 {
1862 case 0: // <string>
1863 {
1864 //TODO: strip the spaces of this token
1865 chainButtonStructs[indexInSensor].classType = copyString_mainModule(token);
1866 }
1867 break;
1868 case 1: // <int>
1869 {
1870 int num = atoi(token);
1871 chainButtonStructs[indexInSensor].buttonNumber = num;
1872 }
1873 break;
1874 case 2: // <int>
1875 {
1876 int num = atoi(token);
1877 chainButtonStructs[indexInSensor].pressKind = num;
1878 }
1879 break;
1880 case 3: // <string> setString
1881 chainButtonStructs[indexInSensor].setString = copyString_mainModule(token);
1882 break;
1883 case 4: // <string> valString
1884 chainButtonStructs[indexInSensor].valString = copyString_mainModule(token);
1885 break;
1886 case 5: // <string> device
1887 chainButtonStructs[indexInSensor].deviceString = copyString_mainModule(token);
1888
1889 {
1890 //! update the chain use string ..
1891 char chainUseSample[200];
1892 sprintf(chainUseSample,"CHAIN_USE: %s press=%d btn=%2d set= %s, val=%s dev=%s",chainButtonStructs[indexInSensor].classType, chainButtonStructs[indexInSensor].pressKind, chainButtonStructs[indexInSensor].buttonNumber, chainButtonStructs[indexInSensor].setString, chainButtonStructs[indexInSensor].valString, chainButtonStructs[indexInSensor].deviceString);
1893 chainButtonStructs[indexInSensor].chainUse = copyString_mainModule(chainUseSample);
1894 }
1895 break;
1896 }
1897
1898 //! only incremnet arrayIndex when
1899 arrayIndex++;
1900 }
1901 }
1902
1903 //! update the result (storage already created)
1904 chainUseStruct->chainUseCount = numChainStructs;
1905 chainUseStruct->chainButtonStructArray = chainButtonStructs;
1906
1907 SerialDebug.printf("parseSensorString_mainModule: ** sensors->count = %ld\n", numChainStructs);
1908
1909 return chainUseStruct;
1910}
1911
1912//! 2.9.26 TODO .. use this for good ...
1913//! just try parsing for now..
1915{
1916
1917 //! 200 fixed problem..
1918 char str[400];
1919 //! needs spaces between "," or won't find them .. FIX THIS ..
1920 //strcpy(str,"BC,1,1,feed, ,$localhost, BC,1,2,feed, , , BC,2,2,SM_Matrix,6,$dev, BC,2,3, togglesocket, ,M5AtomSocket");
1921 strcpy(str,(char*)"BC,0,0,feed, ,$localhost,BC,0,2,feed, , ,BC,1,0,feed, ,$localhost,BC,1,2,feed, , ,BC,2,2,SM_MatrixCell,6,$dev,BC,2,1,togglesocket, ,M5AtomSocket,BC,2,0,togglesocket, ,M5AtomSocket,JC,3,0,feed, ,$localhost,JC,3,100,feed, , ,JC,3,101,togglesocket, ,M5AtomSocket,JC,3,102,feed, , ,JC,3,103,$SMART,QHmwUurxC3.1703806697279,");
1922
1923 //! parse it
1925 //! print it
1926 printChainSensors_mainModule(chainUseStruct);
1927
1928 SerialDebug.println("DONE testParse");
1929
1930 //! bombing after this..
1931}
1932
1933#pragma mark CHAIN
1934//!TODO add code here
1935//! 1.23.26 storage for the chain sensors EPROM value ..
1936//!PREFERENCE_CHAIN_SENSORS_SETTING
1937//!FIRST do the registration maniually .. LATER .. parseSensros
1939{
1941 SerialDebug.printf("initSensors:initChainSensorStringsFromEPROM_mainModule = '%s'\n", _chainSensorsEPROM);
1942
1943 //! Parse to the global..
1944 //! TODO .. finish this (it should parse the structure like testParse() and do all the registerChain calls..
1946
1947 //! add this which is Button -0 (not a Chain button).
1948 //! So if a message comes in for button 0 .. it can find this one..
1949 registerChain_mainModule("BC", 0, BUTTON_SHORT_PRESS, "feed", "", "$localhost" );
1950 registerChain_mainModule("BC", 0, BUTTON_DOUBLE_PRESS,"feed", "", "" ); //wifi feed, or BLE if connected as well with the !dev
1951
1952 //TODO: long press is the AP mode...
1953 //registerChain_mainModule("BC", 0, BUTTON_LONG_PRESS, clean credentials ... eg. "x" local .. something..
1954
1955 //! TODO: the following would use the testParse
1956 //! has to be after the _chainUseStruct global is set...
1957 if (true)
1958 {
1959 //! idea is you define the button and the press kind
1960 //! MatrixCell is Column Major 1,4, 7 // 2,5,8 // 3,6,9
1961 registerChain_mainModule("BC", 1, BUTTON_SHORT_PRESS, "feed", "", "$localhost" );
1962 registerChain_mainModule("BC", 1, BUTTON_DOUBLE_PRESS, "feed", "", "" ); //wifi
1963
1964 // registerChain_mainModule("BC", 2, BUTTON_SHORT_PRESS, "SM_MatrixCell", "5", "$dev" );
1965 registerChain_mainModule("BC", 2, BUTTON_DOUBLE_PRESS, "SM_MatrixCell", "6", "$dev");
1966 //{"cmd":"togglesocket","dev":"M5AtomSocket"}
1967 registerChain_mainModule("BC", 2, BUTTON_LONG_PRESS, "togglesocket", "", "M5AtomSocket");
1968 registerChain_mainModule("BC", 2, BUTTON_SHORT_PRESS, "togglesocket", "", "M5AtomSocket");
1969
1970 //!joystick buttons..
1971 //registerChain_mainModule("JC", 3, BUTTON_SHORT_PRESS, "feed", "", "$localhost" );
1972 //! 1.24.26 don't know what to do yet ... x,y (or left, top, right, botton ??)
1973 //registerChain_mainModule("JC", 3, BUTTON_JOYSTICK_LEFT, "status", "", "" );
1974 registerChain_mainModule("JC", 3, BUTTON_JOYSTICK_TOP, "togglesocket", "", "M5AtomSocket");
1975 registerChain_mainModule("JC", 3, BUTTON_JOYSTICK_RIGHT, "feed", "", "" );
1976 //registerChain_mainModule("JC", 3, BUTTON_JOYSTICK_BOTTOM, "status", "", "" );
1977
1978 //! 2.9.26 try the new smartDefn indirect button
1979 //! this has a future text with MQTT defined
1980 registerChain_mainModule("JC", 3, BUTTON_JOYSTICK_BOTTOM, "$SMART", "QHmwUurxC3.1769990960124", "" );
1981 //1769990960124&flowCat=MQTT&name=sendMQTT
1982
1983 //!
1984 //! 2.16.26 runSmart will just send the runSmart, uuid.flownum .. and let someone else run it..
1985 registerChain_mainModule("JC", 3, BUTTON_SHORT_PRESS, "runSmart", "QHmwUurxC3.1769990960124", "" );
1986 //1769990960124&flowCat=MQTT&name=sendMQTT
1987
1988 //! 2.9.26 try the new smartDefn indirect button
1989 //! this has a future text with MQTT defined
1990 registerChain_mainModule("JC", 3, BUTTON_JOYSTICK_LEFT, "$DOCFOLLOW", "bobsYourUncle", "" );
1991 //registerChain_mainModule("JC", 3, BUTTON_JOYSTICK_LEFT, "$DC", "bobsYourUncle", "name" );
1992
1993
1994#define TRY_JC_BUTTON_1
1995#ifdef TRY_JC_BUTTON_1
1996 //! 3.20.26 Pinapple Express Rain, after Deep Snow last weekend,
1997 //! adding JC to button1 - incase it's the only one there..
1998 //! This is because the button is known when it's touched .. so it searches numbered button for the Press kind (and joystick is seperate)
1999 //! TODO: check STORAGE
2000 registerChain_mainModule("JC", 1, BUTTON_JOYSTICK_TOP, "togglesocket", "", "M5AtomSocket");
2001 registerChain_mainModule("JC", 1, BUTTON_JOYSTICK_RIGHT, "feed", "", "" );
2002 registerChain_mainModule("JC", 1, BUTTON_JOYSTICK_BOTTOM, "$SMART", "QHmwUurxC3.1769990960124", "" );
2003 //! 2.16.26 runSmart will just send the runSmart, uuid.flownum .. and let someone else run it..
2004 registerChain_mainModule("JC", 1, BUTTON_SHORT_PRESS, "runSmart", "QHmwUurxC3.1769990960124", "" );
2005 //! 2.9.26 try the new smartDefn indirect button
2006 //! this has a future text with MQTT defined
2007 registerChain_mainModule("JC", 1, BUTTON_JOYSTICK_LEFT, "$DOCFOLLOW", "bobsYourUncle", "" );
2008
2009#endif
2010 //! 2.9.26 After Seahawks Superbowl Win
2011 //! #419 https://github.com/konacurrents/KSQRAvatar/issues/489
2012 //! decide where the message shows up..
2013 // <class, buttonNum, pressKind, $SMART, uuid.flownum, DEV>
2014
2015 //! eg:
2016 //char *str = "BC,1,1,feed,,$localhost, BC,1,2,feed,,, BC,2,2,SM_Matrix,6,$dev, BC,2,3, togglesocket,,M5AtomSocket, YC,
2017 }
2018
2019 if (false)
2020 //!test...
2021 testParse();
2022
2023 //! request the chain buttons if SMART
2025
2026 SerialDebug.println("done register chain buttons");
2027
2028}
2029
2030
2031
2032//! 1.23.26 Clear Day .. puppies, tyler, Clear Snowy Mt Rainier
2033//!
2034//! Only 1 setSensorsString now .. will always append
2035//! unless a null or blank "" string
2036//! PREFERENCE_CHAIN_SENSORS_SETTING
2037//! set a sensor val (array of sensor,pin,pin,sensor,pin,pin...)
2038void setChainSensorsString_mainModule(char *chainSensorsString)
2039{
2040 //! for now .. resetting
2041 //! 5.17.25
2042 strcpy(_chainSensorsEPROM, "");
2043
2044 SerialDebug.printf("setChainSensorsString_mainModule(%s)\n", chainSensorsString);
2045 //! init EPROM
2046 if (!chainSensorsString || strlen(chainSensorsString)==0)
2047 strcpy(_chainSensorsEPROM, "");
2048 else if (strlen(_chainSensorsEPROM) > 0)
2049 {
2050 // add a ','
2051 strcat(_chainSensorsEPROM, ",");
2052 }
2053 strcat(_chainSensorsEPROM, chainSensorsString);
2054
2055 //! store in EPROM
2057
2058 //! Parse to the global..
2060 //!printout
2061 SerialDebug.printf("setSensors:setChainSensorsString_mainModule = %d\n", _chainUseStruct->chainUseCount);
2062
2063}
2064
2065//! 1.30.26 RAIN, puppies, Tyler looking at me
2066//! return a non 0 length string " " if nothing or 0 length
2067char *non0string(char* str)
2068{
2069 if (!str)
2070 return (char*)" ";
2071 else if (strlen(str) == 0)
2072 return (char*)" ";
2073 else
2074 return str;
2075}
2076//! print sensors, passing in a struct
2077//! also makes a requestChainSMARTButtons() call ..
2079{
2080 if (chainUseStruct)
2081 {
2082 //! print it 2 ways, one as the EPROM wouild look, the other are the chain use string
2083 for (int lap = 0; lap < 2; lap++)
2084 {
2085 boolean showAsEPROM = (lap == 0);
2086
2087 //! go through looking for N one (0 based)
2088 for (int i=0; i< chainUseStruct->chainUseCount; i++)
2089 {
2090 //! grab the i'th struct, then look at the button number and pressKind
2091 ChainButtonStruct* chainButtonStruct = &chainUseStruct->chainButtonStructArray[i];
2092 if (showAsEPROM)
2093 {
2094 //! "JC", 3, BUTTON_JOYSTICK_RIGHT, "feed", "", "" );
2095 if (i > 0)
2096 SerialDebug.printf(",");
2097 SerialDebug.printf("%s,%d,%d,%s,%s,%s (docfollow=%d)", chainButtonStruct->classType, chainButtonStruct->buttonNumber, chainButtonStruct->pressKind, non0string(chainButtonStruct->setString), non0string(chainButtonStruct->valString), non0string(chainButtonStruct->deviceString), chainButtonStruct->isDOCFOLLOW);
2098 }
2099 else
2100 SerialDebug.printf("%d -> %s\n", i, chainButtonStruct->chainUse?chainButtonStruct->chainUse:(char*)"NULL");
2101
2102#ifdef DO_THIS_LATER
2103 //! 2.9.26 SuperBowl win, Vonn crash
2104 //! send the request message again..
2105 //! This will only be set if the setString wasn't updated ..
2106 if (strcmp(chainButtonStruct->setString,"$SMART")==0)
2107 {
2108 //! not finalized yes .. so fire off a request again.
2109 //! make a request for the UUID ...
2110 //! {"set":"getSmartDefn", "val":"uuid.flownum"}
2111 sprintf(_mqttMessage_ChainButton, "{'set':'getSmartDefn','val':'%s'}", chainButtonStruct->valString);
2112 SerialDebug.println(_mqttMessage_ChainButton);
2113
2114 //! send MQTT message requesting a definiition for our SMART button
2115 //! send this message
2117 }
2118#endif
2119 }
2120 if (showAsEPROM)
2121 SerialDebug.println();
2122 }
2123
2124 //! request the chain buttons if SMART
2126 }
2127}
2128
2129#ifdef LATER
2130//! 2.14.26 WORKS .. dynamic binding .. but now add a cache of last results (would have to reboot to clear cache)
2131boolean cachedChainDefinition(char *smartAddress)
2132{
2133 //! if cached return true
2134 boolean cached = false;
2135 //! would be lookup smartAddres to the 'tuple MQTT message'
2136 //! calll
2137 /*
2138 //! //! 2.11.26 set the value for the smartAddress
2139 //! the val will be parsed..
2140 void setChainButtonStructSMART(char *valValue);
2141
2142 //! 2.11.26 Lincolns birtyday
2143 //! will set any buttons with DOCFOLLOW with the smart address specified
2144 void setChainButtonStructDOCFOLLOW(char *SMARTAddress);
2145 */
2146 return cached;
2147}
2148#endif
2149
2150//! 2.9.26 SuperBowl win, Vonn crash
2151//! send the request message again..
2152//! This will only be set if the setString wasn't updated ..
2153//! 2.9.26 Rain. puppies still couple more days
2154//! call this to ask for SMART Addresses .. when MQTT is connected
2155//! this looks at all Chain Buttons and if a SMART Address .. requests on MQTT via
2156//! set: getSmartDefn message
2157//! TODO: 2.14.26 WORKS .. dynamic binding .. but now add a cache of last results (would have to reboot to clear cache)
2159{
2160 SerialDebug.println("requestChainSMARTButtons");
2161 //! go through all chain buttons and see if any are $SMART
2162 //! if so .. make a MQTT request
2163 ChainUseStruct* chainUseStruct = getChainUseStruct_mainModule();
2164 if (chainUseStruct)
2165 {
2166 SerialDebug.printf("%d SMARTButtons\n", chainUseStruct->chainUseCount);
2167
2168 //! go through looking for N one (0 based)
2169 for (int i=0; i< chainUseStruct->chainUseCount; i++)
2170 {
2171 //! grab the i'th struct, then look at the button number and pressKind
2172 ChainButtonStruct* chainButtonStruct = &chainUseStruct->chainButtonStructArray[i];
2173
2174 //! 2.9.26 SuperBowl win, Vonn crash (5 inch hit gate)
2175 //! send the request message again..
2176 //! This will only be set if the setString wasn't updated ..
2177 if (strcmp(chainButtonStruct->setString,"$SMART")==0)
2178 {
2179 char* smartAddress = chainButtonStruct->valString;
2180 //! 2.14.26 Valentimes day, 46th with Laura Babe
2181 //! if already cached .. skip the request
2182 //if (!cachedChainDefinition(smartAddress))
2183 {
2184 //! not finalized yes .. so fire off a request again.
2185 //! make a request for the UUID ...
2186 //! {"set":"getSmartDefn", "val":"uuid.flownum"}
2187 sprintf(_mqttMessage_ChainButton, "{'set':'getSmartDefn','val':'%s'}", smartAddress);
2188 SerialDebug.printf("Request(%d, %s) %s\n", i, smartAddress, _mqttMessage_ChainButton);
2189
2190 //! send MQTT message requesting a definiition for our SMART button
2191 //! send this message
2193 }
2194 }
2195 }
2196 }
2197}
2198
2199//! 2.13.26 2 eagles, starting rain, nice ski yesterday
2200//! add storage for the VALstring so not creating new copy always
2201#define MAX_SMART_ADDRESS 80
2203//! return memory that can be used (reused)
2204char *copyString_SMARTAddress(char* valString)
2205{
2206 if (strlen(valString) > MAX_SMART_ADDRESS)
2207 strcpy(_buffer_ChainButtonSMARTAddress,(char*)"");
2208 else
2209 strcpy(_buffer_ChainButtonSMARTAddress, valString);
2211}
2212//! 2.13.26 2 eagles, starting rain, nice ski yesterday
2213//! add storage for the VALstring so not creating new copy always
2214#define MAX_USE_SAMPLE 250
2216//! return memory that can be used (reused)
2217//! namespace future use ...
2218char *copyString_UseSample(char* valString, char *category)
2219{
2220 if (strlen(valString) > MAX_USE_SAMPLE)
2221 strcpy(_buffer_ChainButtonUseSample,(char*)"");
2222 else
2223 strcpy(_buffer_ChainButtonUseSample, valString);
2225}
2226
2227//! 2.12.26 Lincolns birtyday, SKI crystal nice turns
2228//! will set any buttons with DOCFOLLOW with the smart address specified
2229//! $SMART, uuid.flow, dev
2230//! here the smartAddress == UUID.FLOWNUM
2231//! SMARTAddress is temporary transient storage
2232void setChainButtonStructDOCFOLLOW(char *SMARTAddress)
2233{
2234 SerialDebug.printf("setChainButtonStructDOCFOLLOW: %s\n", SMARTAddress);
2235 //! go through all chain buttons and see if any are $SMART
2236 //! if so .. make a MQTT request
2237 ChainUseStruct* chainUseStruct = getChainUseStruct_mainModule();
2238 if (chainUseStruct)
2239 {
2240 //! go through looking for N one (0 based)
2241 for (int i=0; i< chainUseStruct->chainUseCount; i++)
2242 {
2243 //! grab the i'th struct, then look at the button number and pressKind
2244 ChainButtonStruct* chainButtonStruct = &chainUseStruct->chainButtonStructArray[i];
2245 if (chainButtonStruct->isDOCFOLLOW)
2246 {
2247 // registerChain_mainModule("JC", 3, BUTTON_JOYSTICK_BOTTOM, "$SMART", "QHmwUurxC3.1769990960124", "" );
2248
2249 SerialDebug.printf("setDOCFOLLOW address=($SMART,%s,)\n",(char*) SMARTAddress);
2250 //! the SMART Address is when finalized, so the same button can be updated in the future with just the address UUID.FLOW
2251 chainButtonStruct->SMARTAddress = copyString_SMARTAddress(SMARTAddress);
2252 //! change the DOCFOLLOW to a SMART item..
2253 chainButtonStruct->setString = (char*)"$SMART";
2254 chainButtonStruct->valString = chainButtonStruct->SMARTAddress;
2255 chainButtonStruct->deviceString = (char*)"";
2256
2257 //! buttonFinalized means we have the MQTT message definition (retrieved from the internet, actually iPhone sends the setSmartDefn message
2258 //! If finalized then the SMARTAddress is what you want to use, which will
2259 chainButtonStruct->buttonFinalized = false;
2260
2261
2262 //!update the chain use for this one..
2263 //! eg: "$SMART", "QHmwUurxC3.1769990960124", ""
2264 char chainUseSample[MAX_USE_SAMPLE];
2265 sprintf(chainUseSample,(char*)"CHAIN_USE: %s btn=%2d press=%d set= %s, val=%s dev=%s", chainButtonStruct->classType, chainButtonStruct->buttonNumber, chainButtonStruct->pressKind, chainButtonStruct->setString, chainButtonStruct->valString, chainButtonStruct->deviceString);
2266 //! since DOCFOLLOW all have the same, we can use the same (FOR NOW..
2267 //! TODO : if the <cat> is used .. then different buffers needed..
2268 chainButtonStruct->chainUse = copyString_UseSample(chainUseSample, (char*)"");
2269 }
2270 }
2271 }
2272 //! print it out ...
2274
2275#ifdef DONE_BY_PRINT
2276 //! start the process... this sends MQTT message to look for non buttonFinalized smart addresses.
2278#endif
2279}
2280
2281//! 1.27.26
2282//! 7.9.25 reset SENSORS to default
2283//! "BuzzerSensorClass,23,33,L9110S_DCStepperClass,21,25"
2285{
2286 //UNUSED
2287}
2288
2289
2290
2291//!12.19.25 use the Chain
2292//! 5.3.25 add a central clearing house for defining PIN use
2293//! central clearing house for all pins used to we can analyze if there are overlaps
2294//! pin is the actual number, pinName is the local name (eg. IN1_PIN or VIN_PIN).
2295//! moduleName is the module in the code,
2296//! isI2C is whether this is a I2C bus (which we aren't using much yet)
2297//! 1.22.26 add pressKind and classType
2298void registerChain_mainModule(String classType, int buttonNumber, int pressKind, String setString, String valString, String deviceString)
2299{
2300
2302 {
2303 SerialError.printf("*** ERROR .. too many CHAINS defined ***\n");
2304 return;
2305 }
2306
2307 char chainUseSample[100];
2308 sprintf(chainUseSample,"CHAIN_USE: %s btn=%2d press=%d set= %s, val=%s dev=%s",classType, buttonNumber,pressKind, setString.c_str(), valString.c_str(), deviceString.c_str());
2309 SerialLots.println(chainUseSample);
2310
2311 //! storage is supposed to have been created .. but this line blows ..
2312 SerialLots.printf("chainButtonStruct = %d, count = %d\n", _chainUseStruct,_chainUseStruct? _chainUseStruct->chainUseCount:-1);
2313 //! update the n'th version
2314 //! grab a pointer to the size already created
2315 //! The array is really contiguous memory .. vs linked list, to the address of the n't array is the pointer to that struct
2316 //! grab the next entry (chainUseCount)
2318
2319 //! 1.23.26
2320 //! 5.3.25 create storage here
2321 char *chainUse = (char*)calloc(strlen(chainUseSample)+1, sizeof(char));
2322 strcpy(chainUse, chainUseSample);
2323
2324 //!store globally
2325 chainbuttonStruct->chainUse = chainUse;
2326
2327 //!store classType
2328 chainbuttonStruct->classType = createCopy2(classType.c_str());
2329
2330 //! set the buttonNumber for this chain #
2331 chainbuttonStruct->buttonNumber = buttonNumber;
2332
2333 //! pressKind
2334 chainbuttonStruct->pressKind = pressKind;
2335
2336 //! set the set for this chain #
2337 chainbuttonStruct->setString = createCopy2(setString.c_str());
2338
2339 //! set the set for this chain #
2340 chainbuttonStruct->valString = createCopy2(valString.c_str());
2341
2342 //! set the set for this chain #
2343 chainbuttonStruct->deviceString = createCopy2(deviceString.c_str());
2344
2345 //! 2.11.26
2346 chainbuttonStruct->isDOCFOLLOW = false;
2347
2348 //! 2.9.26 superbowl, raining out
2349 //! fi the set is $SMART then do something ... request the value again .. since otherwise the setString value would be changed
2350 //! $SMART, UUID.FLOW, <dev>
2351 if (strcmp(chainbuttonStruct->setString, "$SMART")==0)
2352 {
2353 //! set the SMARTAddress
2354 chainbuttonStruct->SMARTAddress = createCopy(chainbuttonStruct->valString);
2355 //! not finalized (not BOUND to the MQTT message. the iPhone is the one providing that information ...
2356 chainbuttonStruct->buttonFinalized = false;
2357#ifdef DO_THIS_LATER
2358 //! make a request for the UUID ...
2359 //! {"set":"getSmartDefn", "val":"uuid.flownum"}
2360 sprintf(_mqttMessage_ChainButton, "{'set':'getSmartDefn','val':'%s'}", chainbuttonStruct->SMARTAddress);
2361 SerialDebug.println(_mqttMessage_ChainButton);
2362
2363 //! send MQTT message requesting a definiition for our SMART button
2364 //! send this message
2366#endif
2367 }
2368 //! 2.11.26 add the docfollow
2369 //! $DC,, <nill args)>
2370 //! TODO: args: $DC, <group>, <name> help filter out $DC subsets (context)
2371 else if (strcmp(chainbuttonStruct->setString, "$DC")==0|| strcmp(chainbuttonStruct->setString, "$DOCFOLLOW")==0)
2372 {
2373 //! 2.11.26
2374 chainbuttonStruct->isDOCFOLLOW = true;
2375 //! no smart address
2376 chainbuttonStruct->SMARTAddress = createCopy((char*)"");
2377 //! but finalized
2378 chainbuttonStruct->buttonFinalized = false;
2379 }
2380 else
2381 {
2382 //! no smart address
2383 chainbuttonStruct->SMARTAddress = createCopy((char*)"");
2384 //! but finalized
2385 chainbuttonStruct->buttonFinalized = true;
2386 }
2387
2388 //! increment chainUseCound
2390
2391
2392}
2393
2394#ifdef LATER_STANGE
2395//! NOT USING THIS YET ...
2396//! 3.15.26 find first button struct for a pressKind (so the joystick can be found)
2397//!if matched returns defintion otherwises sends a getSmartDefn message over MQTT hoping it shows up here as DOCFOLLOW sends MQTT
2399{
2400 SerialDebug.printf("getChainUseStruct(%d)\n", pressKind);
2401 ChainUseStruct* chainUseStruct = getChainUseStruct_mainModule();
2402 if (chainUseStruct)
2403 {
2404 //! go through looking for N one (0 based)
2405 for (int i=0; i< chainUseStruct->chainUseCount; i++)
2406 {
2407 //! grab the i'th struct, then look at the button number and pressKind
2408 ChainButtonStruct* chainButtonStruct = &chainUseStruct->chainButtonStructArray[i];
2409
2410 //! i is just the entry .. not the button number
2411 //! N'th entry
2412 if (chainButtonStruct->pressKind == pressKind || chainButtonStruct->pressKind == BUTTON_ANY)
2413 {
2414 SerialDebug.printf("chainButton press=%d) = %s\n", chainButtonStruct->pressKind, chainButtonStruct->chainUse);
2415 //! see if the right pressKind
2416 {
2417 SerialDebug.printf("matched button %ld, press=%ld \n", chainButtonStruct->buttonNumber, pressKind);
2418
2419 //! 2.9.26 if not finalized .. ask again
2420 if (chainButtonStruct->buttonFinalized)
2421 //! found one .. go with it
2422 return chainButtonStruct;
2423 else
2424 {
2425 //! not finalized yes .. so fire off a request again.
2426 //! make a request for the UUID ...
2427 //! {"set":"getSmartDefn", "val":"uuid.flownum"}
2428 sprintf(_mqttMessage_ChainButton, "{'set':'getSmartDefn','val':'%s'}", chainButtonStruct->valString);
2429 SerialDebug.println(_mqttMessage_ChainButton);
2430
2431 //! send MQTT message requesting a definiition for our SMART button
2432 //! send this message
2434
2435 //! and no match..
2436 return NULL;
2437 }
2438 }
2439 }
2440 }
2441 }
2442 return NULL;
2443}
2444#endif
2445
2446//! 1.27.26 moved here for generic use .. even by a non chain button
2447//! 1.22.26 with puppies, cold dry outside
2448//! get the ChainUseStruct for the buttonNumber (eg 1..9 (no 0)
2449//! Column Major in the Matrix (but sequential here)
2450//! return the definition for this 1 based button number (if any)] //TODO -1
2451//! pressKind = -1 (matches first one ..)
2452//! NOTE: pressKind for Joystick is here..
2453//! 1.28.26 you can ask for BUTTON 0 (which will be the deault for the M5Atom single press (or maybe long press)
2454//! 2.9.26 if not finlized yet, then request a smart definition.. in case not found yet.
2455ChainButtonStruct* getChainButtonStruct(int buttonNumber_1based, int pressKind)
2456{
2457 SerialDebug.printf("getChainUseStruct(%d, %d)\n", buttonNumber_1based, pressKind);
2458 ChainUseStruct* chainUseStruct = getChainUseStruct_mainModule();
2459 if (chainUseStruct)
2460 {
2461 //! go through looking for N one (0 based)
2462 for (int i=0; i< chainUseStruct->chainUseCount; i++)
2463 {
2464 //! grab the i'th struct, then look at the button number and pressKind
2465 ChainButtonStruct* chainButtonStruct = &chainUseStruct->chainButtonStructArray[i];
2466
2467 //! i is just the entry .. not the button number
2468 //! N'th entry
2469 if (chainButtonStruct->buttonNumber == buttonNumber_1based)
2470 {
2471 SerialDebug.printf("chainButton (%d, press=%d) = %s\n", buttonNumber_1based, chainButtonStruct->pressKind, chainButtonStruct->chainUse);
2472 //! see if the right pressKind
2473 if (chainButtonStruct->pressKind == pressKind || chainButtonStruct->pressKind == BUTTON_ANY)
2474 {
2475 SerialDebug.printf("matched button %ld, press=%ld \n", buttonNumber_1based, pressKind);
2476
2477 //! 2.9.26 if not finalized .. ask again
2478 if (chainButtonStruct->buttonFinalized)
2479 //! found one .. go with it
2480 return chainButtonStruct;
2481 else
2482 {
2483 //! not finalized yes .. so fire off a request again.
2484 //! make a request for the UUID ...
2485 //! {"set":"getSmartDefn", "val":"uuid.flownum"}
2486 sprintf(_mqttMessage_ChainButton, "{'set':'getSmartDefn','val':'%s'}", chainButtonStruct->valString);
2487 SerialDebug.println(_mqttMessage_ChainButton);
2488
2489 //! send MQTT message requesting a definiition for our SMART button
2490 //! send this message
2492
2493 //! and no match..
2494 return NULL;
2495 }
2496 }
2497 }
2498 }
2499 }
2500 return NULL;
2501}
2502
2503#ifdef NOT_THIS_ONW
2504//! 2.9.26 Superbowl Win, Vonn Crash
2505//! get the chain use struct for the SMART address
2506ChainButtonStruct* getChainButtonStructSMART(char *SMARTAddress)
2507{
2508 SerialDebug.printf("getChainUseStructSMART(%s)\n", SMARTAddress);
2509 ChainUseStruct* chainUseStruct = getChainUseStruct_mainModule();
2510 if (chainUseStruct)
2511 {
2512 //! go through looking for N one (0 based)
2513 for (int i=0; i< chainUseStruct->chainUseCount; i++)
2514 {
2515 //! grab the i'th struct, then look at the button number and pressKind
2516 ChainButtonStruct* chainButtonStruct = &chainUseStruct->chainButtonStructArray[i];
2517
2518 //! i is just the entry .. not the button number
2519 //! N'th entry
2520 if (strcmp(chainButtonStruct->SMARTAddress, SMARTAddress)==0)
2521 {
2522 SerialDebug.printf("Found chainButton %s for SMART = %s\n", chainButtonStruct->classType, SMARTAddress);
2523 //! found one .. go with it
2524 return chainButtonStruct;
2525
2526
2527 }
2528 }
2529 }
2530 return NULL;
2531}
2532#endif
2533
2534//! 2.11.26 set the value for the smartAddress
2535//! the val will be parsed..
2536//! valValue is the address used: UUID.FLOW(set,val,dev)
2537//! NOTE: valValue is transient storage
2538void setChainButtonStructSMART(char *valValue)
2539{
2540 SerialDebug.printf("setChainButtonStructSMART(%s)\n", valValue);
2541 ChainUseStruct* chainUseStruct = getChainUseStruct_mainModule();
2542 if (chainUseStruct)
2543 {
2544 //! 2.,10.26 parsing works .. no extra spaces ..
2545 //! UUID.FLOW(set,val,dev)
2546 SMStruct sm = parseSMAddress(valValue);
2547 char *SMARTAddress = sm.smAddress;
2548 SerialDebug.printf("SM = '%s', '%s', '%s', '%s'\n", sm.smAddress, sm.setString, sm.valString, sm.devString);
2549
2550
2551 //! go through looking for N one (0 based)
2552 for (int i=0; i< chainUseStruct->chainUseCount; i++)
2553 {
2554 //! grab the i'th struct, then look at the button number and pressKind
2555 ChainButtonStruct* chainButtonStruct = &chainUseStruct->chainButtonStructArray[i];
2556
2557 //! i is just the entry .. not the button number
2558 //! N'th entry
2559 if (strcmp(chainButtonStruct->SMARTAddress, SMARTAddress)==0)
2560 {
2561 SerialDebug.printf("Found chainButton %s for SMART = %s\n", chainButtonStruct->classType, SMARTAddress);
2562 //! found one .. go with it
2563
2564 //! 2.9.26 works.. but there might be multiple with same SMART address
2565 //! OOPS .. the getChainButtonStructSMART .. looks for matches .. this should be returning multiple
2566 //! BUT for now .. only the first one.
2567 //! NOTE: this is a chain button with a smart address .. which can be re-bound through this message..
2568 if (chainButtonStruct)
2569 {
2570 SerialDebug.printf("FOUND chainButtonSMART(%s, %d) = %s", SMARTAddress, chainButtonStruct->pressKind, chainButtonStruct->chainUse);
2571
2572 //! for now .. set to the ToggleSocket
2573 chainButtonStruct->setString = sm.setString;
2574 chainButtonStruct->valString = sm.valString;
2575 chainButtonStruct->deviceString = sm.devString;
2576 chainButtonStruct->buttonFinalized = true;
2577 //!update the chain use for this one..
2578 char chainUseSample[250];
2579 sprintf(chainUseSample,(char*)"CHAIN_USE: %s btn=%2d press=%d set= %s, val=%s dev=%s", chainButtonStruct->classType, chainButtonStruct->buttonNumber, chainButtonStruct->pressKind, chainButtonStruct->setString, chainButtonStruct->valString, chainButtonStruct->deviceString);
2580 chainButtonStruct->chainUse = copyString_mainModule(chainUseSample);
2581 //! printout
2583
2584 }
2585 }
2586 }
2587 }
2588}
2589
2590 //! 1.22.26 Dead Morning Dew
2591//! process the given button
2592//! 1.24.26 NOTE: this doesn't care about button press or joystick .. it's just run that button
2594{
2595 if (chainButtonStruct)
2596 {
2597 SerialDebug.printf("processChainUseStruct: %s, %s\n", chainButtonStruct->setString, chainButtonStruct->valString);
2598 char *deviceName = chainButtonStruct->deviceString;
2599 boolean isLocalHost = false;
2600 boolean useCurrentDevice = false;
2601 boolean nullValString = false;
2602 if (!chainButtonStruct->valString || strlen(chainButtonStruct->valString) == 0)
2603 nullValString = true;
2604 if (deviceName && strlen(deviceName) > 0)
2605 {
2606 //! 1.24.26 look at $options
2607 switch (deviceName[0])
2608 {
2609 case '$':
2610 {
2611 //! special
2612 if ( strcmp(deviceName,"$localhost")==0)
2613 isLocalHost = true;
2614 else if (strcmp(deviceName, "$dev")==0)
2615 useCurrentDevice = true;
2616 }
2617 break;
2618 }
2619
2620 }
2621 else
2622 deviceName = NULL;
2623
2624
2625 if (isLocalHost && strcmp(chainButtonStruct->setString,"feed")==0)
2626 {
2628 {
2629 //! 4.3.26 if BLE connected .. just do that..
2630
2631 //!send a BLE feed command as we are connected
2633 }
2634 else
2635 {
2636 //! feed ..
2637 ///feed always (done after the code below..)
2639 //! This will send BLE to our connected device ..
2640 //!
2641 }
2642
2643 }
2644#define TRY_FEED_BLE_WIFI
2645 //! 4.3.26 Off to the Moon
2646 //! if "feed" then send via BLE and WIFI
2647#ifdef TRY_FEED_BLE_WIFI
2648 else if (strcmp(chainButtonStruct->setString,"feed")==0 && //! 8.16.25 BLE CLIENT
2649 //!9.30.22 IF SET .. send a feed but to all devices except ours and our pair (if any)
2650 //! uses new wildcard syntax either ! OUR NAME [ & ! OUR_CONNECTED_NAME
2652
2653 {
2654 SerialDebug.println("*** feed and BLE connected **");
2655 ///feed always (done after the code below..)
2657 }
2658#else
2659#endif
2660
2661 else
2662 {
2663 if (nullValString)
2664 {
2665 //! create a set/val message
2666 //! TODO; device, etc.. topic
2667 ///eg. registerChain_mainModule("BC", 1, BUTTON_DOUBLE_PRESS, "feed", "", "" ); //wifi
2668
2669 if (deviceName)
2670 sprintf(_mqttMessage_ChainButton, "{'cmd':'%s','dev':'%s'}", chainButtonStruct->setString, deviceName);
2671 else
2672 sprintf(_mqttMessage_ChainButton, "{'cmd':'%s'}", chainButtonStruct->setString);
2673
2674 }
2675 else
2676 {
2677 //! create a set/val message
2678 //! TODO; device, etc.. topic
2679 if (deviceName)
2680 sprintf(_mqttMessage_ChainButton, "{'set':'%s','val':'%s','dev':'%s'}", chainButtonStruct->setString, chainButtonStruct->valString, deviceName);
2681 else
2682 sprintf(_mqttMessage_ChainButton, "{'set':'%s','val':'%s'}", chainButtonStruct->setString, chainButtonStruct->valString);
2683
2684 }
2685 //! send this message
2687 }
2688 //!
2689 //! idea is you define the button and the press kind
2690 //! MatrixCell is Column Major 1,4, 7 // 2,5,8 // 3,6,9
2691 //registerChain_mainModule("ButtonClass", 1, BUTTON_SHORT_PRESS, "SM_MatrixCell", "15", "$dev" );
2692 //registerChain_mainModule("ButtonClass", 1, BUTTON_LONG_PRESS, "SM_MatrixCell", "6", "$dev");
2693 //registerChain_mainModule("JoystickClass", 2, BUTTON_SHORT_PRESS, "feed", "", "$localhost" );
2694
2695 }
2696}
boolean isConnectedBLEClient()
returns whether connected over BLE as a client to a server(like a ESP feeder)
void sendFeedCommandBLEClient()
sends the "feed" command over bluetooth to the connected device..
String getJSONConfigString()
retrieve the Configuration JSON string in JSON format..
void sendMessageNoChangeMQTT(char *message)
just send a message but without any extras
char * createCopy2(const char *stringA)
char * main_getUsername()
char * main_JSONStringForWIFICredentials()
retrieve a JSON string for the ssid and ssid_password: {'ssid':<ssid>,'ssidPassword':<pass>"}
char * main_getPassword()
return password
char * getServerServiceName_mainModule()
Definition: MainModule.cpp:336
void main_dispatchAsyncCommand(int asyncCallCommand)
checks if any async commands are in 'dispatch' mode, and if so, invokes them, and sets their flag to ...
PinUseStruct * getPinUseStruct_mainModule()
get the pin use array
char * getChipIdString()
3.17.24 get the chip id as a string
char * connectedBLEDeviceName_mainModule()
returns the connected BLE Device name (the :NAME of advertisment, Address: 01:39:3f:33 part of name,...
char * createCopy(char *stringA)
#define ASYNC_SEND_MQTT_FEED_MESSAGE
sends a message (like FEED) on the users topic
Definition: MainModule.h:213
#define NO_POWEROFF_AMOUNT_STRING_MAIN
Definition: MainModule.h:72
#define ASYNC_CALL_CLEAN_EPROM
cleans the EPROM totally, and reboots
Definition: MainModule.h:205
#define EPROM_DEV_ONLY_SM_SETTING
9.28.23 #272 only show Semantic Markers that are sent directly to the device
#define EPROM_NO_BUTTON_CLICK_POWEROFF_SETTING
sets screentimeout if not button clicks (set,noclick,val,seconds)
#define EPROM_MAIN_GATEWAY_VALUE
void cleanEPROM_mainModule()
clean the preferencesMainModule in EPROM
void savePreferenceInt_mainModule(int preferenceID, int val)
sets an int preference
boolean getDiscoverM5PTClicker()
get option
float getPreferenceFloat_mainModule(int preferenceID)
called to set a preference (which will be an identifier and a string, which can be converted to a num...
#define EPROM_WIFI_CREDENTIAL_2_SETTING
second wifi credential
void savePreferenceBoolean_mainModule(int preferenceID, boolean flag)
save a boolean preference
#define EPROM_FIRST_TIME_FEATURE_SETTING
a firsttime feature flag (only 1 per build) 7.12.22 defaulting to TRUE
#define EPROM_PREFERENCE_SUPPORT_GROUPS_SETTING
the preference for supporting GROUPS (default true)
#define EPROM_PAIRED_DEVICE_SETTING
the guest device paired with this M5 device (or NONE)
void savePreferenceATOMKind_MainModule(String value)
returned from mainModule
#define EPROM_PREFERENCE_TIMER_MAX_INT_SETTING
11.29.23 add the max time .. so a random can be used
char * _preferenceMainModuleLookupDefaults[MAX_MAIN_PREFERENCES]
array of default values to store in the EPROM if not defined..
char _preferenceBuffer[100]
PREFERENCES for the main module.
#define EPROM_STEPPER_ANGLE_FLOAT_SETTING
sets stepper angle, a floating point number
#define EPROM_USE_DOC_FOLLOW_SETTING
NOTE: these EPROM have to be lockstep the same as the PREFERENCE definitions in MainModule....
#define EPROM_PREFERENCE_ATOM_KIND_SETTING
1.4.24 What kind of ATOM plug (set, M5AtomKind, val= {M5AtomSocket, M5AtomScanner}
void printSensors_mainModule(SensorsStruct *sensors)
print sensors, passing in a struct
#define EPROM_PREFERENCE_SM_COMMAND_PIR_SETTING
1.10.24 The Semantic Marker command is sent on PIR, and the Command to send
char _buffer_ChainButtonSMARTAddress[MAX_SMART_ADDRESS]
SensorsStruct * getSensors_mainModule()
return the sensors defined
#define EPROM_PREFERENCE_SM_COMMAND_PIR_OFF_SETTING
1.11.24 The Semantic Marker command is sent on PIR, and the Command to send
char _includeGroupsStringArray[NUMBER_GROUPS][STRING_MAX_SIZE]
resulting group names
char * _preferenceMainModuleLookupEPROMNames[MAX_MAIN_PREFERENCES]
array of preference names (those used in process()
#define EPROM_PREFERENCE_ATOMS_SETTING
1.1.24 the preference for all the ATOM plugs (format: atomType:value} .. for now just use socket:on
void initChainSensorStringsFromEPROM_mainModule()
void appendPreference_mainModule(int preferenceID, String preferenceValue)
called to append to a a preference (which will be an identifier and a string, which can be converted ...
#define EPROM_PAIRED_DEVICE_ADDRESS_SETTING
9.3.22 eprom of the Address of desired BLE
ChainUseStruct * parseChainSensorString_mainModuleNEW(char *chainUseString)
void setDiscoverM5PTClicker(boolean flag)
#define EPROM_SENDWIFI_WITH_BLE
send WIFI to all except our device (and our paired) when
void setSensorsString_mainModule(char *sensorsString)
#define EPROM_BLE_SERVER_USE_DEVICE_NAME_SETTING
if set, the BLE Server (like PTFeeder) will tack on the device name (or none if not defined).
String _appendingPreferenceString
storage for the appending string
void resetAllPreferences_mainModule()
resets preferences.. Currently only reset all, but eventually reset(groups..)
void testParse()
#define EPROM_STEPPER_BUZZER_VALUE
buzzer on or off
#define EPROM_MAIN_BLE_SERVER_VALUE
BLEServer mode.
#define EPROM_STEPPER_SINGLE_FEED_VALUE
single feed mode
#define MAX_SMART_ADDRESS
ChainUseStruct * getChainUseStruct_mainModule()
get the pin use array
#define EPROM_STEPPER_CLOCKWISE_MOTOR_DIRECTION_SETTING
#define MAX_CHAIN_STRING
int _includeGroupLen
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...
#define EPROM_PREFERENCE_SM_ON_PIR_SETTING
1.10.24 Flag on whether a Semantic Marker command is sent on PIR, and the Command to send
void registerChain_mainModule(String classType, int buttonNumber, int pressKind, String setString, String valString, String deviceString)
void togglePreferenceBoolean_mainModule(int preferenceID)
toggles a preference boolean
#define EPROM_USE_SPIFF_SETTING
8.22.22 to turn on/off SPIFF use
void printSensor_mainModule(SensorStruct *sensor)
print sensor
#define EPROM_PREFERENCE_DEBUG_INFO_SETTING
a place to put some kind of Last Will of what went wrong .. for now (> max tries)
#define EPROM_SCREEN_COLOR_SETTING
color of the M5 screen
void resetPreference_mainModule(int preferenceID)
called to reset to blank a preference (which will be an identifier and a string, which can be convert...
#define EPROM_ONLY_GEN3_CONNECT_SETTING
if true, only BLEClient connect to GEN3 feeders..
boolean _isCachedPreferenceBoolean[MAX_MAIN_PREFERENCES]
array of boolean if the ID is cached..
void storePreference_mainModule(int preferenceID, String preferenceValue)
called to append to a a preference (which will be an identifier and a string, which can be converted ...
void initAppendingPreference_mainModule(int preferenceID)
called to init the preference. This won't save anything until storePreference called
char * getPreferenceATOMKind_MainModule()
new 1.4.24 setting ATOM kind (eg. M5AtomSocket, M5AtomScanner)
#define EPROM_STEPPER_FEEDS_PER_JACKPOT_VALUE
#define NUMBER_GROUPS
#define EPROM_PREFERENCE_ATOM_SOCKET_GLOBAL_ONOFF_SETTING
1.12.24 Whether the AtomSocket accepts global on/off messages
#define STRING_MAX_SIZE
void savePreferenceFloat_mainModule(int preferenceID, float val)
called to set a preference (which will be an identifier and a string, which can be converted to a num...
void printChainSensors_mainModule(ChainUseStruct *chainUseStruct)
print sensors, passing in a struct
#define EPROM_DISPLAY_ON_BLANK_SCREEN_VALUE
Display preferences - show messages on blank screen- boolean.
#define EPROM_SENSOR_PIR_VALUE
proximity PIR
void savePreferenceIntFromString_mainModule(int preferenceID, char *val)
sets an int, but only if a valid integer, and no signs. If bad, then a 0 is stored
#define EPROM_USE_SPIFF_MQTT_SETTING
4.4.24 for MQTT use of spiff (or not)
#define EPROM_STEPPER_AUTO_MOTOR_DIRECTION_SETTING
#define EPROM_STEPPER_FACTORY_CLOCKWISE_MOTOR_DIRECTION_SETTING
#define EPROM_INCLUDE_GROUP_NAMES_SETTING
include these topics groups..
void setOnBootPreferences_mainModule()
set some defaults on boot - that override EPROM this can be called on the HOME screen to set back to ...
#define EPROM_STEPPER_RPM_SETTING
SensorsStruct * parseSensorString_mainModule(char *str)
return array of SensorsStruct after parsing string syntax: {SENSOR,pin1,pin2}
#define secondPass
char _sensorsEPROM[1000]
the memory for the sensorsEPROM
char * non0string(char *str)
void initSensorStringsFromEPROM_mainModule()
ChainUseStruct * _chainUseStruct
global for use. This is an object (not a pointer) and has all the storage created statically
char _preferenceBufferString[100]
buffer for the string
#define EPROM_PREFERENCE_TIMER_INT_SETTING
the preference timer
boolean _cachedPreferenceBooleanValues[MAX_MAIN_PREFERENCES]
#define EPROM_STEPPER_JACKPOT_FEED_VALUE
jackpot feed
#define EPROM_SUB_DAWGPACK_SETTING
8.17.22 to turn on/off subscribing to the dawgpack topic
char _buffer_ChainButtonUseSample[MAX_USE_SAMPLE]
#define EPROM_NOTIFY_BLE_DISCOVERY
starts the BLE Discovery notification process - which might be internal or externa (via messages).
Preferences _preferencesMainModule
preferences for MAIN
#define EPROM_USE_SPIFF_QRATOM_SETTING
4.4.24 for QRATOM use of spiff (or not)
void parseIncludeGroups(char *groups)
8.2.24 set the include group (and cache it), called (indirectly from MQTT via setIncludeGroups
ChainButtonStruct * getChainButtonStruct(int buttonNumber_1based, int pressKind)
void requestChainSMARTButtons()
void resetChainSensorToDefault_mainModule()
#define EPROM_SENSOR_TILT_VALUE
sensor preferences for tilt on or off
#define MAX_APPEND
special preference string for saving and printing back later..
#define MAX_USE_SAMPLE
boolean topicInIncludeGroup(char *topic)
char * copyString_SMARTAddress(char *valString)
return memory that can be used (reused)
char * copyString_mainModule(char *str)
copy string
void setChainSensorsString_mainModule(char *chainSensorsString)
void setChainButtonStructSMART(char *valValue)
SensorsStruct * _sensorsStructs_mainModule
array of sensorStruct
#define EPROM_STEPPER_KIND_VALUE
the step kind
#define EPROM_HIGH_TEMP_POWEROFF_VALUE
sets the max temp for a poweroff
int getM5ATOMKind_MainModule()
new 1.4.24 setting ATOM kind (eg. ATOM_KIND_M5_SCANNER, ATOM_KIND_M5_SOCKET)
#define EPROM_STEPPER_AUTO_FEED_VALUE
auto feed
#define EPROM_BLE_USE_DISCOVERED_PAIRED_DEVICE_SETTING
#define PREFERENCES_EPROM_MAIN_NAME
the EPROM is in preferences.h
#define EPROM_WIFI_CREDENTIAL_1_SETTING
for now, save 2 WIFI Credentials
ChainUseStruct * parseChainSensorString_mainModule(char *chainUseString)
#define EPROM_MAIN_BLE_CLIENT_VALUE
BLEClient mode.
void setChainButtonStructDOCFOLLOW(char *SMARTAddress)
#define EPROM_DISPLAY_SCREEN_TIMEOUT_VALUE
sets the timeout value
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 * copyString_UseSample(char *valString, char *category)
char _chainSensorsEPROM[700]
int _cachedPreferenceIntValues[MAX_MAIN_PREFERENCES]
another cache for the Int values..
boolean _firstTimeAtomKind
if the preference was retrieved..
char _mqttMessage_ChainButton[100]
#define EPROM_SENSORS_SETTING
#define EPROM_PREFERENCE_GROUP_NAMES_SETTING
the preference setting group names to subscribe (but empty or # go to wildcard, this also supports wi...
void processChainButtonStruct(ChainButtonStruct *chainButtonStruct)
char * getPreference_mainModule(int preferenceID)
#define EPROM_SEMANTIC_MARKER_ZOOMED_VALUE
display preferences zoomed or not zoomed
SensorStruct * getSensor_mainModule(char *sensorName)
return the sensor specified or null
void setIncludeGroups(char *groups)
8.2.24 set the include group (and cache it), called from MQTT
boolean _DiscoverM5PTClicker
#define EPROM_STEPPER_2FEED_SETTING
void readAppendingPreference_mainModule(int preferenceID)
called to init the preference. This won't save anything until storePreference called
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 EPROM_IS_MINIMAL_MENU_SETTING
whether to show the minimal or expanded menu
#define EPROM_DEVICE_NAME_SETTING
the device name
boolean _isCachedPreferenceInt[MAX_MAIN_PREFERENCES]
array of boolean if the ID is cached..
#define EPROM_SENSOR_PLUGS_SETTING
#define EPROM_CHAIN_SENSORS_SETTING
void initPreferencesMainModule()
initialize the _preferencesMainLookup with EPROM lookup names
void savePreference_mainModule(int preferenceID, String preferenceValue)
called to set a preference (which will be an identifier and a string, which can be converted to a num...
void readPreferences_mainModule()
reads the preferences. Save is everytime the savePreference is called
#define PREFERENCE_USE_SPIFF_SETTING
8.22.22 to turn on/off SPIFF use (more below..)
#define PREFERENCE_PAIRED_DEVICE_ADDRESS_SETTING
the paired device for guest device feeding (6.6.22) .. but the Address 9.3.22
#define PREFERENCE_STEPPER_KIND_VALUE
uses STEPPER type
#define PREFERENCE_SENSOR_TILT_VALUE
Sensor preferences.
#define BUTTON_JOYSTICK_BOTTOM
#define PREFERENCE_SUB_DAWGPACK_SETTING
8.17.22 to turn on/off subscribing to the dawgpack topic
#define PREFERENCE_STEPPER_SINGLE_FEED_VALUE
#define PREFERENCE_SM_COMMAND_PIR_OFF_SETTING
1.11.24 The Semantic Marker command is sent on PIR, and the Command to send on OFF (or opposite)
#define PREFERENCE_SENSOR_PLUGS_SETTING
#define PREFERENCE_STEPPER_FACTORY_CLOCKWISE_MOTOR_DIRECTION_SETTING
#define ATOM_KIND_M5_SCANNER
returned from mainModule
#define PREFERENCE_BLE_SERVER_USE_DEVICE_NAME_SETTING
if set, the BLE Server (like PTFeeder) will tack on the device name (or none if not defined).
#define PREFERENCE_ONLY_GEN3_CONNECT_SETTING
if true, only BLEClient connect to GEN3 feeders..
#define PREFERENCE_SENDWIFI_WITH_BLE
sends the WIFI to all except current device if set
#define PREFERENCE_NO_BUTTON_CLICK_POWEROFF_SETTING
#define PREFERENCE_SENSOR_PIR_VALUE
#define PREFERENCE_SUPPORT_GROUPS_SETTING
the preference for supporting GROUPS (default true)
#define PREFERENCE_INCLUDE_GROUP_NAMES_SETTING
8.2.24 don't change subscription but include these groups (eg. safeHouse,atlasDogs)
#define PREFERENCE_SEMANTIC_MARKER_ZOOMED_VALUE
Display preferences (SemanticMarker etc) - boolean.
#define PREFERENCE_STEPPER_JACKPOT_FEED_VALUE
#define BUTTON_JOYSTICK_LEFT
map x,y to quadrants
#define PREFERENCE_WIFI_CREDENTIAL_2_SETTING
#define ATOM_KIND_M5_SOCKET
#define PREFERENCE_STEPPER_RPM_SETTING
#define PREFERENCE_MAIN_BLE_SERVER_VALUE
#define BUTTON_DOUBLE_PRESS
#define PREFERENCE_PAIRED_DEVICE_SETTING
the paired device for guest device feeding (6.6.22)
#define PREFERENCE_STEPPER_BUZZER_VALUE
stepper preferences
#define PREFERENCE_DEV_ONLY_SM_SETTING
adding AP_DEBUG_MODE to let others know that DEBUG eprom is available. Turn this OFF for non dev
#define MAX_MAIN_PREFERENCES
******* 1 greater than last value **** IMPORTANT *** and no gaps..
#define PREFERENCE_ATOMS_SETTING
1.1.24 the preference for all the ATOM plugs (format: atomType:value} .. for now just use socket:on
#define PREFERENCE_BLE_USE_DISCOVERED_PAIRED_DEVICE_SETTING
#define BUTTON_JOYSTICK_RIGHT
#define PREFERENCE_USE_DOC_FOLLOW_SETTING
for
#define PREFERENCE_WIFI_CREDENTIAL_1_SETTING
#define CHAIN_USE_MAX
#define PREFERENCE_ATOM_SOCKET_GLOBAL_ONOFF_SETTING
1.12.24 Whether the AtomSocket accepts global on/off messages
#define PREFERENCE_USE_SPIFF_MQTT_SETTING
#define PREFERENCE_DEBUG_INFO_SETTING
a place to put some kind of Last Will of what went wrong .. for now (> max tries)
#define PREFERENCE_CHAIN_SENSORS_SETTING
#define BUTTON_SHORT_PRESS
#define PREFERENCE_FIRST_TIME_FEATURE_SETTING
a firsttime feature flag (only 1 per build) 7.12.22 defaulting to TRUE
#define PREFERENCE_DISPLAY_SCREEN_TIMEOUT_VALUE
sets the timeout value
#define PREFERENCE_DISPLAY_ON_BLANK_SCREEN_VALUE
Display preferences - show messages on blank screen- boolean.
#define PREFERENCE_IS_MINIMAL_MENU_SETTING
sets the max temp for a poweroff
#define BUTTON_ANY
#define PREFERENCE_SCREEN_COLOR_SETTING
ithe color of the screen 0..n
#define PREFERENCE_NOTIFY_BLE_DISCOVERY
starts the BLE Discovery notification process - which might be internal or externa (via messages).
#define PREFERENCE_USE_SPIFF_QRATOM_SETTING
For MQTT writing to the QRATOM.
#define PREFERENCE_DEVICE_NAME_SETTING
the device name itself (6.6.22)
#define PREFERENCE_HIGH_TEMP_POWEROFF_VALUE
sets the max temp for a poweroff
#define PREFERENCE_STEPPER_FEEDS_PER_JACKPOT
#define PREFERENCE_GROUP_NAMES_SETTING
the preference setting group names to subscribe (but empty or # go to wildcard, this also supports wi...
#define PREFERENCE_STEPPER_ANGLE_FLOAT_SETTING
#define BUTTON_LONG_PRESS
#define PREFERENCE_STEPPER_2FEED_SETTING
#define PREFERENCE_STEPPER_AUTO_MOTOR_DIRECTION_SETTING
#define PREFERENCE_TIMER_MAX_INT_SETTING
the preference timer MAX (pairs with PREFERENCE_TIMER_INT_SETTING)
#define PREFERENCE_MAIN_GATEWAY_VALUE
#define BUTTON_JOYSTICK_TOP
#define PREFERENCE_STEPPER_CLOCKWISE_MOTOR_DIRECTION_SETTING
#define PREFERENCE_MAIN_BLE_CLIENT_VALUE
#define PREFERENCE_SM_ON_PIR_SETTING
1.10.24 Flag on whether a Semantic Marker command is sent on PIR, and the Command to send
#define PREFERENCE_TIMER_INT_SETTING
the preference timer
#define PREFERENCE_ATOM_KIND_SETTING
1.4.24 What kind of ATOM plug (set, M5AtomKind, val= {M5AtomSocket, M5AtomScanner}
#define PREFERENCE_SM_COMMAND_PIR_SETTING
1.10.24 The Semantic Marker command is sent on PIR, and the Command to send
#define PREFERENCE_SENSORS_SETTING
#define PREFERENCE_STEPPER_AUTO_FEED_VALUE
SMStruct parseSMAddress(char *str)
2.11.26 moved here from ChainButtonClassType
char * chainUse
chain use string for debugging printout
char * valString
val strings
boolean buttonFinalized
if finalized yet ... if the set/val are defined..
int pressKind
press kind: 0 = short press, 1 = long press, 2 = long long press, -1 any, 100,101,...
char * setString
the set strings, val strings, device strings
ChainButtonStruct * chainButtonStructArray
1.22.26 define a Chainbutton and creates N of them
int chainUseCount
number of chain
long pinNumArray[PIN_USE_MAX]
each pin
Definition: MainModule.h:515
char * pinUseArray[PIN_USE_MAX]
string describing the module, etc
Definition: MainModule.h:513
SensorClassType * sensorClassType
and the pointer to matching SensorClassType
SensorStruct * sensors
array of sensorStruct
char * devString
Definition: TokenParser.h:82
char * valString
Definition: TokenParser.h:81
char * smAddress
Definition: TokenParser.h:79
char * setString
Definition: TokenParser.h:80