ESP_IOT v2.5
IOT ESP Coding
PreferencesController.h
Go to the documentation of this file.
1
2
3#ifndef PreferencesController_h
4#define PreferencesController_h
5
6/*STEPPER feederType*/
7#define STEPPER_IS_UNO 1
8#define STEPPER_IS_MINI 2
9#define STEPPER_IS_TUMBLER 3
10//! These are the "preferenceID" in the calls below..
11//! **** Preferences Setup, called from reading EPROM, and from someone saving a preference ****
12#define PREFERENCE_MAIN_GATEWAY_VALUE 0
13#define PREFERENCE_MAIN_BLE_SERVER_VALUE 1
14#define PREFERENCE_MAIN_BLE_CLIENT_VALUE 2
15
16//! stepper preferences
17#define PREFERENCE_STEPPER_BUZZER_VALUE 3
18//these 3 are mutually exclutive
19#define PREFERENCE_STEPPER_SINGLE_FEED_VALUE 4
20#define PREFERENCE_STEPPER_AUTO_FEED_VALUE 5
21#define PREFERENCE_STEPPER_JACKPOT_FEED_VALUE 6
22#define PREFERENCE_STEPPER_ANGLE_FLOAT_SETTING 7
23//! uses STEPPER type
24#define PREFERENCE_STEPPER_KIND_VALUE 8
25#define PREFERENCE_STEPPER_FEEDS_PER_JACKPOT 9
26
27//! Sensor preferences
28#define PREFERENCE_SENSOR_TILT_VALUE 10
29#define PREFERENCE_SENSOR_PIR_VALUE 11
30//! Display preferences (SemanticMarker etc) - boolean
31#define PREFERENCE_SEMANTIC_MARKER_ZOOMED_VALUE 12
32//! Display preferences - show messages on blank screen- boolean
33#define PREFERENCE_DISPLAY_ON_BLANK_SCREEN_VALUE 13
34//! sets the timeout value
35#define PREFERENCE_DISPLAY_SCREEN_TIMEOUT_VALUE 14
36//! sets the max temp for a poweroff
37#define PREFERENCE_HIGH_TEMP_POWEROFF_VALUE 15
38//! sets the max temp for a poweroff
39#define PREFERENCE_IS_MINIMAL_MENU_SETTING 16
40//! sets stepper angle, a floating point number
41//! sets screentimeout if not button clicks (set,noclick,val,seconds)
42//! NO poweroff with the GATEWAY mode
43#define PREFERENCE_NO_BUTTON_CLICK_POWEROFF_SETTING 17
44
45//!for now, save 2 WIFI Credentials
46#define WIFI_CREDENTIALS_MAX 2
47#define PREFERENCE_WIFI_CREDENTIAL_1_SETTING 18
48#define PREFERENCE_WIFI_CREDENTIAL_2_SETTING 19
49//!the paired device for guest device feeding (6.6.22)
50#define PREFERENCE_PAIRED_DEVICE_SETTING 20
51//!the device name itself (6.6.22)
52#define PREFERENCE_DEVICE_NAME_SETTING 21
53//!a firsttime feature flag (only 1 per build) 7.12.22 defaulting to TRUE
54#define PREFERENCE_FIRST_TIME_FEATURE_SETTING 22
55//! if true, only BLEClient connect to GEN3 feeders..
56#define PREFERENCE_ONLY_GEN3_CONNECT_SETTING 23
57//! ithe color of the screen 0..n
58#define PREFERENCE_SCREEN_COLOR_SETTING 24
59
60//!if set, the BLE Server (like PTFeeder) will tack on the device name (or none if not defined).
61#define PREFERENCE_BLE_SERVER_USE_DEVICE_NAME_SETTING 25
62//!if set, the BLE Client will look for its service base name (PTFeeder or PTClicker), but if that name
63//!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
64#define PREFERENCE_BLE_USE_DISCOVERED_PAIRED_DEVICE_SETTING 26
65//! for
66#define PREFERENCE_USE_DOC_FOLLOW_SETTING 27
67
68//! 8.17.22 to turn on/off subscribing to the dawgpack topic
69#define PREFERENCE_SUB_DAWGPACK_SETTING 28
70//! 8.22.22 to turn on/off SPIFF use (more below..)
71#define PREFERENCE_USE_SPIFF_SETTING 29
72
73//!the paired device for guest device feeding (6.6.22) .. but the Address 9.3.22
74#define PREFERENCE_PAIRED_DEVICE_ADDRESS_SETTING 30
75
76//!retreives the motor direction| 1) = default, clockwise; 0 = REVERSE, counterclockwise 9.8.22
77//! false = reverse == counterclockwise
78//! TRUE == default
79//! 8.18.24 note this changes so you can switch directions. the FACTORY_CLOCKWISE
80//! below is the original one time setting.
81//! Renamed to FACTORY for backward compatible
82#define PREFERENCE_STEPPER_FACTORY_CLOCKWISE_MOTOR_DIRECTION_SETTING 31
83
84//! sends the WIFI to all except current device if set
85#define PREFERENCE_SENDWIFI_WITH_BLE 32
86
87//! starts the BLE Discovery notification process - which might be internal or externa (via messages).
88#define PREFERENCE_NOTIFY_BLE_DISCOVERY 33
89
90//! the preference timer
91#define PREFERENCE_TIMER_INT_SETTING 34
92
93//! the preference for supporting GROUPS (*default true)*
94#define PREFERENCE_SUPPORT_GROUPS_SETTING 35
95
96
97//! the preference setting group names to subscribe (but empty or # go to wildcard, this also supports wildcard in the future)
98#define PREFERENCE_GROUP_NAMES_SETTING 36
99
100//! a place to put some kind of Last Will of what went wrong .. for now (> max tries)
101#define PREFERENCE_DEBUG_INFO_SETTING 37
102//! adding AP_DEBUG_MODE to let others know that DEBUG eprom is available. Turn this OFF for non dev
103//#define AP_DEBUG_MODE
104
105//!9.28.23 #272 only show Semantic Markers that are sent directly to the device
106#define PREFERENCE_DEV_ONLY_SM_SETTING 38
107
108//! the preference timer MAX (pairs with PREFERENCE_TIMER_INT_SETTING)
109#define PREFERENCE_TIMER_MAX_INT_SETTING 39
110
111//!1.1.24 the preference for all the ATOM plugs (format: atomType:value} .. for now just use socket:on
112#define PREFERENCE_ATOMS_SETTING 40
113
114//!1.4.24 What kind of ATOM plug (set, M5AtomKind, val= {M5AtomSocket, M5AtomScanner}
115#define PREFERENCE_ATOM_KIND_SETTING 41
116
117//! 1.10.24 Flag on whether a Semantic Marker command is sent on PIR, and the Command to send
118#define PREFERENCE_SM_ON_PIR_SETTING 42
119//! 1.10.24 The Semantic Marker command is sent on PIR, and the Command to send
120#define PREFERENCE_SM_COMMAND_PIR_SETTING 43
121//! 1.11.24 The Semantic Marker command is sent on PIR, and the Command to send on OFF (or opposite)
122#define PREFERENCE_SM_COMMAND_PIR_OFF_SETTING 44
123//! 1.12.24 Whether the AtomSocket accepts global on/off messages
124#define PREFERENCE_ATOM_SOCKET_GLOBAL_ONOFF_SETTING 45
125
126//! 4.4.24 Adding SPIFF for MQTT and QRATOM seperately
127//! For MQTT writing to the SPIFF
128#define PREFERENCE_USE_SPIFF_MQTT_SETTING 46
129//! For MQTT writing to the QRATOM
130#define PREFERENCE_USE_SPIFF_QRATOM_SETTING 47
131
132//! 8.2.24 to let older Tumbler NOT do the auto direction (back and forth)
133//! Isue #332
134//! it will set via message: autoMotorDirection
135//! {"set":"autoMotorDirection","val":"true"}
136#define PREFERENCE_STEPPER_AUTO_MOTOR_DIRECTION_SETTING 48
137
138//! 8.2.24 don't change subscription but include these groups (eg. safeHouse,atlasDogs)
139#define PREFERENCE_INCLUDE_GROUP_NAMES_SETTING 49
140
141//!retreives the motor direction| 1) = default, clockwise; 0 = REVERSE, counterclockwise 9.8.22
142//! false = reverse == counterclockwise
143//! TRUE == default
144//! 8.18.24 this one changes ...
145#define PREFERENCE_STEPPER_CLOCKWISE_MOTOR_DIRECTION_SETTING 50
146
147//! issue #338 sensor definition (in work)
148//! This will be a string in JSON format with various PIN and BUS information
149#define PREFERENCE_SENSOR_PLUGS_SETTING 51
150
151//!5.14.25 Dead 5.14.74 Montana
152//! issue #365 Object Oriented Sensors as well
153//! define the sensors (not sensorPlugs). MQTT: set:sensor, set:sensors
154#define PREFERENCE_SENSORS_SETTING 52
155
156//!8.14.25 Dead Movie from 10.19.1974 tonight..
157//! issue #394 stepperRPM
158//! stepper RPM
159#define PREFERENCE_STEPPER_RPM_SETTING 53
160
161//! 9.3.25 back from LA, Horses out. Tyler on lap. Europe next week
162//! sets the 2feed option (go back and forth)
163#define PREFERENCE_STEPPER_2FEED_SETTING 54
164
165//!12.21.25 Winter Solstice party ..
166//! issue #365 Object Oriented Sensors as well
167//! define the sensors (not sensorPlugs). MQTT: set:sensor, set:sensors
168#define PREFERENCE_CHAIN_SENSORS_SETTING 55
169
170#pragma mark MAX_PREFERENCE Set here
171//! ******* 1 greater than last value **** IMPORTANT *** and no gaps..
172#define MAX_MAIN_PREFERENCES 56
173
174//! 8.2.24 retrieve the includeGroup
175//! really ask a topic if it's in the include group
176boolean topicInIncludeGroup(char *topic);
177//! 8.2.24 set the include group (and cache it), called from MQTT
178void setIncludeGroups(char *groups);
179
180//!initialize the _preferencesMainLookup with EPROM lookup names
182
183//!print the preferences to SerialDebug
185
186//! Preferences for the MainModule .. basically generic settings. So any settings you want, add them here.
187//! NOTE: These are just "state" values, no methods or events are generated on saving these values.. It's up to the caller to perform events
188//! such as turning on the buzzer..
189
190//! called to init the preference. This won't save anything until storePreference called
191void initAppendingPreference_mainModule(int preferenceID);
192//! called to append to a a preference (which will be an identifier and a string, which can be converted to a number or boolean)
193void appendPreference_mainModule(int preferenceID, String preferenceValue);
194//! called to append to a a preference (which will be an identifier and a string, which can be converted to a number or boolean)
195void storePreference_mainModule(int preferenceID, String preferenceValue);
196
197//! called to reset to blank a preference (which will be an identifier and a string, which can be converted to a number or boolean)
198void resetPreference_mainModule(int preferenceID);
199
200
201
202//! called to set a preference (which will be an identifier and a string, which can be converted to a number or boolean)
203void savePreference_mainModule(int preferenceID, String preferenceValue);
204
205//! called to set a preference (which will be an identifier and a string, which can be converted to a number or boolean)
206boolean getPreferenceBoolean_mainModule(int preferenceID);
207
208//!TODO: put them in somewhere that is saving EPROM .. a SettingsModule
209//! these are implemented in the MainModule (since they are writing to the EPROM)
210//!sets and gets the "gateway" functionality
211void savePreferenceBoolean_mainModule(int preferenceID, boolean flag);
212
213//!toggles a preference boolean
214void togglePreferenceBoolean_mainModule(int preferenceID);
215
216//! called to get a preference (which will be an identifier and a string, which can be converted to a number or boolean)
217//! NOTE: this reuses same string buffer so will be overwritten on next call. Save value if you need more than one result (such as WIFI credentials, ouch)
218//! This mean any getPreference will use the same string .. so unless the result is a number or boolean, then copy it locally..
219char* getPreference_mainModule(int preferenceID);
220
221//!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
222char* getPreferenceString_mainModule(int preferenceID);
223
224//! called to get a preference (which will be an identifier and a string, which can be converted to a number or boolean)
225int getPreferenceInt_mainModule(int preferenceID);
226
227//!sets an int
228void savePreferenceInt_mainModule(int preferenceID, int val);
229
230//!sets an int, but only if a valid integer, and no signs
231void savePreferenceIntFromString_mainModule(int preferenceID, char* val);
232
233//! called to get a preference (which will be an identifier and a string, which can be converted to a number or boolean)
234float getPreferenceFloat_mainModule(int preferenceID);
235
236//! called to set a preference (which will be an identifier and a string, which can be converted to a number or boolean)
237void savePreferenceFloat_mainModule(int preferenceID, float val);
238
239//!set some defaults on boot - that override EPROM this can be called on the HOME screen to set back to normal mode..
241
242//!returns if the paired device is not NONE
244
245//!returns if the paired device is not NONE
247
248//!returns if the paired device is not NONE
250
251
252//!returns if the paired device is not NONE .. returns address or device
254
255//!resets preferences.. Currently only reset all, but eventually reset(groups..)
257
258//!transient for now... 10.4.22
259//! set the M5 PTClicker discovery option..
260void setDiscoverM5PTClicker(boolean flag);
261//! get option
262boolean getDiscoverM5PTClicker();
263
264#pragma mark ATOM Processing
265
266//! new 1.4.24 setting ATOM kind (eg. M5AtomSocket, M5AtomScanner). MQTT message "set":"M5AtomKind", val=
267void savePreferenceATOMKind_MainModule(String value);
268//! new 1.4.24 setting ATOM kind (eg. M5AtomSocket, M5AtomScanner)
270
271//!returned from mainModule
272#define ATOM_KIND_M5_SCANNER 0
273#define ATOM_KIND_M5_SOCKET 1
274//! new 1.4.24 setting ATOM kind (eg. ATOM_KIND_M5_SCANNER, ATOM_KIND_M5_SOCKET)
276
277
278
279#define NEW_SENSORS_PREFERENCE
280//! store the SensorClassType instance as well
281#include "../SensorClass/SensorClassType.h"
282//!issue #365 sensor plugs and more
283//! 5.14.25 Hanging with Tyler,
284//! Dead Montana 5.14.74 great stuff
285//! add the Sensors Preference .. first the parsing
286
287//!forward definition
288class SensorClassType;
289
290//! 12.17.25 No Power. 1 tree down, HIGH winds last night, no flooding here, but valleys and roads bad
291//! extend the parser for different SensorKindEnum with different number of parameters and types (int vs str)
292//! There will be a setSensors (existing), and then a setM5Chain the new one.. it's own EPROM too
293//!the SensorKindEnum is what state we are holding. There will be state models behind each of these.
294typedef enum
295{
299
300//! sensor struct
301//! defines the structure
302typedef struct sensorStruct
303{
305 int pin1;
306 int pin2;
307 //! and the pointer to matching SensorClassType
309
310 //!1.22.26 - with puppies
311 //!need to have multiple for ChainButtonClassType
312 //!but defining different buttons (and the order is the order plugged in)
313 //!int buttonNumber; 1..n
315
316//! wrap sensors
317typedef struct sensorsStruct
318{
319 int count;
320 //! array of sensorStruct
323
324//! return the sensor specified or null
326
327//! return the sensor specified or null
328SensorStruct* getSensor_mainModule(char *sensorName);
329
330//! Only 1 setSensorsString now .. will always append
331//! message: set:sensors, val:<val> or empty to clean it out
332//! unless a null or blank "" string
333//! set a sensor val (array of sensor,pin,pin,sensor,pin,pin...)
334//! After each set, the SensorsStruct will be updated
335void setSensorsString_mainModule(char *sensorsString);
336
337//! init the sensorString from EPROM
338//!PREFERENCE_SENSOR_PLUGS_SETTING
340
341//! print sensors, passing in a struct
343
344//! 7.9.25 reset SENSORS to default
345//! "BuzzerSensorClass,23,33,L9110S_DCStepperClass,21,25"
346//void resetSensorToDefault_mainModule();
347
348#pragma mark CHAIN
349#pragma mark CHAIN STRUCT
350#define CHAIN_USE_MAX 15
351
352#define BUTTON_ANY -1
353#define BUTTON_SHORT_PRESS 0
354#define BUTTON_LONG_PRESS 1
355#define BUTTON_DOUBLE_PRESS 2
356//! map x,y to quadrants
357#define BUTTON_JOYSTICK_LEFT 100
358#define BUTTON_JOYSTICK_TOP 101
359#define BUTTON_JOYSTICK_RIGHT 102
360#define BUTTON_JOYSTICK_BOTTOM 103
361
362
363//! 1.22.26 wrap the button
364//! define ChainbuttonStruct
365typedef struct {
366 //! chain use string for debugging printout
367 char *chainUse;
368 //! string describing the module, etc
369 //! THis can be short "BC", or long .. but trying to shorten for EPROM storage
371 //! each in chainUseCount references the 4 arrays index
372 //! the buton numbers
374 //! the set strings, val strings, device strings
376 //! val strings
378 //! the device strings
379 //! Note, if "localhost" then this is an INTERNAL message (like feed)
380 //! so use bluetooth or whatever network works
382 //! press kind: 0 = short press, 1 = long press, 2 = long long press, -1 any, 100,101,102,103 Yoystick left, top, right, bottom
385
386
387//! 12.19.25 ChainStruct, duplicated from above
388//! NOTE: the parser will be updated...
389//! TODO: update the parser
390typedef struct {
391 //! number of chain
393
394 //! 1.22.26 define a Chainbutton and creates N of them
396
398//! get the chain struct
400
401//!12.19.25 use the Chain
402//! 5.3.25 add a central clearing house for defining PIN use
403//! central clearing house for all pins used to we can analyze if there are overlaps
404//! pin is the actual number, pinName is the local name (eg. IN1_PIN or VIN_PIN).
405//! moduleName is the module in the code,
406//! isI2C is whether this is a I2C bus (which we aren't using much yet)
407//! 1.22.26 add pressKind and classType
408void registerChain_mainModule(String classType, int buttonNumber, int pressKind, String setString, String valString, String deviceString) ;
409
410
411//! COPIED from template above..
412//! Only 1 setSensorsString now .. will always append
413//! message: set:sensors, val:<val> or empty to clean it out
414//! unless a null or blank "" string
415//! set a sensor val (array of sensor,pin,pin,sensor,pin,pin...)
416//! After each set, the SensorsStruct will be updated
417void setChainSensorsString_mainModule(char *sensorsString);
418
419//! init the sensorString from EPROM
420//!PREFERENCE_SENSOR_PLUGS_SETTING
422
423//! print sensors, passing in a struct
424void printChainSensors_mainModule(ChainUseStruct* chainUseStruct);
425
426//! 7.9.25 reset SENSORS to default
427//! "BuzzerSensorClass,23,33,L9110S_DCStepperClass,21,25"
428//void resetChainSensorToDefault_mainModule();
429
430
431//! 1.22.26 Dead Morning Dew
432//! process the given button
433//! 1.24.26 NOTE: this doesn't care about button press or joystick .. it's just run that button
434void processChainUseStruct(ChainButtonStruct* chainUseStruct);
435
436//! 1.22.26 with puppies, cold dry outside
437//! get the ChainUseStruct for the buttonNumber (eg 1..9 (no 0)
438//! Column Major in the Matrix (but sequential here)
439//! return the definition for this 1 based button number (if any)] //TODO -1
440//! pressKind = -1 (matches first one ..)
441//! NOTE: pressKind for Joystick is here..
442//! 1.28.26 you can ask for BUTTON 0 (which will be the deault for the M5Atom single press (or maybe long press)
443ChainButtonStruct* getChainUseStruct(int buttonNumber_1based, int pressKind);
444
445
446#endif // PreferensesController_h
struct sensorsStruct SensorsStruct
wrap sensors
void savePreferenceInt_mainModule(int preferenceID, int val)
sets an int
boolean getDiscoverM5PTClicker()
get option
float getPreferenceFloat_mainModule(int preferenceID)
called to get a preference (which will be an identifier and a string, which can be converted to a num...
void savePreferenceBoolean_mainModule(int preferenceID, boolean flag)
save a boolean preference
void savePreferenceATOMKind_MainModule(String value)
new 1.4.24 setting ATOM kind (eg. M5AtomSocket, M5AtomScanner). MQTT message "set":"M5AtomKind",...
void printSensors_mainModule(SensorsStruct *sensors)
print sensors, passing in a struct
SensorsStruct * getSensors_mainModule()
return the sensor specified or null
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 ...
void setDiscoverM5PTClicker(boolean flag)
void setSensorsString_mainModule(char *sensorsString)
void resetAllPreferences_mainModule()
resets preferences.. Currently only reset all, but eventually reset(groups..)
ChainUseStruct * getChainUseStruct_mainModule()
get the chain struct
boolean getPreferenceBoolean_mainModule(int preferenceID)
called to set a preference (which will be an identifier and a string, which can be converted to a num...
void registerChain_mainModule(String classType, int buttonNumber, int pressKind, String setString, String valString, String deviceString)
void togglePreferenceBoolean_mainModule(int preferenceID)
toggles a preference boolean
void resetPreference_mainModule(int preferenceID)
called to reset to blank a preference (which will be an identifier and a string, which can be convert...
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)
ChainButtonStruct * getChainUseStruct(int buttonNumber_1based, int pressKind)
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
void savePreferenceIntFromString_mainModule(int preferenceID, char *val)
sets an int, but only if a valid integer, and no signs
void setOnBootPreferences_mainModule()
set some defaults on boot - that override EPROM this can be called on the HOME screen to set back to ...
@ chainClassTypeEnum
@ sensorClassTypeEnum
void initSensorStringsFromEPROM_mainModule()
char * getPairedDeviceOrAddress_mainModule()
returns if the paired device is not NONE .. returns address or device
char * getPairedDevice_mainModule()
returns if the paired device is not NONE
boolean topicInIncludeGroup(char *topic)
void setChainSensorsString_mainModule(char *sensorsString)
int getM5ATOMKind_MainModule()
new 1.4.24 setting ATOM kind (eg. ATOM_KIND_M5_SCANNER, ATOM_KIND_M5_SOCKET)
int getPreferenceInt_mainModule(int preferenceID)
called to get a preference (which will be an identifier and a string, which can be converted to a num...
char * getPreference_mainModule(int preferenceID)
boolean isValidPairedDevice_mainModule()
returns if the paired device is not NONE
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
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
void processChainUseStruct(ChainButtonStruct *chainUseStruct)
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...
struct sensorStruct SensorStruct
char * getPairedDeviceAddress_mainModule()
returns if the paired device is not NONE
char * chainUse
chain use string for debugging printout
char * valString
val strings
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
SensorClassType * sensorClassType
and the pointer to matching SensorClassType
SensorStruct * sensors
array of sensorStruct