1#include "../../Defines.h"
7#define MenusModel_Help 0
8#define MenusModel_Settings 1
9#define MenusModel_Pairing 2
10#define MenusModel_APMode 3
11#define MenusModel_Timer 4
12#define MenusModel_Status 5
13#define MenusModel_Advanced 6
14#define MenusModel_WIFIShare 7
15#define MenusModel_GuestFeed 8
16#define MenusModel_GuestPage 9
17#define MenusModel_DocFollow 10
18#define MenusModel_Max 11
66 SerialMin.println(
" *** invalid menu item");
118 SerialCall.printf(
"initTimer: sec = %d\n",
_modelStateStructs[i].currentCounterSeconds);
119#if defined(ESP_M5_CAMERA) || defined(ESP_32)
136 SerialDebug.printf(
"setTimerDelaySeconds_mainModule(%d)\n", delaySeconds);
153 SerialDebug.printf(
"startStopTimer_mainModule(%d, %d)\n", startTimer, timerModelStruct->
delaySeconds);
168 SerialTemp.print(
"deviceState->pairedDeviceStateEnum: ");
173 SerialLots.println(
"pairedButNotConnectedEnum");
177 SerialLots.println(
"pairedAndConnectedEnum");
181 SerialLots.println(
"pairableAndConnectedEnum");
185 SerialLots.println(
"notConnectedEnum");
192 SerialTemp.println(
"deviceState = rebootModel ");
210 SerialTemp.println(
"deviceState = menusModel ");
215 SerialTemp.println(
"deviceState = timerModel ");
219 SerialTemp.printf(
"deviceState->maxItems (%d) \n", deviceState->
maxItems );
220 SerialTemp.printf(
"deviceState->currentItem (%d) \n", deviceState->
currentItem );
229 SerialCall.printf(
"getModel(%d) = %d\n", modelKind, model);
242 SerialCall.printf(
"hasModelForSM_Mode(%d) == yes\n", SM_Mode);
248 SerialCall.printf(
"hasModelForSM_Mode(%d) == NO\n", SM_Mode);
261 item = (item + 1) % max;
264 SerialCall.printf(
"incrementMenuState(%d) = %d \n", modelKind, item);;
271 SerialDebug.println(
"restartAllMenuStates");
292 char _smMessage_ModelController[30];
297#ifdef USE_MQTT_NETWORKING
314#ifdef NO_MORE_PREFERENCE_BLE_USE_DISCOVERED_PAIRED_DEVICE_SETTING
328#ifdef USE_BLE_CLIENT_NETWORKING
339#ifdef USE_BLE_CLIENT_NETWORKING
353 SerialLots.printf(
"invokePair(%s, gen3=%d)\n", deviceName, isGEN3);
366#ifdef NO_MORE_PREFERENCE_BLE_USE_DISCOVERED_PAIRED_DEVICE_SETTING
374#ifdef USE_BLE_CLIENT_NETWORKING
392 SerialTemp.println(
" *** GEN3 only but connected to a non GEN3 .. so unpair **");
403 SerialCall.printf(
"updateMenuState(%d) \n", modelKind);
410 char pairedDeviceString[50];
411 char pairedDeviceAddressString[50];
416#ifdef USE_BLE_CLIENT_NETWORKING
419 boolean isConnectedBLE =
false;
421 SerialLots.printf(
"\nPAIRED_DEVICE_MODEL\n");
422 SerialLots.printf(
"isConnectedBLE(%d)\n", isConnectedBLE);
426 SerialLots.printf(
"gen3Only(%d)\n", gen3Only);
431 SerialLots.printf(
"gatewayOn(%d)\n", gatewayOn);
435 strcpy(pairedDeviceString, pairedDeviceTemp);
436 SerialLots.printf(
"pairedDevice(%s)\n", pairedDeviceString);
439 strcpy(pairedDeviceAddressString, pairedDeviceAddressTemp);
441 SerialLots.printf(
"pairedDeviceAddress(%s)\n", pairedDeviceAddressString);
445 SerialLots.printf(
"connectedBLEDeviceName(%s)\n", connectedBLEDeviceName);
448 SerialLots.printf(
"connectedBLEDeviceNameAddress(%s)\n", connectedBLEDeviceNameAddress);
451 boolean pairedAndConnected =
false;
452 boolean pairedButNotConnected =
false;
453 boolean pairableAndConnected =
false;
454 boolean unpaired =
false;
460 if (strcmp(pairedDeviceString,connectedBLEDeviceName)==0 ||
461 strcmp(pairedDeviceAddressString,connectedBLEDeviceNameAddress)==0)
463 pairedAndConnected =
true;
465 pairableAndConnected =
true;
468 else if (strlen(pairedDeviceString) > 0 || strlen(pairedDeviceAddressString) > 0)
470 if (strlen(pairedDeviceString) > 0 && strcmp(pairedDeviceString,(
char*)
"NONE")==0)
472 else if (strlen(pairedDeviceAddressString) > 0 && strcmp(pairedDeviceAddressString,(
char*)
"NONE")==0)
476 pairedButNotConnected =
true;
484 if (pairedButNotConnected)
485 SerialLots.printf(
"pairedButNotConnected(%d)\n", pairedButNotConnected);
486 if (pairedAndConnected)
487 SerialLots.printf(
"pairedAndConnected(%d)\n", pairedAndConnected);
488 if (pairableAndConnected)
489 SerialLots.printf(
"pairableAndConnected(%d)\n", pairableAndConnected);
491 SerialLots.printf(
"unpaired(%d)\n", unpaired);
493 if (pairedButNotConnected)
499 else if (pairedAndConnected)
505 else if (pairableAndConnected)
548 SerialCall.printf(
"updateMenuState timer(%d)\n", deviceState->
delayRunning);
555 int currentTimeMillis = millis();
556 int delayMillisSeconds = deviceState->
delaySeconds * 1000;
558 SerialCall.printf(
"updateMenuState(%d) \n", modelKind);
559 SerialCall.printf(
"secondsDelay = %d\n", deviceState->
delaySeconds * 1000);
560 SerialCall.printf(
"currentAbsoluteTime = %d\n", currentTimeMillis);
561 SerialLots.printf(
"delayStartMillis = %d\n", deviceState->
delayStartMillis);
562 SerialLots.printf(
"diffMillis = %d\n", currentTimeMillis - deviceState->
delayStartMillis);
572 SerialDebug.printf(
"delayFinished \n");
613 SerialCall.printf(
"menuForState(%d,%d)\n", modelKind, item);
630 menu = (
char*)
"scan..";
634 menu = (
char*)
"unpair";
638 menu = (
char*)
"Gen3";
640 menu = (
char*)
"AnyBLE";
643 SerialMin.printf(
"a.**** Invalid item: %d\n",item);
651 menu = (
char*)
"feed";
654 menu = (
char*)
"unpair";
658 menu = (
char*)
"Gen3";
660 menu = (
char*)
"AnyBLE";
663 SerialMin.printf(
"b. **** Invalid item: %d\n",item);
671 menu = (
char*)
"feed";
674 menu = (
char*)
"skip";
677 menu = (
char*)
"pair";
681 menu = (
char*)
"Gen3";
683 menu = (
char*)
"AnyBLE";
686 SerialMin.printf(
"c. **** Invalid item: %d\n",item);
694 menu = (
char*)
"scan..";
698 menu = (
char*)
"Gen3";
700 menu = (
char*)
"AnyBLE";
703 SerialMin.printf(
"d. **** Invalid item: %d\n",item);
716 menu = (
char*)
"reboot";
719 menu = (
char*)
"poweroff";
723 menu = (
char*)
"blankscrn";
727 menu = (
char *)
"Set Uno";
730 menu = (
char *)
"Tumbler";
734 menu = (
char*)
"colorscrn";
737 menu = (
char*)
"SemMarker";
741 menu = (
char*)
"BLE+WIFI";
743 menu = (
char*)
"BLEOnly";
747 menu = (
char*)
"CycleScrn";
751 menu = (
char*)
"Wave+Page";
755 menu = (
char*)
"Wave+Strm";
760 menu = (
char*)
"PTClicker";
762 menu = (
char*)
"PTFeeder";
766 SerialMin.printf(
"e. **** Invalid item: %d\n",item);
793 menu = (
char*)
"BLEPair";
796 menu = (
char*)
"APMode";
799 menu = (
char*)
"WIFIShare";
802 menu = (
char*)
"Timer";
805 menu = (
char*)
"Advanced";
808 menu = (
char*)
"Status";
811 menu = (
char*)
"GuestPage";
814 menu = (
char*)
"GuestFeed";
817 menu = (
char*)
"Settings";
820 menu = (
char*)
"DocFollow";
823 menu = (
char*)
"Help";
827 SerialMin.printf(
"f. **** Invalid item: %d\n",item);
842 menu = (
char*)
"Stop";
844 menu = (
char*)
"Start";
857 menu = (
char*)
"Delay";
861 SerialMin.printf(
"g. **** Invalid item: %d\n",item);
875 boolean modelChanged =
false;
886 SerialCall.printf(
"pairedDeviceModel");
975 SerialCall.println(
"*** rebootModel ***");
990#ifdef USE_BLE_CLIENT_NETWORKING
995#ifdef USE_BLE_CLIENT_NETWORKING
1006 modelChanged =
true;
1010 modelChanged =
true;
1014#ifdef USE_MQTT_NETWORKING
1034#ifdef USE_MQTT_NETWORKING
1042 char pubString[100];
1044 sprintf(pubString,(
char*)
"#followMe {AVM=https://SemanticMarker.org/bot/wave/%s?action=next}", deviceState->
waveName);
1054#ifdef USE_MQTT_NETWORKING
1062 char pubString[100];
1065 sprintf(pubString,(
char*)
"#followMe {AVM=https://SemanticMarker.org/bot/wave/%s?stream=%0d&page=0}", deviceState->
waveName, deviceState->
currentStreamNum+1);
1084 SerialMin.println(
"h, *** invalid item ***");
1091 modelChanged =
true;
1092 SerialCall.println(
"*** menusModel ***");
1114 SerialCall.printf(
"*** timerModel *** %d\n", deviceState->
delayRunning);
1144 if (currentDelay == 5)
1146 else if (currentDelay == 30)
1148 else if (currentDelay == 60)
1150 else if (currentDelay == 120)
1154 SerialTemp.printf(
".. change delay = %d\n", currentDelay);
1162 SerialMin.println(
"i. *** invalid item ***");
1167 return modelChanged;
1174 boolean modelChanged =
false;
1179 char *semanticMarker = NULL;
1181#ifdef NOTHING_YET_SAVE_SOME_MEMORY
1214 return semanticMarker;
boolean isConnectedBLEClient()
returns whether connected over BLE as a client to a server(like a ESP feeder)
void disconnect_BLEClientNetworking()
try to disconnect..
void skipNameOrAddress_BLEClientNetworking(char *nameOrAddress)
an address or name to skip (for at least 1 time)
void sendCommandBLEClient_13orLess(String cmdString)
send a string of 13 characters or less
void incrementScreenColor_displayModule()
void publishMQTTMessageDefaultTopic(char *message)
Wrapper of the mqttclient publish.
void sendMessageMQTT(char *message)
boolean processJSONMessageMQTT(char *ascii, char *topic)
process the JSON message (looking for FEED, etc). Note: topic can be nil, or if not,...
void setConnectedBLEDevice_mainModule(char *deviceName, boolean isGEN3)
char * connectedBLEDeviceNameAddress_mainModule()
returns address part of name.
char * charSMMode_mainModule(int whichSMMode)
returns string form whichSMMode, sg "sm0", sm1 ...
char * deviceName_mainModule()
gets the device name
boolean connectedBLEDeviceIsGEN3_mainModule()
whether the connected is a GEN3 (so the name isn't valid)
void processClientCommandChar_mainModule(char cmd)
single character version of processClientCommand (since many used that already)
int getCurrentSMMode_mainModule()
returns the current SM Mode
char * getFullBLEDeviceName_mainModule()
full: ""Name: PTFeeder:HowieFeeder, Address: 7c:9e:bd:48:af:92, serviceUUID: 0xdead"
void setCurrentSMMode_mainModule(int whichSMMode)
sets the current screen mode .. which can be used by Button and Display processing
char * getPairedDevice_mainModule()
returns if the paired device is not NONE
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 * connectedBLEDeviceName_mainModule()
returns the connected BLE Device name (the :NAME of advertisment, Address: 01:39:3f:33 part of name,...
#define SM_pair_dev
guest feed device
#define ASYNC_REBOOT
sets the GATEWAY mode off
#define SM_guest_feed
guest feed
#define SM_guest_page
guest page
#define ASYNC_SEND_MQTT_FEED_MESSAGE
sends a message (like FEED) on the users topic
#define SM_timer
timer .. todo
#define SM_status
//status
#define MAX_SM_EXPANDED_MODES
#define ASYNC_POWEROFF
sets the GATEWAY mode off
#define ASYNC_BLANKSCREEN
blank the screen
#define SM_doc_follow
docfollow
#define SM_smart_clicker_homepage
//! homepage
#define SM_WIFI_ssid
WIFI ssid.
#define SM_ap_mode
AP MODE.
void updateMenuState(ModelKindEnum modelKind)
updates the model for the menu state, this sets max etc
void invokeUnpairNoNameBASE_ModelController()
void incrementMenuState(ModelKindEnum modelKind)
increments the device states deviceState (wrapping around)
boolean invokeMenuState(ModelKindEnum modelKind)
invokes the menu state, return true if the model state has change enough to refreesh your View (such ...
void initMenuToSMMode()
init the mapping
void invokeUnpair_ModelController(char *nameOrAddress)
performs the unpairing
void invokeFeed_ModelController()
performs the BLE feed
void invokePair_ModelController()
#define MenusModel_WIFIShare
void setTimerDelaySeconds_mainModule(int delaySeconds)
void invokeSkip_ModelController(char *nameOrAddress)
performs skip
void printDeviceState(ModelStateStruct *deviceState)
print it out..
#define MenusModel_Help
a pseudo Class
void startStopTimer_mainModule(boolean startTimer)
#define MenusModel_Status
char * menuForState(ModelKindEnum modelKind, int item)
returns the menu string for the deviceState's item number (use woudl go 0..maxItems -1
#define MenusModel_DocFollow
#define MenusModel_GuestFeed
#define MenusModel_Settings
void invokeUnpairNoName_ModelController()
ModelStateStruct * hasModelForSM_Mode(int SM_Mode)
retrieves the state model for the SM_Mode (SM_0 .. SM_LAST) null if none
#define MenusModel_Advanced
int _menuToSMMode[MenusModel_Max]
storage of mapping
char * getModelSemanticMarker(ModelKindEnum modelKind)
retrieves a semantic marker for the current selected item
ModelStateStruct * getModel(ModelKindEnum modelKind)
retrieves the state model for the modelKind
void initModelStructs_ModelController()
initialize the objects
void invokeFeedLocally()
storage..
#define MenusModel_APMode
#define MenusModel_GuestPage
#define MenusModel_Pairing
void invokeToggleGen3_ModelController()
toggles the GEN3 setting
void restartAllMenuStates_ModelController()
restarts all the menu states to the first one .. useful for getting a clean start....
ModelStateStruct _modelStateStructs[ModelKindEnumMax]
ModelKindEnum
a pseudo Class
@ pairedButNotConnectedEnum
@ notConnectedEnum
factory default but not connecte to anything..
@ pairableAndConnectedEnum
void savePreferenceInt_mainModule(int preferenceID, int val)
sets an int preference
boolean getDiscoverM5PTClicker()
get option
void savePreferenceBoolean_mainModule(int preferenceID, boolean flag)
save a boolean preference
void setDiscoverM5PTClicker(boolean flag)
boolean getPreferenceBoolean_mainModule(int preferenceID)
called to set a preference (which will be an identifier and a string, which can be converted to a num...
void togglePreferenceBoolean_mainModule(int preferenceID)
toggles a preference boolean
int getPreferenceInt_mainModule(int preferenceID)
called to set a preference (which will be an identifier and a string, which can be converted to a num...
char * getPreferenceString_mainModule(int preferenceID)
returns the preference but in it's own string buffer. As long as you use it before calling getPrefere...
void printPreferenceValues_mainModule()
print the preferences to SerialDebug
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...
#define PREFERENCE_PAIRED_DEVICE_ADDRESS_SETTING
the paired device for guest device feeding (6.6.22) .. but the Address 9.3.22
#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_SEMANTIC_MARKER_ZOOMED_VALUE
Display preferences (SemanticMarker etc) - boolean.
#define PREFERENCE_PAIRED_DEVICE_SETTING
the paired device for guest device feeding (6.6.22)
#define PREFERENCE_BLE_USE_DISCOVERED_PAIRED_DEVICE_SETTING
#define PREFERENCE_MAIN_GATEWAY_VALUE
#define PREFERENCE_TIMER_INT_SETTING
the preference timer
the struct for the models. Since this isn't straight OO, we are overlaying information....
ModelKindEnum modelKindEnum
What kind of model.
int currentCounterSeconds
current seconds (<= delaySeconds)
int currentPageState
for the next page state 0..n
boolean feedLocalOnly
feed local instead of MQTT or BLE..
int currentItem
the current item
int currentStreamNum
the stream number
char * waveName
which wave
int SM_Mode
which SM mode 0.. SM_LAST
boolean perfersBigText
a preference to the View that big text is desired
unsigned long delayStartMillis
Timer info (placeholder)
PairedDeviceStateEnum pairedDeviceStateEnum
boolean delayRunning
true if still waiting for delay to finish
int delaySeconds
length of delay (changable..)
int maxItems
the number of items in the model