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//! 8.2.24 includeGroups
15//! 8.2.24 break up the list..
16#define NUMBER_GROUPS 4
17#define STRING_MAX_SIZE 40
19//!resulting group names
21
22
23//!Issue #103
24//!NOTE: the EPROM space might be limiting: https://github.com/espressif/arduino-esp32/blob/master/tools/partitions/default.csv
25//!to 4KB .. https://www.esp32.com/viewtopic.php?t=9136
26//! So we should start limiting our use, and start with these string indexes..
27//! main module preferences
28//! gateway is on THESE MUST ALL BE UNIQUE
29#define EPROM_MAIN_GATEWAY_VALUE "1gt"
30//!BLEServer mode
31#define EPROM_MAIN_BLE_SERVER_VALUE "2bs"
32//!BLEClient mode
33#define EPROM_MAIN_BLE_CLIENT_VALUE "3bc"
34
35//!buzzer on or off
36#define EPROM_STEPPER_BUZZER_VALUE "4bz"
37//! single feed mode
38#define EPROM_STEPPER_SINGLE_FEED_VALUE "5sf"
39//!auto feed
40#define EPROM_STEPPER_AUTO_FEED_VALUE "6af"
41//!jackpot feed
42#define EPROM_STEPPER_JACKPOT_FEED_VALUE "7jf"
43//! the step kind
44#define EPROM_STEPPER_KIND_VALUE "8sk"
45//num feeds in jackpot mode
46#define EPROM_STEPPER_FEEDS_PER_JACKPOT_VALUE "9jp"
47//! sensor preferences for tilt on or off
48#define EPROM_SENSOR_TILT_VALUE "TILT_10" //10tt"
49 //!proximity PIR
50#define EPROM_SENSOR_PIR_VALUE "11pr"
51//! display preferences zoomed or not zoomed
52#define EPROM_SEMANTIC_MARKER_ZOOMED_VALUE "12sz"
53
54//! Display preferences - show messages on blank screen- boolean
55#define EPROM_DISPLAY_ON_BLANK_SCREEN_VALUE "13bk"
56//! sets the timeout value
57#define EPROM_DISPLAY_SCREEN_TIMEOUT_VALUE "14to"
58//! sets the max temp for a poweroff
59#define EPROM_HIGH_TEMP_POWEROFF_VALUE "15pw"
60//!whether to show the minimal or expanded menu
61#define EPROM_IS_MINIMAL_MENU_SETTING "16mm"
62//! sets stepper angle, a floating point number
63#define EPROM_STEPPER_ANGLE_FLOAT_SETTING "17sa"
64
65//! sets screentimeout if not button clicks (set,noclick,val,seconds)
66#define EPROM_NO_BUTTON_CLICK_POWEROFF_SETTING "18po"
67
68//!for now, save 2 WIFI Credentials
69#define EPROM_WIFI_CREDENTIAL_1_SETTING "19w1"
70//!second wifi credential
71#define EPROM_WIFI_CREDENTIAL_2_SETTING "20w2"
72
73//! the guest device paired with this M5 device (or NONE)
74#define EPROM_PAIRED_DEVICE_SETTING "21pd"
75
76//! the device name
77#define EPROM_DEVICE_NAME_SETTING "22dn"
78
79//!a firsttime feature flag (only 1 per build) 7.12.22 defaulting to TRUE
80#define EPROM_FIRST_TIME_FEATURE_SETTING "23fs"
81
82//! if true, only BLEClient connect to GEN3 feeders..
83#define EPROM_ONLY_GEN3_CONNECT_SETTING "23gs"
84
85//!color of the M5 screen
86#define EPROM_SCREEN_COLOR_SETTING "24sc"
87
88//!if set, the BLE Server (like PTFeeder) will tack on the device name (or none if not defined).
89#define EPROM_BLE_SERVER_USE_DEVICE_NAME_SETTING "25bs"
90//!if set, the BLE Client will look for its service base name (PTFeeder or PTClicker), but if that name
91//!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
92#define EPROM_BLE_USE_DISCOVERED_PAIRED_DEVICE_SETTING "26bd"
93//!NOTE: these EPROM have to be lockstep the same as the PREFERENCE definitions in MainModule.h
94
95#define EPROM_USE_DOC_FOLLOW_SETTING "27df"
96
97//! 8.17.22 to turn on/off subscribing to the dawgpack topic
98#define EPROM_SUB_DAWGPACK_SETTING "28dg"
99
100//! 8.22.22 to turn on/off SPIFF use
101#define EPROM_USE_SPIFF_SETTING "29sf"
102
103//! 9.3.22 eprom of the Address of desired BLE
104#define EPROM_PAIRED_DEVICE_ADDRESS_SETTING "30da"
105
106//!retreives the motor direction| true default, clockwise; false = REVERSE, counterclockwise 9.8.22
107//! false = reverse == counterclockwise
108//! true = default
109#define EPROM_STEPPER_FACTORY_CLOCKWISE_MOTOR_DIRECTION_SETTING "31md"
110
111//!send WIFI to all except our device (and our paired) when
112#define EPROM_SENDWIFI_WITH_BLE "32wb"
113
114//! starts the BLE Discovery notification process - which might be internal or externa (via messages).
115#define EPROM_NOTIFY_BLE_DISCOVERY "33bd"
116
117//! the preference timer
118#define EPROM_PREFERENCE_TIMER_INT_SETTING "34tm"
119
120//! the preference for supporting GROUPS (*default true)*
121#define EPROM_PREFERENCE_SUPPORT_GROUPS_SETTING "35g"
122
123//! the preference setting group names to subscribe (but empty or # go to wildcard, this also supports wildcard in the future)
124#define EPROM_PREFERENCE_GROUP_NAMES_SETTING "36g"
125
126//! a place to put some kind of Last Will of what went wrong .. for now (> max tries)
127#define EPROM_PREFERENCE_DEBUG_INFO_SETTING "37db"
128
129
130//!9.28.23 #272 only show Semantic Markers that are sent directly to the device
131#define EPROM_DEV_ONLY_SM_SETTING "38dsm"
132
133//! 11.29.23 add the max time .. so a random can be used
134#define EPROM_PREFERENCE_TIMER_MAX_INT_SETTING "39x"
135
136//! 1.1.24 the preference for all the ATOM plugs (format: atomType:value} .. for now just use socket:on
137#define EPROM_PREFERENCE_ATOMS_SETTING "40a"
138
139//!1.4.24 What kind of ATOM plug (set, M5AtomKind, val= {M5AtomSocket, M5AtomScanner}
140#define EPROM_PREFERENCE_ATOM_KIND_SETTING "41Atom"
141
142//! 1.10.24 Flag on whether a Semantic Marker command is sent on PIR, and the Command to send
143#define EPROM_PREFERENCE_SM_ON_PIR_SETTING "42pir"
144//! 1.10.24 The Semantic Marker command is sent on PIR, and the Command to send
145#define EPROM_PREFERENCE_SM_COMMAND_PIR_SETTING "43pir"
146//! 1.11.24 The Semantic Marker command is sent on PIR, and the Command to send
147#define EPROM_PREFERENCE_SM_COMMAND_PIR_OFF_SETTING "44pir"
148//! 1.12.24 Whether the AtomSocket accepts global on/off messages
149#define EPROM_PREFERENCE_ATOM_SOCKET_GLOBAL_ONOFF_SETTING "45sock"
150
151//! 4.4.24 for MQTT use of spiff (or not)
152#define EPROM_USE_SPIFF_MQTT_SETTING "46spiff"
153//! 4.4.24 for QRATOM use of spiff (or not)
154#define EPROM_USE_SPIFF_QRATOM_SETTING "47spiff"
155
156//! 8.2.24 to let older Tumbler NOT do the auto direction (back and forth)
157//! Isue #332
158//! it will set via message: autoMotorDirection
159//! {"set":"autoMotorDirection","val":"true"}
160#define EPROM_STEPPER_AUTO_MOTOR_DIRECTION_SETTING "48a"
161
162//! include these topics groups..
163#define EPROM_INCLUDE_GROUP_NAMES_SETTING "49e"
164
165//!retreives the FACTORY motor direction| true default, clockwise; false = REVERSE, counterclockwise 9.8.22
166//! false = reverse == counterclockwise
167//! true = default
168#define EPROM_STEPPER_CLOCKWISE_MOTOR_DIRECTION_SETTING "50sf"
169
170
171//! issue #338 sensor definition (in work)
172//! This will be a string in JSON format with various PIN and BUS information
173#define EPROM_SENSOR_PLUGS_SETTING "51sp"
174
175//!5.14.25 Dead 5.14.74 Montana
176//! issue #365 Object Oriented Sensors as well
177//! define the sensors (not sensorPlugs). MQTT: set:sensor, set:sensors
178#define EPROM_SENSORS_SETTING "52sensors"
179
180//!8.14.25 Dead Movie from 10.19.1974 tonight..
181//! issue #394 stepperRPM
182//! stepper RPM
183#define EPROM_STEPPER_RPM_SETTING "53sRPM"
184
185//!the EPROM is in preferences.h
186#include <Preferences.h>
187//!name of main prefs eprom
188#define PREFERENCES_EPROM_MAIN_NAME "MainPrefs"
189
190
191
192//! preferences for MAIN
194//!array of preference names (those used in process()
196//!array of default values to store in the EPROM if not defined..
198//!initialize the _preferencesMainLookup with EPROM lookup names
200
201//!Cache for heavy hitter boolean values (those referenced every loop.. seems to be hard on the EPROM to keep up:
202//! This array will only have the Boolean values set.. the 'save' will fill them, and the 'get' will return
204
205//!array of boolean if the ID is cached..
207
208//! another cache for the Int values..
210
211//!array of boolean if the ID is cached..
213
214//! 8.2.24 retrieve the includeGroup
215//! really ask a topic if it's in the include group
216//! modifies the _
217boolean topicInIncludeGroup(char *topic)
218{
219 // for now just see if topc in groups..
220 //! 8.2.24 just string match for now..
221 //! NOTE: topic is a full path .. but
222 //! MessageArrived: '#FEED {'deviceName':'MaggieMae'}', onTopic=usersP/groups/atlasDogs
223 boolean found = false;
224
225 //! find the topic (eg. usersP/groups/atlasDogs , is atlasDogs
226 char *topicName = rindex(topic,'/');
227 //! go past the "/"
228 topicName++;
229
230 //! go through list..
231 for (int i=0; i< _includeGroupLen; i++)
232 {
233 char *group = _includeGroupsStringArray[i];
234 if (group && strlen(group) == 0)
235 {
236 //!empty is a find .. not specified
237 found = true;
238 break;
239 }
240 //! note "group" the short name is 2nd so it's asking if "/userP/groups/atlasDogs contains string atlasDogs
241 //! that way the topic doesn't need to be parsed.. (although it could be wrong :eg atlas also matches..
242 //if (containsSubstring(topic, group))
243 SerialTemp.printf("compare: %s to %s\n", topicName, group);
244 if (strcmp(topicName, group) == 0)
245 {
246 found = true;
247 break;
248 }
249 }
250 if (_includeGroupLen == 0)
251 {
252 found = true;
253 }
254
255 SerialTemp.printf("topicInIncludeGroup(%s) =%d\n", topicName, found);
256 return found;
257}
258
259//! 8.2.24 set the include group (and cache it), called (indirectly from MQTT via setIncludeGroups
260void parseIncludeGroups(char *groups)
261{
262 SerialTemp.printf("parseIncludeGroups %s\n", groups);
263
264 //! parse the groups (if nothing, then it's ok if no "," use full string)
265 /**
266 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.
267 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.
268
269 char *strtok_r(char *str, const char *delim, char **saveptr);
270 @see https://www.tutorialspoint.com/c_standard_library/c_function_strtok.htm
271 @see https://linux.die.net/man/3/strtok_r
272 */
273
275 if (!index(groups,','))
276 {
277 //!no comma
280 SerialTemp.printf("Add Group[%d] %s\n", _includeGroupLen, groups);
281 }
282 else
283 {
284 char *str = groups;
285 char *rest = NULL;
286 char *token;
287 for (token = strtok_r(str,",",&rest); token != NULL; token = strtok_r(NULL, ",", &rest))
288 {
290 SerialTemp.printf("Add Group[%d] %s\n", _includeGroupLen, _includeGroupsStringArray[_includeGroupLen]);
292
293 }
294 }
295}
296
297//! 8.2.24 set the include group (and cache it), called from MQTT
298void setIncludeGroups(char *groups)
299{
300 //!process the groups..
301 parseIncludeGroups(groups);
302
303 //!save persistently
305}
306
307//! called to set a preference (which will be an identifier and a string, which can be converted to a number or boolean)
308void savePreference_mainModule(int preferenceID, String preferenceValue)
309{
310#ifdef NOT_NOW
311 if (preferenceID != PREFERENCE_DEBUG_INFO_SETTING)
312 SerialTemp.printf("savePreference .. %d = '%s'\n", preferenceID, preferenceValue.c_str());
313#endif
314 // cannot invoke the preference, as this would be an infinite loop back to here..
315
316 //save in EPROM
317 _preferencesMainModule.begin(PREFERENCES_EPROM_MAIN_NAME, false); //readwrite..
318 _preferencesMainModule.putString(_preferenceMainModuleLookupEPROMNames[preferenceID], preferenceValue);
319
320 // Close the Preferences
322
323}
324
325//! special preference string for saving and printing back later..
326#define MAX_APPEND 1500
327//!storage for the appending string
329//! called to init the preference. This won't save anything until storePreference called
331{
333}
334
335//! called to init the preference. This won't save anything until storePreference called
337{
339}
340//! called to append to a a preference (which will be an identifier and a string, which can be converted to a number or boolean)
341void appendPreference_mainModule(int preferenceID, String preferenceValue)
342{
344 {
345 SerialDebug.println(" *** preference > max, emptying .. ");
347 }
348 _appendingPreferenceString += "\n" + preferenceValue;
349}
350//! called to append to a a preference (which will be an identifier and a string, which can be converted to a number or boolean)
351void storePreference_mainModule(int preferenceID, String preferenceValue)
352{
353#ifdef AP_DEBUG_MODE
354
355 appendPreference_mainModule(preferenceID, preferenceValue);
356 // SerialDebug.printf("storePref(%d): %s\n", _appendingPreferenceString.length(), _appendingPreferenceString.c_str());
358#else
359 //!turn AP_DEBUG_MODe off for now...
360 //!1.1.24 seems the append is goofing things..
361 savePreference_mainModule(preferenceID, preferenceValue);
362
363#endif
364}
365
366//! called to reset to blank a preference (which will be an identifier and a string, which can be converted to a number or boolean)
367void resetPreference_mainModule(int preferenceID)
368{
369#ifdef DO_ERASE
370 savePreference_mainModule(preferenceID,"");
372#endif
373}
374
375
376//!sets an int preference
377void savePreferenceInt_mainModule(int preferenceID, int val)
378{
379 if (_isCachedPreferenceInt[preferenceID])
380 {
381 //! CACHE SETTINGS 1
382 _cachedPreferenceIntValues[preferenceID] = val;
383 }
384
385 //!convert to a string..
386 char str[20];
387 sprintf(str,"%d",val);
388 savePreference_mainModule(preferenceID, str);
389}
390
391//!sets an int, but only if a valid integer, and no signs. If bad, then a 0 is stored
392void savePreferenceIntFromString_mainModule(int preferenceID, char* val)
393{
394 //This function returns the converted integral number as an int value. If no valid conversion could be performed, it returns zero.
395 int num = atoi(val);
396 savePreferenceInt_mainModule(preferenceID, num);
397}
398
399//!toggles a preference boolean
401{
402 boolean val = getPreferenceBoolean_mainModule(preferenceID);
403 val = !val;
404 savePreferenceBoolean_mainModule(preferenceID, val);
405}
406
407
408
409//! called to get a preference (which will be an identifier and a string, which can be converted to a number or boolean)
410//! Note: no CACHE is looked at here. It's up to the Boolean or Int to do that..
411char* getPreference_mainModule(int preferenceID)
412{
413 // cannot invoke the preference, as this would be an infinite loop back to here..
414
415 //!get from EPROM
417
418 strcpy(_preferenceBuffer, _preferencesMainModule.getString( _preferenceMainModuleLookupEPROMNames[preferenceID]).c_str());
419#ifdef TOOMUCH
420 SerialLots.printf("getPreference_mainModule[%d] = %s\n", preferenceID, _preferenceBuffer);
421#endif
422 // Close the Preferences
424 return _preferenceBuffer;
425}
426
427
428//! called to set a preference (which will be an identifier and a string, which can be converted to a number or boolean)
429boolean getPreferenceBoolean_mainModule(int preferenceID)
430{
431 boolean valBool;
432 // check some of the boolean ones
433 if (_isCachedPreferenceBoolean[preferenceID])
434 {
435 //! CACHE SETTINGS 5
436 valBool = _cachedPreferenceBooleanValues[preferenceID];
437#ifdef TOOMUCH
438 SerialLots.print(" CACHE preference = ");
439 SerialLots.printf(" [%d] = ",preferenceID);
440 SerialLots.println(valBool);
441#endif
442 }
443 else
444 {
445 char* val = getPreference_mainModule(preferenceID);
446#ifdef TOOMUCH
447 SerialLots.print(" preference = ");
448 SerialLots.printf(" [%d] = ",preferenceID);
449 SerialLots.println(val);
450#endif
451 valBool = (strcmp(val,"1")==0)?true:false;
452 }
453 return valBool;
454}
455
456//! save a boolean preference
457void savePreferenceBoolean_mainModule(int preferenceID, boolean flag)
458{
459 if (_isCachedPreferenceBoolean[preferenceID])
460 {
461 //! CACHE SETTINGS 5
462 _cachedPreferenceBooleanValues[preferenceID] = flag;
463
464 SerialLots.print(" set CACHE preference");
465 SerialLots.printf(" [%d] = ",preferenceID);
466 SerialLots.println(flag);
467 }
468
469 savePreference_mainModule(preferenceID, flag?(char*)"1":(char*)"0");
470}
471
472
473
474//!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
475char* getPreferenceString_mainModule(int preferenceID)
476{
479}
480//! called to set a preference (which will be an identifier and a string, which can be converted to a number or boolean)
481int getPreferenceInt_mainModule(int preferenceID)
482{
483 int ival = 0;
484 if (_isCachedPreferenceInt[preferenceID])
485 {
486 ival = _cachedPreferenceIntValues[preferenceID];
487 }
488 else
489 {
490 ival = atoi(getPreference_mainModule(preferenceID));
491 }
492
493 return ival;
494}
495
496//! called to set a preference (which will be an identifier and a string, which can be converted to a number or boolean)
497float getPreferenceFloat_mainModule(int preferenceID)
498{
499 //!TODO: 8.18.24 add a cache for floats ..
500 //!actially cache the string value??
501 char* val = getPreference_mainModule(preferenceID);
502 float fval = atof(val);
503 return fval;
504}
505//! called to set a preference (which will be an identifier and a string, which can be converted to a number or boolean)
506void savePreferenceFloat_mainModule(int preferenceID, float val)
507{
508 //!convert to a string..
509 char str[20];
510 sprintf(str,"%2f",val);
511 savePreference_mainModule(preferenceID, str);
512}
513
514//! clean the preferencesMainModule in EPROM
516{
517 _preferencesMainModule.begin(PREFERENCES_EPROM_MAIN_NAME, false); //readwrite..
520}
521
522//!set some defaults on boot - that override EPROM
523//!This is also called when going back tot he MAIN menu (HOME SCREEN)
525{
526 SerialTemp.println("setOnBootPreferences_mainModule");
527 //!set zoomed = true (no semantic marker)
529
530 //!use the minimal menu on boot
532
533
534}
535
536//! reads the preferences. Save is everytime the savePreference is called
537//! 5.14.25 (Dead 5.14.74 3rd Wall of Sound)
538//! add the Sensors as well..
540{
541 SerialDebug.printf("readPreferences_mainModule(%s)\n",PREFERENCES_EPROM_MAIN_NAME);
542
543 //!clean the cached, and initialize what are cached..
544 for (int i = 0; i < MAX_MAIN_PREFERENCES; i++)
545 {
549 _isCachedPreferenceInt[i] = false;
550 }
551
552 //!intiialize the preferences arrays from EPROM. This also updates the defaults
553 //! BUT: the caches below are from the value retrieved (and defult if need be)
555
556 //!start the read-write of the EPROM
557 _preferencesMainModule.begin(PREFERENCES_EPROM_MAIN_NAME, false); //readwrite..
558
559 for (int i = 0; i < MAX_MAIN_PREFERENCES; i++)
560 {
561 String preferenceValue;
562 int preferenceID = i;
563 preferenceValue = _preferencesMainModule.getString(_preferenceMainModuleLookupEPROMNames[preferenceID]);
564 //SerialLots.printf("preverenceValue[%s] = %s\n", _preferenceMainModuleLookupEPROMNames[preferenceID], preferenceValue);
565 if (preferenceValue && preferenceValue.length() > 0)
566 {
567 // already set
568 }
569 else
570 {
571 //otherwise go to the preference defaults
572 preferenceValue = _preferenceMainModuleLookupDefaults[i];
573 _preferencesMainModule.putString(_preferenceMainModuleLookupEPROMNames[preferenceID], preferenceValue);
574 }
575 SerialLots.printf("Preference[%s] = ",_preferenceMainModuleLookupEPROMNames[preferenceID]);
576 SerialLots.println(preferenceValue);
577
578 //! check some of the boolean ones to cache .. so don't have to go to the EPROM everytime..
579 switch (i)
580 {
581 //!**** NOTE: THis is where whether things are cached or not is set! Eventually all boolean and int could be cached..
582 //! CACHE SETTINGS (boolean)
593 //!8.2.24
595
596 //SerialLots.printf("setting Cached[%d] = %s\n", i, preferenceValue);
598 _cachedPreferenceBooleanValues[i] = (preferenceValue.compareTo("1")==0)?true:false;
599 break;
600 //! CACHE SETTINGS (int)
605
606 _isCachedPreferenceInt[i] = true;
607 _cachedPreferenceIntValues[i] = atoi(&preferenceValue[0]);
608 break;
609
610 //! 8.2.24 set the includeGroups
612 //! grab the state at the start, then it's only modified from a MQTT message
613 {
615 //!save
616 //! parse (do it this way, instead of setIncludeGroups (as that stored in eprom again)
617 parseIncludeGroups(groups);
618 }
619 break;
620#ifdef TODO_THIS_CACHE
621 //! 8.18.24 figure this out ..
622 //! the UNO is not using this .. so let's not worry about it for now ... only Tumbler.
624 {
625 //! do this in the "string" part, not the float part..
626 break;
627 }
628#endif
629 default:
630 break;
631 }
632 }
633 //! Close the Preferences
635
636 //! set onbootPreferences
638
639 //! 5.14.25 (Dead 5.14.74 3rd Wall of Sound)
640 //! add the Sensors as well..
642
643}
644
645//!initialize the _preferencesMainLookup with EPROM lookup names
646//!BUT these are not stored in EPROM. The next method
648{
649 SerialDebug.println("***initPreferencesMainModule");
650#ifdef AP_DEBUG_MODE
651#else
652 // savePreference_mainModule(PREFERENCE_DEBUG_INFO_SETTING,"");
654#endif
655
656 strcpy(_preferenceBufferString,(char*)"");
657 strcpy(_preferenceBuffer,(char*)"");
658
659 for (int i = 0; i < MAX_MAIN_PREFERENCES; i++)
660 {
661 switch (i)
662 {
666#ifdef ESP_M5
667 //! 12.27.23 ON for all M5 (the reason is credentials ...)
668#ifdef ESP_M5_CAMERA
669 //!default on for the M5 Camera (but it can be turned on later..)
671#else
672#ifdef ATOM_QRCODE_MODULE
673 //! 12.8.22 default back TRUE
674 //!default off for the M5 (but it can be turned on later..)
676#else
677 //! 12.8.22 default back TRUE
678 //!default off for the M5 (but it can be turned on later..)
680#endif //ATOM
681#endif //ESP_M5_CAMERA
682#else
683 //! 12.8.22 default back TRUE
684 //!default off for the M5 (but it can be turned on later..)
686#endif //ESP_M5
687 SerialTemp.printf(" **** setting PREFERENCE_MAIN_BLE_SERVER_VALUE[%d]: %s\n", i,_preferenceMainModuleLookupDefaults[i]);
688 break;
691#ifdef ESP_M5
692 //! 12.27.23 ON for most M5 , but off for the SOCKET
693#ifdef ATOM_SOCKET_MODULE
694 //! only the SOCKET will be off by default for now...
696#else
698#endif // ESP_M5_ATOM_LITE
699
700#else
702#endif
703 break;
704 //! Sensor preferences
708 break;
713 break;
714 //!used for first time features..
718 //! This is a feeder that gateways to a GEN3
719#ifdef ESP_32_FEEDER_BLE_GEN3
721#else
722 //! This is a feeder that gateways to a GEN3
724#endif
725 break;
726
727 //INT SETTINGS..
732 break;
733
734
735 //! REST ARE NOT CACHED
736 //These are hard coded default values for the preferences
740 break;
741
742 //! STEPPER preferences (no ifdef.. )
746 break;
750 break;
754 break;
756 /*
757 per issue @269, stepper angle default = 45 (which it has been for awhile)
758 */
761#ifdef ESP_M5
762 //! 5.2.25 default 0.5 SECONDS (not angle for the HDriver
763 _preferenceMainModuleLookupDefaults[i] = (char*)"1.25";
764#else
765 _preferenceMainModuleLookupDefaults[i] = (char*)"22.5";
766#endif
767 break;
770 //! 3.28.23 change default to 5 (from 30)
772 break;
775 //! 11.29.23 add a max so random can be used
777 break;
780 /*
781 #define STEPPER_IS_UNO 1
782 #define STEPPER_IS_MINI 2
783 #define STEPPER_IS_TUMBLER 3
784 per issue @269, default is now Tumbler
785 */
787 break;
791 break;
795 break;
796
800 break;
804 break;
808 break;
811 _preferenceMainModuleLookupDefaults[i] = (char*)"480";
812 break;
816 break;
821 break;
825 _preferenceMainModuleLookupDefaults[i] = (char*)"NONE";
826 break;
830 _preferenceMainModuleLookupDefaults[i] = (char*)"NONE";
831 break;
835 _preferenceMainModuleLookupDefaults[i] = (char*)"NONE";
836 break;
840#ifdef ESP_M5
841#ifdef ESP_M5_CAMERA
842 _preferenceMainModuleLookupDefaults[i] = (char*)"M5Camera";
843#else
844#ifdef ESP_M5_ATOM_LITE
845 _preferenceMainModuleLookupDefaults[i] = (char*)"M5Atom";
846#else
848#endif //ESP_m5
849#endif //ESP_M5_Camera
850#else
851 _preferenceMainModuleLookupDefaults[i] = (char*)"ESP32";
852#endif
853 break;
854
855 //!set with message: set:bleusedevicename,val:on/off
858 //! 12.8.22 setting to TRUE as default
860#ifdef ESP_M5
861 //! 1.6.23 .. PetTutor Blue app still not always discovering new syntax
863#else
864 //! 3.24.25 use the BLE name in the feeder too..
866 //_preferenceMainModuleLookupDefaults[i] = (char*)"0";
867
868#endif
869 break;
870 //!set with message: set:bleusepaireddevicename,val:on/off
874 break;
875
879 break;
880 //!used for first time features..
885 break;
886
887 //! 8.17.22 to turn on/off subscribing to the dawgpack topic
891#ifdef ESP_M5
893#else
895#endif
896 break;
897
898 //!//! 8.22.22 to turn on/off SPIFF use (not cached yet as it's an infrequent event)
902#ifdef ESP_M5_CAMERA
904#else
906
907#endif
908 break;
909
910 //!the paired device for guest device feeding (6.6.22) .. but the Address 9.3.22
915
916 break;
917
918 ///!retreives the motor direction| 0 (false) = default, clockwise; 1 (true) = REVERSE, counterclockwise 9.8.22
919 //! TRUE = reverse == counterclockwise
920 //! FALSE = default
925
926 break;
927 //! 8.18.24 the factory setting
928 ///!retreives the motor direction| 0 (false) = default, clockwise; 1 (true) = REVERSE, counterclockwise 9.8.22
929 //! TRUE = reverse == counterclockwise
930 //! FALSE = default
935
936 break;
937
938 //! 10.4.22
943
944 break;
945
946 //! 11.1.22 TODO.. messages for this..
951 break;
952
953 //! 7.26.23 added group message support (or turn it off)
954 //! PREFERENCE_SUPPORT_GROUPS_SETTING
955 //! default OFF 1.15.24
956 //! @see https://github.com/konacurrents/ESP_IOT/issues/300
961 break;
962
963 //! 7.26.23 added group message support (or turn it off)
964 //! PREFERENCE_GROUP_NAMES_SETTING
965 //! the preference setting group names to subscribe (but empty or # go to wildcard, this also supports wildcard in the future)
970 break;
971
972 //! a place to put some kind of Last Will of what went wrong .. for now (> max tries)
973 //! 9.16.23
977 _preferenceMainModuleLookupDefaults[i] = (char*)"none";
978 break;
979
980 //! 9.28.23 #272 only show Semantic Markers that are sent directly to the device, default OFF
985 break;
986
987 //! 1.1.24 first version of preferences for the ATOMs depending on which ATOM kind
988 //! first version, only the socket and the value is on/off
989 //! syntaxURL socket=off&smscanner=on
993 _preferenceMainModuleLookupDefaults[i] = (char*)"socket=off";
994 break;
995
996 //!1.4.24 What kind of ATOM plug (set, M5AtomKind, val= {M5AtomSocket, M5AtomScanner}
1000 _preferenceMainModuleLookupDefaults[i] = (char*)"M5AtomScanner";
1001 break;
1002
1003 //! 1.10.24 The Semantic Marker command is sent on PIR, and the Command to send
1008 break;
1009
1010 //! 1.10.24 The Semantic Marker command is sent on PIR, and the Command to send
1014 _preferenceMainModuleLookupDefaults[i] = (char*)"{'set':'socket','val':'on'}";
1015 break;
1016 //! 1.11.24 The Semantic Marker command is sent on PIR, and the Command to send for OFF
1020 _preferenceMainModuleLookupDefaults[i] = (char*)"{'set':'socket','val':'off'}";
1021 break;
1022
1023 //! 1.12.24 whether global on/off is allowed. Default on..
1028 break;
1029
1030 //!//! 4.4.24 to turn on/off SPIFF use (not cached yet as it's an infrequent event)
1034#ifdef USE_SPIFF_MQTT_SETTING
1036#endif //USE_SPIFF_MQTT_SETTING
1037 break;
1038 //!//! 4.4.24 to turn on/off SPIFF use (not cached yet as it's an infrequent event)
1042#ifdef USE_SPIFF_QRATOM_SETTING
1044#endif //USE_SPIFF_QRATOM_SETTING
1045 break;
1046
1047
1048 //! 8.2.24 to let older Tumbler NOT do the auto direction (back and forth)
1049 //! Isue #332
1050 //! it will set via message: autoMotorDirection
1051 //! {"set":"autoMotorDirection","val":"true"}
1056 break;
1057
1058 //! 8.2.24 include these groups (or none)
1059 //! {"set":"includeGroups","val":"group1,group2"}
1064 break;
1065
1066 //! issue #338 sensor definition (in work)
1067 //! This will be a string in JSON format with various PIN and BUS information
1071 _preferenceMainModuleLookupDefaults[i] = (char*)"L9110S_DCStepperClass";
1072 break;
1073
1074 //!5.14.25 Dead 5.14.74 Montana
1075 //! issue #365 Object Oriented Sensors as well
1076 //! define the sensors (not sensorPlugs). MQTT: set:sensor, set:sensors
1077 //! 7.9.25 default to BuzzerSensorClass and L9110S_DCStepperClass
1080 (char*)EPROM_SENSORS_SETTING;
1081 _preferenceMainModuleLookupDefaults[i] = (char*)"BuzzerSensorClass,23,33,L9110S_DCStepperClass,21,25";
1082 break;
1083
1084
1085 //!8.14.25 Dead Movie from 10.19.1974 tonight..
1086 //! issue #394 stepperRPM
1087 //! stepper RPM
1091 _preferenceMainModuleLookupDefaults[i] = (char*)"15.0";
1092 break;
1093
1094
1095 default:
1096 SerialError.printf(" ** NO default for preference[%d]\n", i);
1097 }
1098 }
1099}
1100
1101//! 7.9.25 reset SENSORS to default
1102//! "BuzzerSensorClass,23,33,L9110S_DCStepperClass,21,25"
1104{
1105 setSensorsString_mainModule((char*)"BuzzerSensorClass,23,33,L9110S_DCStepperClass,21,25");
1106}
1107
1108//!print the preferences to SerialDebug
1110{
1111 //!this inits the string to the EPROM value
1113
1114#ifdef SERIAL_DEBUG_TEMP
1115 SerialTemp.println("******************");
1116 SerialTemp.println(VERSION);
1117 SerialTemp.printf("CHIP_ID: %s\n", getChipIdString());
1118 SerialTemp.printf("PREFERENCE_DEVICE_NAME_SETTING: %s\n", getPreference_mainModule(PREFERENCE_DEVICE_NAME_SETTING));
1119
1120 //ouch.. this sets 2 values ..
1121 // readPreferences_mainModule();
1122 SerialTemp.printf("STEPPER_KIND: %d 1=UNO,2=MINI,3=TUMBLER\n", getPreferenceInt_mainModule(PREFERENCE_STEPPER_KIND_VALUE));
1123 SerialTemp.printf("PREFERENCE_TIMER_INT_SETTING: %d\n", getPreferenceInt_mainModule(PREFERENCE_TIMER_INT_SETTING));
1124 SerialTemp.printf("STEPPER_AUTO_FEED: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_STEPPER_AUTO_FEED_VALUE));
1125 SerialTemp.printf("STEPPER_JACKPOT_FEED: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_STEPPER_JACKPOT_FEED_VALUE));
1126 SerialTemp.printf("PREFERENCE_STEPPER_ANGLE_FLOAT_SETTING: %f\n", getPreferenceFloat_mainModule(PREFERENCE_STEPPER_ANGLE_FLOAT_SETTING));
1127 SerialTemp.printf("STEPPER_FEEDS_PER_JACKPOT: %d\n", getPreferenceInt_mainModule(PREFERENCE_STEPPER_FEEDS_PER_JACKPOT));
1128 SerialTemp.printf("DISPLAY_SCREEN_TIMEOUT: %d\n", getPreferenceInt_mainModule(PREFERENCE_DISPLAY_SCREEN_TIMEOUT_VALUE));
1129 SerialTemp.printf("PREFERENCE_HIGH_TEMP_POWEROFF_VALUE: %d\n", getPreferenceInt_mainModule(PREFERENCE_HIGH_TEMP_POWEROFF_VALUE));
1130 SerialTemp.printf("PREFERENCE_IS_MINIMAL_MENU_SETTING: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_IS_MINIMAL_MENU_SETTING));
1131 SerialTemp.printf("PREFERENCE_SEMANTIC_MARKER_ZOOMED_VALUE: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_SEMANTIC_MARKER_ZOOMED_VALUE));
1132 SerialTemp.printf("PREFERENCE_NO_BUTTON_CLICK_POWEROFF_SETTING: %d\n", getPreferenceInt_mainModule(PREFERENCE_NO_BUTTON_CLICK_POWEROFF_SETTING));
1133 SerialTemp.printf("PREFERENCE_MAIN_GATEWAY_VALUE: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_MAIN_GATEWAY_VALUE));
1134 SerialTemp.printf("PREFERENCE_SENSOR_TILT_VALUE: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_SENSOR_TILT_VALUE));
1135 SerialTemp.printf("WIFI_CREDENTIAL_1: %s\n", getPreference_mainModule(PREFERENCE_WIFI_CREDENTIAL_1_SETTING));
1136 SerialTemp.printf("WIFI_CREDENTIAL_2: %s\n", getPreference_mainModule(PREFERENCE_WIFI_CREDENTIAL_2_SETTING));
1137 SerialTemp.printf("PREFERENCE_PAIRED_DEVICE_SETTING: %s\n", getPreference_mainModule(PREFERENCE_PAIRED_DEVICE_SETTING));
1138 SerialTemp.printf("PREFERENCE_PAIRED_DEVICE_ADDRESS_SETTING: %s\n", getPreference_mainModule(PREFERENCE_PAIRED_DEVICE_ADDRESS_SETTING));
1139 SerialTemp.printf("PREFERENCE_BLE_SERVER_USE_DEVICE_NAME_SETTING: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_BLE_SERVER_USE_DEVICE_NAME_SETTING));
1140
1141 SerialTemp.printf("PREFERENCE_MAIN_BLE_CLIENT_VALUE: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_MAIN_BLE_CLIENT_VALUE));
1142 SerialTemp.printf("PREFERENCE_MAIN_BLE_SERVER_VALUE: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_MAIN_BLE_SERVER_VALUE));
1143 SerialTemp.printf("PREFERENCE_FIRST_TIME_FEATURE_SETTING: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_FIRST_TIME_FEATURE_SETTING));
1144 SerialTemp.printf("PREFERENCE_SCREEN_COLOR_SETTING: %d\n", getPreferenceInt_mainModule(PREFERENCE_SCREEN_COLOR_SETTING));
1145
1146 SerialTemp.printf("PREFERENCE_SUB_DAWGPACK_SETTING: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_SUB_DAWGPACK_SETTING));
1147 SerialTemp.printf("PREFERENCE_STEPPER_CLOCKWISE_MOTOR_DIRECTION_SETTING: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_STEPPER_CLOCKWISE_MOTOR_DIRECTION_SETTING));
1148 SerialTemp.printf("PREFERENCE_STEPPER_FACTORY_CLOCKWISE_MOTOR_DIRECTION_SETTING: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_STEPPER_FACTORY_CLOCKWISE_MOTOR_DIRECTION_SETTING));
1149 SerialTemp.printf("AUTO_MOTOR_DIRECTION: %d 1=reverseEachTime,2=dont\n", getPreferenceBoolean_mainModule(PREFERENCE_STEPPER_AUTO_MOTOR_DIRECTION_SETTING));
1150 //! don't change subscription but include these groups (eg. safeHouse,atlasDogs)
1151 SerialTemp.printf("PREFERENCE_INCLUDE_GROUP_NAMES_SETTING: %s\n", getPreference_mainModule(PREFERENCE_INCLUDE_GROUP_NAMES_SETTING));
1152 SerialTemp.printf("PREFERENCE_SENDWIFI_WITH_BLE: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_SENDWIFI_WITH_BLE));
1153 SerialTemp.printf("PREFERENCE_ONLY_GEN3_CONNECT_SETTING: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_ONLY_GEN3_CONNECT_SETTING));
1154 SerialTemp.printf("PREFERENCE_SUPPORT_GROUPS_SETTING: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_SUPPORT_GROUPS_SETTING));
1155 SerialTemp.printf("PREFERENCE_GROUP_NAMES_SETTING: %s\n", getPreference_mainModule(PREFERENCE_GROUP_NAMES_SETTING));
1156 SerialTemp.printf("PREFERENCE_DEV_ONLY_SM_SETTING: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_DEV_ONLY_SM_SETTING));
1157
1158 SerialTemp.printf("PREFERENCE_ATOMS_SETTING: %s\n", getPreference_mainModule(PREFERENCE_ATOMS_SETTING));
1159 SerialTemp.printf("PREFERENCE_ATOM_KIND_SETTING: %s\n", getPreference_mainModule(PREFERENCE_ATOM_KIND_SETTING));
1160
1161 //! 1.10.24 Flag on whether a Semantic Marker command is sent on PIR, and the Command to send
1162 SerialTemp.printf("PREFERENCE_SM_ON_PIR_SETTING: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_SM_ON_PIR_SETTING));
1163 //! 1.10.24 The Semantic Marker command is sent on PIR, and the Command to send
1164 SerialTemp.printf("PREFERENCE_SM_COMMAND_PIR_SETTING: %s\n", getPreference_mainModule(PREFERENCE_SM_COMMAND_PIR_SETTING));
1165 //! 1.11.24 The Semantic Marker command is sent on PIR, and the Command to send
1166 SerialTemp.printf("PREFERENCE_SM_COMMAND_PIR_OFF_SETTING: %s\n", getPreference_mainModule(PREFERENCE_SM_COMMAND_PIR_OFF_SETTING));
1167 //! 1.12.24 The Semantic Marker command is sent on PIR, and the Command to send
1168 SerialTemp.printf("PREFERENCE_ATOM_SOCKET_GLOBAL_ONOFF_SETTING: %d\n", getPreferenceBoolean_mainModule(PREFERENCE_ATOM_SOCKET_GLOBAL_ONOFF_SETTING));
1169
1170 SerialTemp.printf("PREFERENCE_SENSOR_PLUGS_SETTING: %s\n", getPreference_mainModule(PREFERENCE_SENSOR_PLUGS_SETTING));
1171
1172 //! 5.14.25
1173 SerialTemp.printf("PREFERENCE_SENSORS_SETTING: %s\n", getPreference_mainModule(PREFERENCE_SENSORS_SETTING));
1174
1175 //!8.14.25 Dead Movie from 10.19.1974 tonight..
1176 //! issue #394 stepperRPM
1177 //! stepper RPM
1178 SerialTemp.printf("PREFERENCE_STEPPER_RPM_SETTING: %s\n", getPreference_mainModule(PREFERENCE_STEPPER_RPM_SETTING));
1179
1180
1181#ifdef M5CORE2_MODULE
1182 SerialTemp.printf("PREFERENCE_M5Core2_SETTING:\n");
1183#endif
1184#if (SERIAL_DEBUG_CALL)
1185 // this is many lines long .. so only show in the CALL settting..
1186 SerialTemp.printf("PREFERENCE_DEBUG_INFO_SETTING: %s\n", getPreference_mainModule(PREFERENCE_DEBUG_INFO_SETTING));
1187#endif
1188
1189
1190 SerialTemp.printf("WIFI_CREDENTIAL: %s\n", main_JSONStringForWIFICredentials());
1191 //!retrieve a JSON string for the ssid and ssid_password: {'ssid':<ssid>,'ssidPassword':<pass>"}
1192
1193 //! 5.14.25 also print out the sensors
1194 //! print sensors
1196
1197 //! 7.31.25
1198 SerialTemp.println(" *** Example JSON messages you can modify and paste into serial monitor, no DEV required");
1199 //! TODO: add preference to not support this??
1200 //! show example JSON (break up as getPreference re-uses same string...
1201 SerialTemp.printf("{\"set\":\"sensors\",\"val\":\"%s\"}", (char*)"BuzzerSensorClass,19,22,L9110S_DCStepperClass,21,25");
1202 SerialTemp.println();
1203 SerialTemp.printf("{\"set\":\"sensors\",\"val\":\"%s\"}", (char*)"BuzzerSensorClass,21,25,ULN2003_StepperClass,23,33");
1204 SerialTemp.println();
1205 SerialTemp.printf("{\"set\":\"sensorPlugs\",\"val\":\"L9110S_DCStepperClass\"}");
1206 SerialTemp.println();
1207 SerialTemp.printf("{\"set\":\"M5AtomKind\",\"val\":\"M5HDriver\"}");
1208 SerialTemp.println();
1209 SerialTemp.printf("{\"set\":\"stepperAngle\",\"val\":\"0.25\"}");
1210 SerialTemp.println();
1211 SerialTemp.printf("{\"set\":\"stepperRPM\",\"val\":\"15.0\"}");
1212 SerialTemp.println();
1213 SerialTemp.printf("{\"set\":\"stepperAngle\",\"val\":\"2048.0\"}");
1214 SerialTemp.println();
1215
1216 SerialDebug.println("{\"ssid\":\"Bob\", \"ssidPassword\":\"scott\"}");
1217
1218
1219 //! 7.31.25 PIN USE
1221 SerialTemp.printf(" *** PIN USE (%d) .. check for duplicated. Will do this for you later..\n", pinUseStruct.pinUseCount);
1222
1223 for (int i=0; i< pinUseStruct.pinUseCount; i++)
1224 {
1225 SerialTemp.println(pinUseStruct.pinUseArray[i]);
1226 }
1227 SerialTemp.printf(" *** PIN Count = %d\n", pinUseStruct.pinUseCount);
1228
1229#endif
1230}
1231
1232
1233//!resets preferences.. Currently only reset all, but eventually reset(groups..)
1235{
1236// savePreferenceBoolean_mainModule(PREFERENCE_SENDWIFI_WITH_BLE, false);
1237// savePreferenceInt_mainModule(PREFERENCE_TIMER_INT_SETTING, 30);
1238
1239 SerialLots.println("Clean EPROM.. ");
1240 //! dispatches a call to the command specified. This is run on the next loop()
1242
1243}
1244
1245boolean _DiscoverM5PTClicker = false;
1246//!transient for now... 10.4.22
1247//! set the M5 PTClicker discovery option..
1248void setDiscoverM5PTClicker(boolean flag)
1249{
1250 SerialTemp.println("Setting _DiscoverM5PTClicker");
1251 _DiscoverM5PTClicker = flag;
1252}
1253//! get option
1255{
1256 return _DiscoverM5PTClicker;
1257}
1258
1259
1260//! if the preference was retrieved..
1261boolean _firstTimeAtomKind = true;
1263//!returned from mainModule
1264//#define ATOM_KIND_M5_SCANNER 0
1265//#define ATOM_KIND_M5_SOCKET 1
1266//! new 1.4.24 setting ATOM kind (eg. M5AtomSocket, M5AtomScanner)
1267//! 1.5.24 also set the initial atom storage
1268//! Then the device reboots.. so setup() and loop() are for the correct ATOM
1270{
1271 SerialDebug.printf("M5AtomKind = %s\n", value.c_str());
1272 _firstTimeAtomKind = true;
1274
1275 //! 1.5.24 also set the initial atom storage
1276 //! 1.4.24 use the _atomKind (which CAN change)
1277 switch (getM5ATOMKind_MainModule())
1278 {
1280 //! 8.1.23 for the ATOM Lite QRCode Reader
1282 break;
1284 //! 12.26.23 for the ATOM Socket Power
1286 break;
1287 }
1288
1289}
1290//! new 1.4.24 setting ATOM kind (eg. M5AtomSocket, M5AtomScanner)
1292{
1294 return atomKind;
1295}
1296
1297//! new 1.4.24 setting ATOM kind (eg. ATOM_KIND_M5_SCANNER, ATOM_KIND_M5_SOCKET)
1298//! sets global _ATOM_KIND
1300{
1301 //! optimize to only call this retrieval from EPROM 1 time.. unless changing the ATOMKind
1303 {
1304 char *atomKind = getPreferenceATOMKind_MainModule();
1305 if (strcasecmp(atomKind,"M5AtomScanner")==0)
1306 {
1308 }
1309 else if (strcasecmp(atomKind,"M5AtomSocket")==0)
1310 {
1312 }
1313 _firstTimeAtomKind = false;
1314 }
1315 return _ATOM_KIND;
1316}
1317
1318#define NEW_SENSORS_PREFERENCE
1319//! 5.14.25 Hanging with Tyler,
1320//! Dead Montana 5.14.74 great stuff
1321//! add the Sensors Preference .. first the parsing
1322
1323
1324#define PRINT SerialDebug.printf
1325
1327
1328//! array of sensorStruct
1330
1331//! array
1333
1334//! print sensor
1336{
1337 if (sensor)
1338 PRINT("SENSOR: %s,%d,%d\n", sensor->sensorName, sensor->pin1, sensor->pin2);
1339 else
1340 PRINT("SENSOR: **** Null sensor ***\n");
1341}
1342
1343
1344//! print sensors, passing in a struct
1346{
1347 PRINT("SENSORS ******** \n");
1348 int count = sensors->count;
1349 for (int i=0; i< count; i++)
1350 {
1351 printSensor_mainModule(&sensors->sensors[i]);
1352 }
1353 PRINT(" ******** \n");
1354}
1355
1356//! return the sensors defined
1358{
1360}
1361
1362//! return the sensor specified or null
1364{
1365 SensorStruct *sensor = NULL;
1367 {
1368 SerialDebug.println(" **** sensorsStructs_mainModule NULL ****");
1369 return NULL;
1370 }
1371
1372 int count = _sensorsStructs_mainModule->count;
1373 for (int i=0; i< count; i++)
1374 {
1375 if (strcmp(_sensorsStructs_mainModule->sensors[i].sensorName, sensorName) == 0)
1376 {
1377 sensor = &_sensorsStructs_mainModule->sensors[i];
1378 break;
1379 }
1380 }
1381// if (!sensor)
1382// PRINT("*** No sensor: %s\n", sensorName);
1383 return sensor;
1384}
1385
1386//! Only 1 setSensorsString now .. will always append
1387//! unless a null or blank "" string
1388//! set a sensor val (array of sensor,pin,pin,sensor,pin,pin...)
1389void setSensorsString_mainModule(char *sensorsString)
1390{
1391 //! for now .. resetting
1392 //! 5.17.25
1393 strcpy(_sensorsEPROM, "");
1394
1395 PRINT("setSensorsString_mainModule(%s)\n", sensorsString);
1396 //! init EPROM
1397 if (!sensorsString || strlen(sensorsString)==0)
1398 strcpy(_sensorsEPROM, "");
1399 else if (strlen(_sensorsEPROM) > 0)
1400 {
1401 // add a ','
1402 strcat(_sensorsEPROM, ",");
1403 }
1404 strcat(_sensorsEPROM, sensorsString);
1405
1406 //! store in EPROM
1408
1409 //! Parse to the global..
1411}
1412
1413//! init the sensorString from EPROM
1414//!PREFERENCE_SENSOR_PLUGS_SETTING
1416{
1417 SerialDebug.println("**** initSensorStringsFromEPROM_mainModule ****");
1419 //! Parse to the global..
1421}
1422//! **********************************
1423
1424
1425//! copy string
1427{
1428 char *copy = strdup(str);
1429 return copy;
1430}
1431
1432//! 3.29.25 Raiiiinier Beeer movie last night
1433//! 5.13.25 Home with Tyler, Mom in LA
1434//! Foundation triligy..
1435//! parseSensorString_mainModule the string
1437{
1438 //! result
1439 SensorsStruct *sensors;
1440 //! default
1441 sensors = (SensorsStruct*) calloc(1,sizeof(SensorsStruct));
1442 sensors->count = 0;
1443 sensors->sensors = NULL;
1444
1445 //! syntax: sensor,pin1,pin2
1446 PRINT("*** parseSensorString_mainModule: %s\n", sensorsString);
1447
1448 if (!sensorsString || strlen(sensorsString)==0)
1449 {
1450 return sensors;
1451 }
1452
1453 char *rest = NULL;
1454 char *token;
1455 int arrayIndex = 0;
1456
1457 //! needed to copy sensorsString.. as the code below broke the callers' value to "https:" .. SIDE EFFECT
1458 char str[300];
1459 char strCopy[300];
1460 strcpy(str,sensorsString);
1461 strcpy(strCopy,sensorsString);
1462
1463 //! resulting array
1464 SensorStruct *sensorItems;
1465
1466 //! number of sensors
1467 int numSensors;
1468
1469 //! 2 pass
1470 for (int whichPass = 0; whichPass<2; whichPass++)
1471 {
1472#define secondPass (whichPass == 1)
1473 int max = 3;
1474
1475 if (secondPass)
1476 {
1477 numSensors = arrayIndex / max;
1478 strcpy(str,strCopy);
1479 PRINT(" ** Create sensors %d\n", numSensors);
1480 sensorItems= (SensorStruct*) calloc(numSensors,sizeof(SensorStruct));
1481 }
1482
1483 //! reset arrayIndex (which will be increments of 3)
1484 arrayIndex = 0;
1485
1486 //! 2 pass, first count, 2nd parseSensorString_mainModule
1487
1488 //! look for tokens, comma seperated
1489 for (char *token= strtok(str,","); token!= NULL; token= strtok(NULL, ","))
1490 {
1491 int indexInSensor = arrayIndex / max;
1492 int indexInArray = arrayIndex % max;
1493 //PRINT("%d Token[%d] = %s\n",indexInArray, indexInSensor, token);
1494
1495 //! which of the max is this..
1496 switch (indexInArray)
1497 {
1498 case 0:
1499 {
1500 if (secondPass)
1501 {
1502 //PRINT("Sensor = %s\n", token);
1503 sensorItems[indexInSensor].sensorName = copyString_mainModule(token);
1504
1505 //! empty the class
1506 sensorItems[indexInSensor].sensorClassType = NULL;
1507
1508 }
1509 break;
1510 }
1511 case 1:
1512 {
1513 if (secondPass)
1514 {
1515 int pin = atoi(token);
1516 if (pin == 16 || pin == 17)
1517 {
1518 //!@see https://www.reddit.com/r/arduino/comments/1g89dlo/esp32_crashing_due_to_pinmode_and_fastled/
1519 SerialDebug.printf("*** BAD PIN: %d, setting to 22 ***\n", pin);
1520 pin = 22;
1521 }
1522 //PRINT("Pin1= %d\n", pin);
1523 sensorItems[indexInSensor].pin1= pin;
1524 }
1525 break;
1526 }
1527 case 2:
1528 {
1529 if (secondPass)
1530 {
1531 int pin = atoi(token);
1532 if (pin == 16 || pin == 17)
1533 {
1534 SerialDebug.printf("*** BAD PIN: %d, setting to 22 ***\n", pin);
1535 pin = 22;
1536 }
1537 //PRINT("Pin2= %d\n", pin);
1538 sensorItems[indexInSensor].pin2= pin;
1539 }
1540 break;
1541 }
1542 }
1543 //! only incremnet arrayIndex when
1544 arrayIndex++;
1545 }
1546 }
1547
1548 //! update the result (storage already created)
1549 sensors->count = numSensors;
1550 sensors->sensors = sensorItems;
1551
1552 return sensors;
1553}
1554
char * main_JSONStringForWIFICredentials()
retrieve a JSON string for the ssid and ssid_password: {'ssid':<ssid>,'ssidPassword':<pass>"}
Definition: MainModule.cpp:904
void main_dispatchAsyncCommand(int asyncCallCommand)
checks if any async commands are in 'dispatch' mode, and if so, invokes them, and sets their flag to ...
char * getChipIdString()
3.17.24 get the chip id as a string
PinUseStruct getPinUseStruct_mainModule()
get the pin use array
#define NO_POWEROFF_AMOUNT_STRING_MAIN
Definition: MainModule.h:68
#define ASYNC_CALL_CLEAN_EPROM
cleans the EPROM totally, and reboots
Definition: MainModule.h:195
#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
void resetSensorToDefault_mainModule()
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
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 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
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..)
#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 EPROM_STEPPER_CLOCKWISE_MOTOR_DIRECTION_SETTING
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 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...
#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 PRINT
#define EPROM_STEPPER_RPM_SETTING
SensorsStruct * parseSensorString_mainModule(char *str)
array
#define secondPass
void initSensorStringsFromEPROM_mainModule()
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
#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
#define EPROM_SENSOR_TILT_VALUE
sensor preferences for tilt on or off
#define MAX_APPEND
special preference string for saving and printing back later..
boolean topicInIncludeGroup(char *topic)
char * copyString_mainModule(char *str)
copy string
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
#define EPROM_MAIN_BLE_CLIENT_VALUE
BLEClient mode.
#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...
int _cachedPreferenceIntValues[MAX_MAIN_PREFERENCES]
another cache for the Int values..
boolean _firstTimeAtomKind
if the preference was retrieved..
#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...
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
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
void initPreferencesMainModule()
initialize the _preferencesMainLookup with EPROM lookup names
char _sensorsEPROM[500]
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 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 PREFERENCE_WIFI_CREDENTIAL_2_SETTING
#define ATOM_KIND_M5_SOCKET
#define PREFERENCE_STEPPER_RPM_SETTING
#define PREFERENCE_MAIN_BLE_SERVER_VALUE
#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 PREFERENCE_USE_DOC_FOLLOW_SETTING
for
#define PREFERENCE_WIFI_CREDENTIAL_1_SETTING
#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_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 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 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 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
char * pinUseArray[PIN_USE_MAX]
Definition: MainModule.h:497
SensorClassType * sensorClassType
and the pointer to matching SensorClassType
SensorStruct * sensors
array of sensorStruct