ESP_IOT v2.5
IOT ESP Coding
StepperModule.cpp
Go to the documentation of this file.
1/**
2* \link StepperModule
3*/
4
5#include "StepperModule.h"
6#include "PTStepper.h"
7
8#ifdef ESP_M5
9
11{
12
13}
14
15//!the main loop fro the StepperModule. This used be called FeederStateMachine()
17{
18
19}
20#else
21
22
23//! called to set a preference (which will be an identifier and a string, which can be converted to a number or boolean)
24void stepperModule_savePreference(int preferenceID, String preferenceValue);
25
26/*feederState*/
27#define FEED_STOPPED 0
28#define SINGLE_FEED 1
29#define AUTO_FEED 2
30#define JACKPOT_FEED 3
31
33int _feedsPerJackpot = 3; //this will be set by user at some point
34int _feedCount = _feedsPerJackpot; //init to max feeds per Jackpot
35
36#define FEED_INTERVAL 1000 // make this a variable determined by user input and stored in JSON
37unsigned long feedPreviousMillis = 0;
38
39//proteced
40// someone else the "savePreferenceBoolean_mainModule(PREFERENCE_STEPPER_BUZZER_VALUE) knows where to save it..
41
42//!returns the buzzer status
44{
46 return buzzStatus;
47}
48
49//! retreives the feeder type (versus grabbing a global variable)
51{
53}
54
55//!called on setup()
57{
59
60 //calls the PTStepper setup
62}
63
64//TODO: this isn't directly called.. but called from the main processsClientCommand(String cmd)
65////Keep ProcessClientCmd short to let the callback run. instead change the feeder state flag
67 SerialLots.printf("***** ProcessClientCmd(%c) from client*****\n", cmd);
68
69 if ((cmd == 0x00) || (cmd == 's') || (cmd == 'c'))
70 {
71 SerialLots.println("Setting FeedState = SINGLE_FEED");
72 _feedState = SINGLE_FEED; // Gen 3 Pet Tutor used 0x00 to feed so 0x00 is to make it backward compatible 's' is the new version
73 //not used .. for awhile.. So let's stop writing to EPROM all the time.
74 }
75 else if (cmd == 'a')
76 {
77 SerialLots.println("Setting FeedState = AUTO_FEED");
79
80 }
81 else if (cmd == 'j')
82 {
83 SerialLots.println("Setting FeedState = JACKPOT_FEED");
85
86 }
87 else if (cmd == 'B')
88 {
89 SerialLots.println("1.Setting buzzStatus = BUZZON");
90
91 //set the flag, then buz.. (or don't care, and the value is stored in mainModule.. TODO: maybe that should cache the result)
92
93 //make a buzz sound..
96
97 }
98 else if (cmd == 'b')
99 {
100 SerialLots.println("2.Setting buzzStatus = BUZZOFF");
102 }
103
104 //!NOTE: There are other commands, but these are only the ones that require a action.
105 //!TODO: make these "events" on the setting of those values. eg. register for stepperValue true or false, etc.. They would be invoked from the 'savePreferencesBoolean' call.
106}
107//void FeederStateMachine() {
108
109//!the main loop fro the StepperModule. This used be called FeederStateMachine()
111{
112 // FeedState is NO LONGER public and can be set by BLE client via the GATT for the characteristic
113
114 switch (_feedState)
115 {
116 case SINGLE_FEED:
117 {
120 SerialDebug.println("SINGLE Feed"); //this should write a 0x01 for feed ack
121 _feedState = FEED_STOPPED; //this will cancel Continous feed if it is set
122 break;
123 }
124#ifdef MOVED_TO_TIMER_LOGIC
125
126 case AUTO_FEED: //note: the only difference in this case is the FEED_STOPPED does NOT get set
127 {
128 unsigned long feedCurrentMillis = millis();
129
130 if (feedCurrentMillis - feedPreviousMillis >= FEED_INTERVAL) { // changed this to check a timer to see when to fire the feeder..session length,random interval, auto increment time
133 SerialDebug.println("AUTO Feed");
134 feedPreviousMillis = feedCurrentMillis;
135 }
136 break;
137 }
138#endif
139 case JACKPOT_FEED: //note: the only difference in this case is the FEED_STOPPED does NOT get set
140 {
141 if (_feedCount > 0) {
142 unsigned long feedCurrentMillis = millis();
143 if (feedCurrentMillis - feedPreviousMillis >= FEED_INTERVAL) { // changed this to check a timer to see when to fire the feeder
144 blinkLED_UIModule(); // Moved 021622 WJL
146 SerialDebug.println("JACKPOT Feed");
147 _feedCount--;
148 feedPreviousMillis = feedCurrentMillis;
149 }
150 }
151 else {
152 _feedCount = _feedsPerJackpot; //reset counter after all feeds for Jackpot completed
154 }
155 break;
156 }
157 case FEED_STOPPED:
158 {
159 //SerialDebug.println("Feed Stopped -- ");
160 //do nothing
161 break;
162 }
163 default:
164 {
166 break;
167 }
168 }
169}
170
171
172#endif //ESP_M5
int getFeederType_mainModule()
get the feeder type (Sepper 1,2,3 ...)
Definition: MainModule.cpp:161
void start_PTStepper()
starts the PTStepper
Definition: PTStepper.cpp:187
void setup_PTStepper()
setup the PTStepper
Definition: PTStepper.cpp:131
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 PREFERENCE_STEPPER_BUZZER_VALUE
stepper preferences
#define AUTO_FEED
void loop_StepperModule()
the main loop fro the StepperModule. This used be called FeederStateMachine()
#define FEED_STOPPED
unsigned long feedPreviousMillis
#define JACKPOT_FEED
void setup_StepperModule()
called on setup()
#define SINGLE_FEED
int getFeederType()
retreives the feeder type (versus grabbing a global variable)
void stepperModule_ProcessClientCmdFinal(char cmd)
the Blink the LED - and it will use the latest BUZZER status (so MQTT could set buzzer on....
int _feedsPerJackpot
int _feedCount
void stepperModule_savePreference(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 FEED_INTERVAL
int _feedState
boolean getBuzzStatus_StepperModule()
returns the buzzer status
void setBuzzerLight_UIModule(boolean onFlag)
UI specific actions.
Definition: UI.cpp:110
void blinkLED_UIModule()
blink the LED
Definition: UI.cpp:137