|
6 | 6 | #include "parameters.h"
|
7 | 7 | #include <liveText.h>
|
8 | 8 | #include <offscreen.h>
|
| 9 | +#include "sleepTools.h" |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +#define OLED_CS 10 |
| 14 | +#define OLED_RST 6 |
| 15 | +#define OLED_SDCS 4 |
| 16 | +#define TAP_PIN 15 |
| 17 | +#define TAP_SUMTIME 20 |
| 18 | +#define TAP_NUMDATA 3 |
| 19 | +#define TAP_VAL 10 |
| 20 | +#define AWAKE_MS 8000 |
| 21 | +#define DIMMING_MS 3000 |
9 | 22 |
|
10 |
| -#define OLED_CS 10 |
11 |
| -#define OLED_RST 6 |
12 |
| -#define OLED_SDCS 4 |
13 | 23 |
|
14 | 24 | UI ourDisplay;
|
15 | 25 | blinker idleLight(13,80,2000);
|
@@ -168,74 +178,81 @@ void logInd::logging(bool onOff) {
|
168 | 178 |
|
169 | 179 |
|
170 | 180 | UI::UI(void)
|
171 |
| - : timeObj(500) { |
| 181 | + : timeObj(250) { |
172 | 182 |
|
173 | 183 | mHaveScreen = false;
|
174 | 184 | mColorMap = NULL;
|
| 185 | + mTSensor = NULL; |
175 | 186 | }
|
176 | 187 |
|
177 | 188 |
|
178 |
| -UI::~UI(void) { if (mColorMap) delete(mColorMap); } |
| 189 | +UI::~UI(void) { |
| 190 | + if (mColorMap) delete(mColorMap); |
| 191 | + if (mTSensor) delete(mTSensor); |
| 192 | +} |
179 | 193 |
|
180 | 194 |
|
181 | 195 | // We can't tell weather we have a screen or not. So we'll look for the SD drive.
|
182 | 196 | void UI::begin(void) {
|
183 | 197 |
|
184 |
| - hookup(); |
185 |
| - mHaveScreen = SD.begin(OLED_SDCS); |
186 |
| - dataLog::begin(mHaveScreen); // Hardware's been checked. Fire the logger up. |
187 |
| - if (mHaveScreen) { |
188 |
| - mHaveScreen = mHaveScreen && initScreen(ADAFRUIT_684,OLED_CS,OLED_RST,0); |
189 |
| - if (mHaveScreen) { |
190 |
| - |
191 |
| - mLastMoist = -1; |
192 |
| - mLastLimit = -1; |
193 |
| - mLastState = weAre; |
| 198 | + hookup(); |
| 199 | + mHaveScreen = SD.begin(OLED_SDCS); |
| 200 | + dataLog::begin(mHaveScreen); // Hardware's been checked. Fire the logger up. |
| 201 | + if (mHaveScreen) { |
| 202 | + mHaveScreen = initScreen(ADAFRUIT_684,OLED_CS,OLED_RST,0); |
| 203 | + if (mHaveScreen) { |
| 204 | + mTSensor = new tapSensor(TAP_PIN,TAP_SUMTIME,TAP_NUMDATA); |
| 205 | + if (mTSensor) { |
| 206 | + mTSensor->begin(); |
| 207 | + ourSleepMgr.setupSleep(AWAKE_MS,DIMMING_MS); |
| 208 | + } |
| 209 | + mLastMoist = -1; |
| 210 | + mLastLimit = -1; |
| 211 | + mLastState = weAre; |
194 | 212 |
|
195 |
| - screen->fillScreen(&black); |
196 |
| - //screen->drawRect(0,0,96,screen->height(),&white); |
197 |
| - mColorMap = new colorMultiMap(); |
198 |
| - mWetColor.setColor(LC_BLUE); |
199 |
| - mWetColor.blend(&green,40); |
200 |
| - mDryColor.setColor(LC_YELLOW); |
201 |
| - mDryColor.blend(&red,40); |
202 |
| - mDryColor.blend(&white,40); |
| 213 | + screen->fillScreen(&black); |
| 214 | + mColorMap = new colorMultiMap(); |
| 215 | + mWetColor.setColor(LC_BLUE); |
| 216 | + mWetColor.blend(&green,40); |
| 217 | + mDryColor.setColor(LC_YELLOW); |
| 218 | + mDryColor.blend(&red,40); |
| 219 | + mDryColor.blend(&white,40); |
203 | 220 |
|
204 |
| - int yPos = 0; |
| 221 | + int yPos = 0; |
205 | 222 |
|
206 |
| - mMoisture = new percView(5,yPos); |
207 |
| - mMoisture->setPercent(mLastMoist); |
208 |
| - viewList.addObj(mMoisture); |
| 223 | + mMoisture = new percView(5,yPos); |
| 224 | + mMoisture->setPercent(mLastMoist); |
| 225 | + viewList.addObj(mMoisture); |
209 | 226 |
|
210 |
| - mLimit = new percView(53,yPos); |
211 |
| - mLimit->setPercent(mLastLimit); |
212 |
| - viewList.addObj(mLimit); |
| 227 | + mLimit = new percView(53,yPos); |
| 228 | + mLimit->setPercent(mLastLimit); |
| 229 | + viewList.addObj(mLimit); |
213 | 230 |
|
214 |
| - mSlash = new label(41,yPos,96,16,"/",2); |
215 |
| - mSlash->setColors(&white); |
216 |
| - viewList.addObj(mSlash); |
217 |
| - |
218 |
| - yPos = yPos + 20; |
219 |
| - mKey = new label(9,yPos,96,16,"Reading/Limit",1); |
220 |
| - mKey->setColors(&white); |
221 |
| - viewList.addObj(mKey); |
222 |
| - |
223 |
| - mLoggingInd = new logInd(0,yPos+10); |
224 |
| - viewList.addObj(mLoggingInd); |
225 |
| - mLoggingInd->logging(false); |
226 |
| - |
227 |
| - yPos = yPos + 20; //"100/100" |
228 |
| - mState = new stateView(0,yPos); |
229 |
| - mState->setState(mLastState); |
230 |
| - viewList.addObj(mState); |
231 |
| - |
232 |
| - start(); |
233 |
| - } |
234 |
| - } |
235 |
| - if (!mHaveScreen) { |
236 |
| - pinMode(13, OUTPUT); |
237 |
| - idleLight.setOnOff(true); // Start up our running light. Its all we got. |
238 |
| - } |
| 231 | + mSlash = new label(41,yPos,96,16,"/",2); |
| 232 | + mSlash->setColors(&white); |
| 233 | + viewList.addObj(mSlash); |
| 234 | + |
| 235 | + yPos = yPos + 20; |
| 236 | + mKey = new label(9,yPos,96,16,"Reading/Limit",1); |
| 237 | + mKey->setColors(&white); |
| 238 | + viewList.addObj(mKey); |
| 239 | + |
| 240 | + mLoggingInd = new logInd(0,yPos+10); |
| 241 | + viewList.addObj(mLoggingInd); |
| 242 | + mLoggingInd->logging(false); |
| 243 | + |
| 244 | + yPos = yPos + 20; //"100/100" |
| 245 | + mState = new stateView(0,yPos); |
| 246 | + mState->setState(mLastState); |
| 247 | + viewList.addObj(mState); |
| 248 | + |
| 249 | + start(); |
| 250 | + } |
| 251 | + } |
| 252 | + if (!mHaveScreen) { |
| 253 | + pinMode(13, OUTPUT); |
| 254 | + idleLight.setOnOff(true); // Start up our running light. Its all we got. |
| 255 | + } |
239 | 256 | }
|
240 | 257 |
|
241 | 258 |
|
@@ -282,31 +299,47 @@ void UI::idle(void) {
|
282 | 299 |
|
283 | 300 | bool refresh;
|
284 | 301 | colorObj aColor;
|
285 |
| - |
286 |
| - if (mHaveScreen && ding()) { |
287 |
| - if (weAre!=sitting) { |
288 |
| - mState->setNeedRefresh(); |
289 |
| - } |
290 |
| - refresh = false; |
291 |
| - if (ourParamObj.getDryLimit()!=mLastLimit) { |
292 |
| - mLimit->setPercent(ourParamObj.getDryLimit()); |
293 |
| - mLastLimit = ourParamObj.getDryLimit(); |
294 |
| - refresh = true; |
295 |
| - } |
296 |
| - if (moisture!=mLastMoist||refresh) { |
297 |
| - setColorMap(ourParamObj.getDryLimit()); |
298 |
| - aColor = mColorMap->Map(moisture); |
299 |
| - mMoisture->setColors(&aColor,&black); |
300 |
| - mMoisture->setPercent(moisture); |
301 |
| - mLastMoist = moisture; |
302 |
| - } |
303 |
| - if (weAre!=mLastState) { |
304 |
| - mState->setState(weAre); |
305 |
| - mLastState = weAre; |
306 |
| - } |
307 |
| - if (isLogging()==mLoggingInd->holding) { // If they match, |
308 |
| - mLoggingInd->logging(isLogging()); // fix it. |
309 |
| - } // Otherwise, leave it alone! |
310 |
| - start(); |
311 |
| - } |
| 302 | + |
| 303 | + if (mTSensor) { // If we have a tap sensor.. |
| 304 | + if (mTSensor->getTapVal()>=TAP_VAL) { // If we sense a tap.. |
| 305 | + ourSleepMgr.wakeup(); // We need to wake up. |
| 306 | + } |
| 307 | + } |
| 308 | + if (mHaveScreen && ding()) { // If we have a screen and its time to check stuff.. |
| 309 | + if (ourSleepMgr.checkSleep()!=percBlack) { // If we need to change the dimming value of the display.. |
| 310 | + percBlack = ourSleepMgr.checkSleep(); // Set the new diming value. |
| 311 | + mMoisture->setNeedRefresh(); // This is SUCH the sad hack. We need to redraw everthing. |
| 312 | + mLimit->setNeedRefresh(); // This is first time coding a screen saver and there is |
| 313 | + mSlash->setNeedRefresh(); // no "draw all" method. So we hadrcode for now. |
| 314 | + mKey->setNeedRefresh(); // |
| 315 | + mLoggingInd->setNeedRefresh(); // |
| 316 | + mState->setNeedRefresh(); // |
| 317 | + } |
| 318 | + if (percBlack!=100) { // If the screen is not off.. |
| 319 | + if (weAre!=sitting) { // If we are not sitting.. (IE Watering or Soaking) |
| 320 | + mState->setNeedRefresh(); // We need to draw the state view, showing the progress bar. |
| 321 | + } |
| 322 | + refresh = false; // Default to no refresh on these next guys. |
| 323 | + if (ourParamObj.getDryLimit()!=mLastLimit) { // If the user changed the dry limit while we weren't looking.. |
| 324 | + mLimit->setPercent(ourParamObj.getDryLimit()); // Set the display limit to match the new value. |
| 325 | + mLastLimit = ourParamObj.getDryLimit(); // Save the new value for later checking. |
| 326 | + refresh = true; // And we're going to do some refreshing of the screen. |
| 327 | + } |
| 328 | + if (moisture!=mLastMoist||refresh) { // If the moisture has changed, or we need to refresh anyway.. |
| 329 | + setColorMap(ourParamObj.getDryLimit()); // Reset the color map to reflect the new dry limit. |
| 330 | + aColor = mColorMap->Map(moisture); // Map our a color for the new moisture value. |
| 331 | + mMoisture->setColors(&aColor,&black); // Set up the text colors for the drawing. |
| 332 | + mMoisture->setPercent(moisture); // Draw the new percentage value. |
| 333 | + mLastMoist = moisture; // Save off the new percentage value for chekcing later on. |
| 334 | + } |
| 335 | + } |
| 336 | + if (weAre!=mLastState) { // If we have changed state.. |
| 337 | + mState->setState(weAre); // Change the state text. |
| 338 | + mLastState = weAre; // Save off the new state for checking later on. |
| 339 | + } |
| 340 | + if (isLogging()==mLoggingInd->holding) { // If they match.. (Sadly don't know what I'm doing here.) |
| 341 | + mLoggingInd->logging(isLogging()); // fix it. |
| 342 | + } // Otherwise, leave it alone! |
| 343 | + start(); |
| 344 | + } |
312 | 345 | };
|
0 commit comments