Skip to content

Commit fd246ec

Browse files
author
me
committed
working through cleanup of json docs and unused variables
1 parent ad1f870 commit fd246ec

File tree

4 files changed

+60
-148
lines changed

4 files changed

+60
-148
lines changed

src/src/Stepper.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,12 @@ volatile double targetToolRelPos = 0;
3636
int use_limit = false;
3737
volatile int64_t calculated_stepper_pulses=0;
3838

39-
volatile bool jog_done = true;
4039
volatile int32_t jog_steps = 0;
4140
volatile double jog_scaler = 0.2;
4241
volatile uint16_t vel = 1;
4342
volatile double stopPos = 0;
4443
volatile double stopNeg = 0;
4544
volatile bool useStops = true;
46-
volatile bool stopPosEx = false;
47-
volatile bool stopNegEx = false;
48-
volatile int exDelta = 0;
4945
volatile bool pos_feeding = false;
5046

5147
rmtStepper::State zstepper;

src/src/Stepper.h

-4
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,12 @@ extern volatile double targetToolRelPos;
3434
extern int use_limit;
3535
extern volatile int64_t calculated_stepper_pulses;
3636

37-
extern volatile bool jog_done;
3837
extern volatile int32_t jog_steps;
3938
extern volatile double jog_scaler;
4039
extern volatile uint16_t vel;
4140
extern volatile double stopPos;
4241
extern volatile double stopNeg;
4342
extern volatile bool useStops;
44-
extern volatile bool stopPosEx;
45-
extern volatile bool stopNegEx;
46-
extern volatile int exDelta;
4743
extern volatile bool pos_feeding;
4844

4945
extern int microsteps;

src/src/display.cpp

-111
Original file line numberDiff line numberDiff line change
@@ -4,115 +4,4 @@
44

55

66

7-
/* Gutted
8-
#include "display.h"
97

10-
#include <Wire.h>
11-
#include "SSD1306Wire.h"
12-
#include "neotimer.h"
13-
#include "state.h"
14-
#include "Machine.h"
15-
#include "Stepper.h"
16-
17-
18-
SSD1306Wire display(0x3c, 5, 4);
19-
Neotimer display_timer = Neotimer(500);
20-
21-
int display_mode = STARTUP;
22-
23-
24-
void clear(){
25-
display.clear();
26-
//display.flipScreenVertically();
27-
display.setTextAlignment(TEXT_ALIGN_LEFT);
28-
display.setFont(ArialMT_Plain_10);
29-
}
30-
// TODO: figure out best way to deal with different displays or using Serial.
31-
32-
void init_display(){
33-
//#ifdef USESSD1306
34-
// setup the display
35-
36-
display.init();
37-
delay(200);
38-
clear();
39-
40-
41-
//#endif
42-
43-
}
44-
45-
static String sp = String(" ");
46-
47-
48-
49-
50-
// this is the feed mode
51-
void do_startup_display(){
52-
53-
display.drawString(0,0,"Display gutted ") ;
54-
display.display();
55-
}
56-
57-
void do_ready_display(){
58-
display.drawString(0,0," Display gutted") ;
59-
display.display();
60-
}
61-
// this is the config mode
62-
void do_configure_display(){
63-
display.drawString(0,0, "config: ");
64-
display.display();
65-
}
66-
67-
68-
void do_debug_ready_display(){
69-
display.drawString(0,0,"Debug Jog" + String(vel));
70-
display.drawString(0,11," Left to jog 10mm");
71-
//display.drawString(0,21," back: middle " + String(step_delta) );
72-
display.drawString(0,31,"J:"+ String(jogging) + " JS: " + String(jog_done));
73-
display.drawString(0,41,"s: " +String(jog_steps));
74-
display.display();
75-
}
76-
77-
void do_status_display(){
78-
// Slave logging/feeding
79-
// this mode only moves slaved to spindle and with a direction button pressed
80-
display.drawString(0,0,"RPM:" + String(rpm) + " Rapid: " + String(rapids) );
81-
display.drawString(0,11, "Feed Pitch: " + String(pitch,2));
82-
display.drawString(0,21,"Pos: " + String(relativePosition)) ;
83-
display.drawString(0,31," Delta: " + String( (int32_t)delta ));
84-
display.display();
85-
}
86-
87-
void do_display(){
88-
89-
if(display_timer.repeat()){
90-
91-
92-
clear();
93-
switch (display_mode) {
94-
case STARTUP:
95-
do_startup_display();
96-
break;
97-
case CONFIGURE:
98-
do_configure_display();
99-
break;
100-
case DSTATUS:
101-
do_status_display();
102-
break;
103-
case READY:
104-
do_ready_display();
105-
break;
106-
case FEEDING:
107-
do_status_display();
108-
break;
109-
case DEBUG_READY:
110-
do_debug_ready_display();
111-
break;
112-
113-
}
114-
115-
}
116-
117-
}
118-
*/

src/src/web.cpp

+60-29
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ bool web = true;
2323
//TODO move the location of this into a platformio variable or something? Maybe the location of the file as a constant in config.h
2424
#include "../../wifisecret.h"
2525

26-
// json buffer
26+
// json docs
2727

2828
// config stateDoc
2929
StaticJsonDocument<600> stateDoc;
@@ -40,31 +40,34 @@ StaticJsonDocument<600> statusDoc;
4040
// Used to log to UI
4141
StaticJsonDocument<600> logDoc;
4242

43-
size_t len = 0;
43+
// buffer for msgpack
44+
char outBuffer[450];
45+
46+
4447

48+
size_t serialize_len = 0;
49+
50+
// stores websocket data from asyncWebServer that gets fed to arduinoJSON
4551
String wsData;
4652

53+
// sends updates (statusDoc) to UI every interval
4754
Neotimer update_timer = Neotimer(1000);
4855

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
5657
AsyncWebServer server(80);
5758
AsyncWebSocket ws("/els");
5859
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
6063
uint8_t statusCounter = 0;
6164

65+
// I htink this is sent from the UI and used to set the absolute target postion, in the Doc it is "ja"
6266
double jogAbs = 0;
6367

6468
void saveNvConfigDoc(){
6569
EepromStream eepromStream(0, 512);
6670
serializeJson(nvConfigDoc, eepromStream);
67-
//EEPROM.commit();
6871
eepromStream.flush();
6972
loadNvConfigDoc();
7073
}
@@ -89,6 +92,7 @@ void initNvConfigDoc(){
8992
9093
*/
9194
//nvConfigDoc[""] = ;
95+
9296
saveNvConfigDoc();
9397
}
9498

@@ -113,32 +117,60 @@ void loadNvConfigDoc(){
113117

114118

115119
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
117126
statusDoc["pmm"] = toolRelPosMM;
127+
// defined in util.h and helps UI figure out what to display
118128
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;
119133
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
121138
statusDoc["delta"] = delta;
122-
statusDoc["calcPos"] = calculated_stepper_pulses;
139+
// this doesn't appear to be used now, but...
123140
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
124143
statusDoc["targetPosMM"] = targetToolRelPosMM;
144+
// bool for constant run mode, TODO: bad name though
125145
statusDoc["feeding"] = feeding;
146+
// bools for sync movements, TODO: bad name
126147
statusDoc["jogging"] = jogging;
148+
// bool for rapid sync movement TODO: bad name
127149
statusDoc["rap"] = rapiding;
150+
// main bool to turn movement on/off
128151
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
132153
statusDoc["sp"] = stopPos;
154+
// the stop in the Z - direction
133155
statusDoc["sn"] = stopNeg;
156+
// for stats
157+
// TODO: move this to a debug doc
134158
statusDoc["c0"] = cpu0;
135159
statusDoc["c1"] = cpu1;
136-
statusDoc["xd"] = exDelta;
160+
// this is incremented every status update
137161
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
139166
statusDoc["fd"] = z_feeding_dir;
167+
// Wait for the spindle/ncoder "0" position
168+
// this acts like a thread dial
140169
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
141172
statusDoc["rpm"] = rpm;
173+
// this is the effective pulses, so 600 line encoder using full quad is 2400 CPR
142174
statusDoc["cpr"] = encoder.cpr;
143175
sendStatus();
144176
}
@@ -196,29 +228,29 @@ void setRunMode(int mode){
196228
}
197229

198230
void sendState(){
199-
len = serializeMsgPack(stateDoc, outBuffer);
231+
serialize_len = serializeMsgPack(stateDoc, outBuffer);
200232
Serial.print(" s ");
201-
ws.binaryAll(outBuffer,len);
233+
ws.binaryAll(outBuffer,serialize_len);
202234
}
203235

204236
void sendLogP(Log::Msg *msg){
205237
logDoc["msg"] = msg->buf;
206238
logDoc["level"] = (int)msg->level;
207239
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);
210242
}
211243

212244
void sendStatus(){
213-
len = serializeMsgPack(statusDoc, outBuffer);
214-
ws.binaryAll(outBuffer,len);
245+
serialize_len = serializeMsgPack(statusDoc, outBuffer);
246+
ws.binaryAll(outBuffer,serialize_len);
215247

216248
}
217249

218250
void sendNvConfigDoc(){
219251
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);
222254
}
223255

224256

@@ -325,8 +357,6 @@ void handleJog(){
325357
*/
326358
if(!pos_feeding){
327359
setStops();
328-
//Serial.print("updated targetToolRelPos");
329-
//Serial.println(targetToolRelPos);
330360
jogging = true;
331361
init_pos_feed();
332362
updateStatusDoc();
@@ -632,6 +662,7 @@ void init_ota(){
632662

633663
}
634664
void sendUpdates(){
665+
// called in main loop
635666
if(update_timer.repeat()){
636667
// only send state when it changes
637668
//updateStateDoc();

0 commit comments

Comments
 (0)