-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMcCleanBox.ino
More file actions
158 lines (144 loc) · 3.97 KB
/
McCleanBox.ino
File metadata and controls
158 lines (144 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <lvgl.h>
#include <Arduino.h>
#include <M5Unified.h>
#include <esp_timer.h>
#include <string>
#include "src/ui/LVGLHelper.h"
#include "src/ui/ui.h"
#include "src/ui_actions.h"
#include "src/ext_vars.h"
#include "src/ui/vars.h"
#include "src/ext_vars.h"
//#include "src/MBsettings.h"
#include "src/file.h"
m5::rtc_datetime_t dt;
static constexpr const char* const wd[] = {"Sun","Mon","Tue","Wed","Thr","Fri","Sat","ERR"};
int inPin = 27;
int cnt = 0;
const int debounceTime = 20; // debounce in milliseconds
volatile boolean rotated = false;
bool timeron = false;
int32_t currentMillis = millis();
int32_t startMillis = millis();
int32_t previousMillis = millis();
int32_t TpreviousMillis = millis();
void improt() {
rotated = true;
}
//maybe move to UI actions
void gtimer() {
timeron = true;
currentMillis = millis();
startMillis = millis();
previousMillis = millis();
cnt = 0;
set_var_rotcount("000");
set_var_gtimerv("00.0");
}
void deBounce () //debounce function borrowed from http://gammon.com.au/interrupts
{
unsigned long now = millis ();
do
{
// on bounce, reset time-out
if (digitalRead (inPin) == LOW)
now = millis ();
}
while (digitalRead (inPin) == LOW ||
(millis () - now) <= debounceTime);
} // end of deBounce
void setup()
{
M5.begin();
///fix this
if (M5.Rtc.isEnabled()) { M5.Rtc.setDateTime( {{ 2021, 12, 31 }, { 12, 34, 56 }} );}
pinMode(27,INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(27),improt,CHANGE);
Serial.begin( 115200 );
M5.Display.setBrightness(128);
M5.Display.startWrite();
M5.Display.println("M5 Tough");
Serial.println("M5 Tough");
lvgl_init();
newfile();
if (M5.Rtc.isEnabled()) {
M5.Rtc.getDateTime(&dt);
char tm[5];
sprintf(tm, "%02d:%02d", dt.time.hours,dt.time.minutes);
set_var_time(tm);
if (M5.Rtc.getDateTime(&dt)) { /*
char dt[32];
snprintf( dt, 30, "%04d/%02d/%02d(%s)"
, dt.date.year
, dt.date.month
, dt.date.date
, wd[dt.date.weekDay & 7]
);
set_var_infobox(dt);
add_var_infobox("\n"); */
}
}
else { add_var_infobox("rtc err"); }
add_var_infobox("add software version info\n");
add_var_infobox("add impeller info\n");
add_var_infobox("add timer info\n");
Serial.println( "Setup done" );
}
void loop()
{
vTaskDelay(1);
lv_task_handler();
if (rotated == true) {
deBounce ();
cnt++;
rotated = false;
if (timeron == true) {
char cto_lv[5];
sprintf(cto_lv, "%03d", cnt);
//Serial.println(to_lv);
set_var_rotcount(cto_lv);
}
}
currentMillis = millis();
if (timeron == true) {
if (currentMillis - startMillis >= 10000) {
float td = ((currentMillis - startMillis)*0.001);
char to_lv[5];
sprintf(to_lv, "%04.1f", td);
//Serial.println(to_lv);
set_var_gtimerv(to_lv);
timeron = false;
add_var_prevresults (to_lv);
add_var_prevresults ("s ");
char cto_lv[5];
sprintf(cto_lv, "%03d", cnt);
add_var_prevresults (cto_lv);
add_var_prevresults ("r ");
add_var_prevresults ("\n");
}
if (currentMillis - previousMillis >= 99) {
float td = ((currentMillis - startMillis)*0.001);
char to_lv[5];
sprintf(to_lv, "%04.1f", td);
set_var_gtimerv(to_lv);
previousMillis = currentMillis;
}
}
ui_tick();
if (currentMillis - TpreviousMillis >= 350) {
M5.Rtc.getDateTime(&dt);
char tm[5];
sprintf(tm, "%02d:%02d", dt.time.hours,dt.time.minutes);
set_var_time(tm);
TpreviousMillis = currentMillis;
}
}
/*
Serial.print(F("- int ram tot: "));
Serial.println(ESP.getHeapSize());
Serial.print(F("- int ram left: "));
Serial.println(ESP.getFreeHeap());
Serial.print(F("- spi ram tot: "));
Serial.println(ESP.getPsramSize());
Serial.print(F("- spi ram left: "));
Serial.println(ESP.getFreePsram());*/