@@ -23,7 +23,7 @@ bool web = true;
23
23
// TODO move the location of this into a platformio variable or something? Maybe the location of the file as a constant in config.h
24
24
#include " ../../wifisecret.h"
25
25
26
- // json buffer
26
+ // json docs
27
27
28
28
// config stateDoc
29
29
StaticJsonDocument<600 > stateDoc;
@@ -40,31 +40,34 @@ StaticJsonDocument<600> statusDoc;
40
40
// Used to log to UI
41
41
StaticJsonDocument<600 > logDoc;
42
42
43
- size_t len = 0 ;
43
+ // buffer for msgpack
44
+ char outBuffer[450 ];
45
+
46
+
44
47
48
+ size_t serialize_len = 0 ;
49
+
50
+ // stores websocket data from asyncWebServer that gets fed to arduinoJSON
45
51
String wsData;
46
52
53
+ // sends updates (statusDoc) to UI every interval
47
54
Neotimer update_timer = Neotimer(1000 );
48
55
49
- /* not used for dhcp
50
- // Put IP Address details
51
- IPAddress local_ip(192,168,1,1);
52
- IPAddress gateway(192,168,1,1);
53
- IPAddress subnet(255,255,255,0);
54
- */
55
-
56
+ // TOOD: consider configs from config.h to update this stuff
56
57
AsyncWebServer server (80 );
57
58
AsyncWebSocket ws (" /els" );
58
59
AsyncWebSocketClient * globalClient = NULL ;
59
- char outBuffer[450 ];
60
+
61
+
62
+ // This is a bit like a ping counter, increments each time a new status is sent to the UI
60
63
uint8_t statusCounter = 0 ;
61
64
65
+ // I htink this is sent from the UI and used to set the absolute target postion, in the Doc it is "ja"
62
66
double jogAbs = 0 ;
63
67
64
68
void saveNvConfigDoc (){
65
69
EepromStream eepromStream (0 , 512 );
66
70
serializeJson (nvConfigDoc, eepromStream);
67
- // EEPROM.commit();
68
71
eepromStream.flush ();
69
72
loadNvConfigDoc ();
70
73
}
@@ -89,6 +92,7 @@ void initNvConfigDoc(){
89
92
90
93
*/
91
94
// nvConfigDoc[""] = ;
95
+
92
96
saveNvConfigDoc ();
93
97
}
94
98
@@ -113,32 +117,60 @@ void loadNvConfigDoc(){
113
117
114
118
115
119
void updateStatusDoc (){
116
- statusDoc[" p" ] = toolRelPos;
120
+ // types the message as a status update for the UI
121
+ statusDoc[" cmd" ] = " status" ;
122
+
123
+ // Currently used for the UI DRO display,
124
+ // TODO: needs renamed and this is likely better to compute this in the browser!
125
+ // TODO: this means that we need to convert any "distance" move to steps befor it gets send to the controller
117
126
statusDoc[" pmm" ] = toolRelPosMM;
127
+ // defined in util.h and helps UI figure out what to display
118
128
statusDoc[" m" ] = (int )run_mode;
129
+ // the position in steps, only used in the "debug" screen of the ui
130
+ // TODO: could just send this and remove "pmm" and calculate position in MM in the browser
131
+ // TODO: toolPos and toolRelPos should be consolidated as they seem largely redundant
132
+ statusDoc[" p" ] = toolRelPos;
119
133
statusDoc[" tp" ] = toolPos;
120
- statusDoc[" encoderPos" ] = encoder.pulse_counter ;
134
+
135
+ statusDoc[" encoderPos" ] = encoder.getCount ();
136
+ // This is the number of encoder pulses needed before the next stepper pulse
137
+ // TODO: make this optional and move to a "debug" doc
121
138
statusDoc[" delta" ] = delta;
122
- statusDoc[ " calcPos " ] = calculated_stepper_pulses;
139
+ // this doesn't appear to be used now, but...
123
140
statusDoc[" targetPos" ] = targetToolRelPos;
141
+ // I think this is used for aboslute movements
142
+ // TODO: We should convert to steps in the UI and not have to do the conversion in the controller
124
143
statusDoc[" targetPosMM" ] = targetToolRelPosMM;
144
+ // bool for constant run mode, TODO: bad name though
125
145
statusDoc[" feeding" ] = feeding;
146
+ // bools for sync movements, TODO: bad name
126
147
statusDoc[" jogging" ] = jogging;
148
+ // bool for rapid sync movement TODO: bad name
127
149
statusDoc[" rap" ] = rapiding;
150
+ // main bool to turn movement on/off
128
151
statusDoc[" pos_feed" ] = pos_feeding;
129
- statusDoc[" jog_dong" ] = jog_done;
130
- statusDoc[" sne" ] = stopNegEx;
131
- statusDoc[" spe" ] = stopPosEx;
152
+ // the virtual stop in the Z + direction
132
153
statusDoc[" sp" ] = stopPos;
154
+ // the stop in the Z - direction
133
155
statusDoc[" sn" ] = stopNeg;
156
+ // for stats
157
+ // TODO: move this to a debug doc
134
158
statusDoc[" c0" ] = cpu0;
135
159
statusDoc[" c1" ] = cpu1;
136
- statusDoc[ " xd " ] = exDelta;
160
+ // this is incremented every status update
137
161
statusDoc[" c" ] = statusCounter++;
138
- statusDoc[" cmd" ] = " status" ;
162
+
163
+ // intended feeding "handiness" CCW or CW
164
+ // so if the spindle is rotating CW, and the intension is to feed in the Z- direction this should be false
165
+ // but this somewhat depends on the setup
139
166
statusDoc[" fd" ] = z_feeding_dir;
167
+ // Wait for the spindle/ncoder "0" position
168
+ // this acts like a thread dial
140
169
statusDoc[" sw" ] = syncWaiting;
170
+ // generated in the encoder and displayed in the UI
171
+ // TODO: consider making the smoothing configurable or done in the browser
141
172
statusDoc[" rpm" ] = rpm;
173
+ // this is the effective pulses, so 600 line encoder using full quad is 2400 CPR
142
174
statusDoc[" cpr" ] = encoder.cpr ;
143
175
sendStatus ();
144
176
}
@@ -196,29 +228,29 @@ void setRunMode(int mode){
196
228
}
197
229
198
230
void sendState (){
199
- len = serializeMsgPack (stateDoc, outBuffer);
231
+ serialize_len = serializeMsgPack (stateDoc, outBuffer);
200
232
Serial.print (" s " );
201
- ws.binaryAll (outBuffer,len );
233
+ ws.binaryAll (outBuffer,serialize_len );
202
234
}
203
235
204
236
void sendLogP (Log::Msg *msg){
205
237
logDoc[" msg" ] = msg->buf ;
206
238
logDoc[" level" ] = (int )msg->level ;
207
239
logDoc[" cmd" ] = " log" ;
208
- len = serializeMsgPack (logDoc,outBuffer);
209
- ws.binaryAll (outBuffer,len );
240
+ serialize_len = serializeMsgPack (logDoc,outBuffer);
241
+ ws.binaryAll (outBuffer,serialize_len );
210
242
}
211
243
212
244
void sendStatus (){
213
- len = serializeMsgPack (statusDoc, outBuffer);
214
- ws.binaryAll (outBuffer,len );
245
+ serialize_len = serializeMsgPack (statusDoc, outBuffer);
246
+ ws.binaryAll (outBuffer,serialize_len );
215
247
216
248
}
217
249
218
250
void sendNvConfigDoc (){
219
251
nvConfigDoc[" cmd" ] = " nvConfig" ;
220
- len = serializeMsgPack (nvConfigDoc, outBuffer);
221
- ws.binaryAll (outBuffer,len );
252
+ serialize_len = serializeMsgPack (nvConfigDoc, outBuffer);
253
+ ws.binaryAll (outBuffer,serialize_len );
222
254
}
223
255
224
256
@@ -325,8 +357,6 @@ void handleJog(){
325
357
*/
326
358
if (!pos_feeding){
327
359
setStops ();
328
- // Serial.print("updated targetToolRelPos");
329
- // Serial.println(targetToolRelPos);
330
360
jogging = true ;
331
361
init_pos_feed ();
332
362
updateStatusDoc ();
@@ -632,6 +662,7 @@ void init_ota(){
632
662
633
663
}
634
664
void sendUpdates (){
665
+ // called in main loop
635
666
if (update_timer.repeat ()){
636
667
// only send state when it changes
637
668
// updateStateDoc();
0 commit comments