ESP_IOT v2.5
IOT ESP Coding
UI.cpp
Go to the documentation of this file.
1//! \link UIModule
2
3//
4//
5//
6//
7
8#include "UI.h"
9
10#ifdef ESP_M5
11
12/***************** End definitons ** Start assignments **********/
15
16//!UI specific actions
17void setBuzzerLight_UIModule(boolean onFlag){}
18
19//!turns on/off a solid light
20void solidLightOnOff_UIModule(boolean onOff){}
21
22//!blink the LED
24
25#else
26
27#ifdef BOARD
28
29//! a quick call to find if is PTStepper
30boolean isPTStepper()
31{
32 //! NOTE: this is only re-evaluated on reboot .. for now
33 //! 3.16.25 for now this is compile option ..
34 //! but no reason the same build cannot support it..
35 //! sensor kind (see the M5AtomSensor .. as example)
37 //! 4.1.25 generically use identity. if nil or PTStepperClass then it's true (if ESP_32)
38 char *classIdentity = stepperIdentity_StepperModule();
39 SerialDebug.printf("sensorPlug = %s, classIdentity=%s\n", sensorPlug, classIdentity?classIdentity:(char*)"none");
40
41#ifdef ESP_32
42 boolean defaultPTStepper = true;
43#else
44 //! only esp32 has a PTStepper
45 boolean defaultPTStepper = false;
46#endif
47 if (!classIdentity || strcmp(classIdentity,"PTStepperClass")==0)
48 //! use this one...
49 return defaultPTStepper;
50 else
51 return false;
52}
53
54//!initialize the board layoud, which is different than default
55void setup_UIModule()
56{
57 if (!isPTStepper())
58 return;
59
60 //! 3.27.25 don't do this not PTFeeder plug
61
62 SerialDebug.println("XXXXXXXXXXXXXXXX BOARD Defined XXXXXXXXXXXXXXXXXXX");
63 boolean buzzStatus = getBuzzStatus_StepperModule();
64
65 pinMode(BLUE_LED, OUTPUT);
66 pinMode(GREEN_LED, OUTPUT);
67 pinMode(YELLOW_LED, OUTPUT);
68 pinMode(BUZZ, OUTPUT);
69
70 digitalWrite(BLUE_LED, LOW);
71 digitalWrite(GREEN_LED, HIGH); //turn the power light on
72
73 if (buzzStatus)
74 {
75 digitalWrite(YELLOW_LED, HIGH);
76 }
77 else
78 {
79 digitalWrite(YELLOW_LED, LOW);
80 }
81
82 pinMode(TOUCH_1, INPUT);
83 pinMode(TOUCH_2, INPUT);
84 pinMode(TOUCH_3, INPUT);
85
86 pinMode(POWER_PIN, OUTPUT);
87 digitalWrite(POWER_PIN, LOW); //nessesary to enable 6.3V circuit
88 SerialDebug.println("POWER_PIN set LOW");
89}
90//! the main loop()
91void loop_UIModule()
92{
93 //nothing yet
94}
95#else
96
97
98void setup_UIModule()
99{
100 if (!isPTStepper())
101 return;
102
103 SerialDebug.println("OOOOOOOOOOOOOOOO No BOARD Defined OOOOOOOOOOOOOOOOOOO");
104 pinMode(BUZZ, OUTPUT);
105
106 digitalWrite(BUZZ, LOW);
107}
108
109//! the main loop()
110void loop_UIModule()
111{
112 //nothing yet
113}
114#endif //BOARD
115
116//!UI specific actions
117void setBuzzerLight_UIModule(boolean onFlag)
118{
119 if (!isPTStepper())
120 return;
121
122 SerialDebug.printf("setBuzzerLight %s\n",onFlag?"ON":"OFF");
123
124#ifdef BOARD
125 //set the buzzer light on
126 digitalWrite(YELLOW_LED, onFlag?HIGH:LOW);
127#endif
128
129}
130
131//!callback for SOLID blinking led
132//void solidLight(char *message)
133void solidLightOnOff_UIModule(boolean onOff)
134{
135 if (!isPTStepper())
136 return;
137
138#ifdef ESP_32
139 SerialDebug.println("solidLight..");
140 digitalWrite(LED, onOff ? HIGH : LOW);
141#endif
142}
143
144//!blink the LED
145void blinkLED_UIModule() {
146
147 if (!isPTStepper())
148 return;
149
150#ifdef ESP_32
151 // grab the buzzStatus right now
152 boolean buzzStatus = getBuzzStatus_StepperModule();
154 int stepperSteps = (int) (stepperAngle / 0.176);
155
156 SerialDebug.printf("BlinkLed LED=%d, HIGH=%d, LOW=%d, BUZZ=%d, buzzStatus=%d, StepperAngle=%d, Steps=%d\n", LED, HIGH, LOW, BUZZ, buzzStatus, stepperAngle, stepperSteps);
157#ifdef BOARD
158 digitalWrite(BLUE_LED, HIGH); // Flash the LED
159#else
160 digitalWrite(LED, HIGH); // Flash the LED
161#endif //BOARD
162
163 if (buzzStatus)
164 {
165 SerialDebug.println("UIModule.UI.buzz");
166 digitalWrite(BUZZ, HIGH); // Buzz the Piezo
167 }
168 delay(150); // Was 300
169#ifdef BOARD
170 digitalWrite(BLUE_LED, LOW); // Flash the LED
171#else
172 digitalWrite(LED, LOW);
173#endif //BOARD
174
175
176 if (buzzStatus)
177 {
178 digitalWrite(BUZZ, LOW);
179 }
180 delay(30); // Kill time to detect double beep
181#endif //ESP_32
182}
183
184#endif //ESP_M5
#define LED
defines.h defines the #ifdef USE_MODULE statements, as they are included elsewhere....
Definition: ESP_IOT.ino:14
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...
char * getPreference_mainModule(int preferenceID)
#define PREFERENCE_SENSOR_PLUGS_SETTING
#define PREFERENCE_STEPPER_ANGLE_FLOAT_SETTING
char * stepperIdentity_StepperModule()
boolean getBuzzStatus_StepperModule()
returns the buzzer status
void setup_UIModule()
UIModule
Definition: UI.cpp:13
void loop_UIModule()
Definition: UI.cpp:14
void setBuzzerLight_UIModule(boolean onFlag)
UI specific actions.
Definition: UI.cpp:17
void blinkLED_UIModule()
blink the LED
Definition: UI.cpp:23
void solidLightOnOff_UIModule(boolean onOff)
turns on/off a solid light
Definition: UI.cpp:20
#define BUZZ
Definition: UI.h:7