Skip to content

Commit 90ca0ac

Browse files
authored
OLED and Other Updates (#844)
* publish * Updates - CoreXY and OLED - Moved position calculation out of report_realtime_status(...) so other functions can access it. - Added a function to check if a limit switch is defined - CoreXY fixed bug in forward kinematics when midtbot is used. - Modified OLED display. * Cleanup for PR * Delete midtbot_x2.h * Incorporated PR 846 - Some OLED cleanup - verified correct forward kinematics on MidTbot
1 parent e8cf0bb commit 90ca0ac

File tree

9 files changed

+247
-190
lines changed

9 files changed

+247
-190
lines changed

Grbl_Esp32/Custom/CoreXY.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ void forward_kinematics(float* position) {
314314
// apply the forward kinemetics to the machine coordinates
315315
// https://corexy.com/theory.html
316316
//calc_fwd[X_AXIS] = 0.5 / geometry_factor * (position[X_AXIS] + position[Y_AXIS]);
317-
calc_fwd[X_AXIS] = ((0.5 * (print_position[X_AXIS] + print_position[Y_AXIS]) * geometry_factor) - wco[X_AXIS]);
317+
calc_fwd[X_AXIS] = ((0.5 * (print_position[X_AXIS] + print_position[Y_AXIS]) / geometry_factor) - wco[X_AXIS]);
318318
calc_fwd[Y_AXIS] = ((0.5 * (print_position[X_AXIS] - print_position[Y_AXIS])) - wco[Y_AXIS]);
319319

320320
for (int axis = 0; axis < n_axis; axis++) {

Grbl_Esp32/Custom/oled_basic.cpp

Lines changed: 115 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@
3838
3939
Add this to your machine definition file
4040
#define DISPLAY_CODE_FILENAME "Custom/oled_basic.cpp"
41-
4241
*/
4342

4443
// Include the correct display library
4544

46-
#include "SSD1306Wire.h" // legacy: #include "SSD1306.h"
45+
#include "SSD1306Wire.h"
4746
#include "../src/WebUI/WebSettings.h"
4847

4948
#ifndef OLED_ADDRESS
@@ -66,142 +65,129 @@ SSD1306Wire display(OLED_ADDRESS, OLED_SDA, OLED_SCL, OLED_GEOMETRY);
6665

6766
static TaskHandle_t displayUpdateTaskHandle = 0;
6867

69-
// returns the position of a machine axis
70-
// wpos =true for corrected work postion
71-
float getPosition(uint8_t axis, bool wpos = true) {
72-
float wco; // work coordinate system offset
73-
74-
float current_position = sys_position[axis] / axis_settings[axis]->steps_per_mm->get();
75-
76-
if (wpos) {
77-
// Apply work coordinate offsets and tool length offset to current position.
78-
wco = gc_state.coord_system[axis] + gc_state.coord_offset[axis];
79-
if (axis == TOOL_LENGTH_OFFSET_AXIS) {
80-
wco += gc_state.tool_length_offset;
81-
}
82-
83-
current_position -= wco;
84-
}
85-
return current_position;
86-
}
87-
88-
String getStateText() {
89-
String str = "";
90-
91-
switch (sys.state) {
92-
case State::Idle:
93-
str = "Idle";
94-
break;
95-
case State::Cycle:
96-
str = "Run";
97-
break;
98-
case State::Hold:
99-
if (!(sys.suspend.bit.jogCancel)) {
100-
str = "Hold:";
101-
sys.suspend.bit.holdComplete ? str += "0" : str += "1"; // Ready to resume
102-
break;
103-
} // Continues to print jog state during jog cancel.
104-
case State::Jog:
105-
str = "Jog";
106-
break;
107-
case State::Homing:
108-
str = "Homing";
109-
break;
110-
case State::Alarm:
111-
str = "Alarm";
112-
break;
113-
case State::CheckMode:
114-
str = "Check";
115-
break;
116-
case State::SafetyDoor:
117-
str = "Door:";
118-
if (sys.suspend.bit.initiateRestore) {
119-
str += "3"; // Restoring
120-
} else {
121-
if (sys.suspend.bit.retractComplete) {
122-
sys.suspend.bit.safetyDoorAjar ? str += "1" : str += "0"; // Door ajar
123-
// Door closed and ready to resume
124-
} else {
125-
str += "2"; // Retracting
126-
}
127-
}
128-
break;
129-
case State::Sleep:
130-
str = "Sleep";
131-
break;
132-
}
133-
134-
return str;
135-
}
136-
13768
// This displays the status of the ESP32 Radios...BT, WiFi, etc
13869
void displayRadioInfo() {
139-
String radio_info = "";
140-
141-
const uint8_t row1 = 18;
142-
const uint8_t row2 = 30;
143-
const uint8_t row3 = 42;
144-
145-
display.setTextAlignment(TEXT_ALIGN_LEFT);
146-
display.setFont(ArialMT_Plain_10);
70+
String radio_addr = "";
71+
String radio_name = "";
72+
String radio_status = "";
14773

14874
#ifdef ENABLE_BLUETOOTH
14975
if (WebUI::wifi_radio_mode->get() == ESP_BT) {
150-
radio_info = String("Bluetooth: ") + WebUI::bt_name->get();
151-
display.drawString(0, row1, radio_info);
152-
radio_info = String("Status: ") + String(WebUI::SerialBT.hasClient() ? "Connected" : "Not connected");
153-
display.drawString(0, row2, radio_info);
76+
radio_name = String("BT: ") + WebUI::bt_name->get();
15477
}
15578
#endif
15679
#ifdef ENABLE_WIFI
15780
if ((WiFi.getMode() == WIFI_MODE_STA) || (WiFi.getMode() == WIFI_MODE_APSTA)) {
158-
radio_info = "STA SSID: " + WiFi.SSID();
159-
display.drawString(0, row1, radio_info);
160-
161-
radio_info = "IP: " + WiFi.localIP().toString();
162-
display.drawString(0, row2, radio_info);
163-
164-
radio_info = "Status: ";
165-
(WiFi.status() == WL_CONNECTED) ? radio_info += "Connected" : radio_info += "Not connected";
166-
display.drawString(0, row3, radio_info);
167-
//}
81+
radio_name = "STA: " + WiFi.SSID();
82+
radio_addr = WiFi.localIP().toString();
16883
} else if ((WiFi.getMode() == WIFI_MODE_AP) || (WiFi.getMode() == WIFI_MODE_APSTA)) {
169-
radio_info = String("AP SSID: ") + WebUI::wifi_ap_ssid->get();
170-
171-
display.drawString(0, row1, radio_info);
172-
173-
radio_info = "IP: " + WiFi.softAPIP().toString();
174-
display.drawString(0, row2, radio_info);
84+
radio_name = String("AP:") + WebUI::wifi_ap_ssid->get();
85+
radio_addr = WiFi.softAPIP().toString();
17586
}
17687
#endif
17788

17889
#ifdef WIFI_OR_BLUETOOTH
17990
if (WebUI::wifi_radio_mode->get() == ESP_RADIO_OFF) {
180-
display.drawString(0, row1, "Radio Mode: None");
91+
radio_name = "Radio Mode: None";
18192
}
18293
#else
183-
display.drawString(0, row1, "Wifi and Bluetooth Disabled");
94+
radio_name = "Radio Mode:Disabled";
18495
#endif
96+
97+
display.setTextAlignment(TEXT_ALIGN_LEFT);
98+
display.setFont(ArialMT_Plain_10);
99+
100+
if (sys.state == State::Alarm) { // print below Alarm:
101+
display.drawString(0, 18, radio_name);
102+
display.drawString(0, 30, radio_addr);
103+
104+
} else { // print next to status
105+
if (WebUI::wifi_radio_mode->get() == ESP_BT) {
106+
display.drawString(55, 2, radio_name);
107+
} else {
108+
display.drawString(55, 2, radio_addr);
109+
}
110+
}
111+
}
112+
// Here changes begin Here changes begin Here changes begin Here changes begin Here changes begin
113+
114+
void draw_checkbox(int16_t x, int16_t y, int16_t width, int16_t height, bool checked) {
115+
if (checked)
116+
display.fillRect(x, y, width, height); // If log.0
117+
else
118+
display.drawRect(x, y, width, height); // If log.1
185119
}
186120

187121
void displayDRO() {
188-
char axisVal[20];
122+
uint8_t oled_y_pos;
123+
float print_position[MAX_N_AXIS];
124+
//float wco[MAX_N_AXIS];
189125

190-
display.setFont(ArialMT_Plain_16);
191126
display.setTextAlignment(TEXT_ALIGN_LEFT);
192-
display.drawString(0, 13, String('X') + ":");
193-
display.drawString(0, 30, "Y:");
194-
display.drawString(0, 47, "Z:");
127+
display.setFont(ArialMT_Plain_10);
195128

196-
display.setTextAlignment(TEXT_ALIGN_RIGHT);
197-
snprintf(axisVal, 20 - 1, "%.3f", getPosition(X_AXIS, true));
198-
display.drawString(100, 13, axisVal);
129+
char axisVal[20];
130+
131+
display.drawString(80, 14, "L"); // Limit switch
132+
133+
auto n_axis = number_axis->get();
134+
AxisMask lim_pin_state = limits_get_state();
135+
ControlPins ctrl_pin_state = system_control_get_state();
136+
bool prb_pin_state = probe_get_state();
137+
138+
if (bit_istrue(status_mask->get(), RtStatus::Position)) {
139+
calc_mpos(print_position);
140+
} else {
141+
calc_wpos(print_position);
142+
}
199143

200-
snprintf(axisVal, 20 - 1, "%.3f", getPosition(Y_AXIS, true));
201-
display.drawString(100, 30, axisVal);
144+
for (uint8_t axis = X_AXIS; axis < n_axis; axis++) {
145+
oled_y_pos = 24 + (axis * 10);
202146

203-
snprintf(axisVal, 20 - 1, "%.3f", getPosition(Z_AXIS, true));
204-
display.drawString(100, 47, axisVal);
147+
String axis_letter = String(report_get_axis_letter(axis));
148+
axis_letter += ":";
149+
display.setTextAlignment(TEXT_ALIGN_LEFT);
150+
display.drawString(0, oled_y_pos, axis_letter); // String('X') + ":");
151+
152+
display.setTextAlignment(TEXT_ALIGN_RIGHT);
153+
snprintf(axisVal, 20 - 1, "%.3f", print_position[axis]);
154+
display.drawString(60, oled_y_pos, axisVal);
155+
156+
if (limitsSwitchDefined(axis, 0)) { // olny draw the box if a switch has been defined
157+
draw_checkbox(80, 27 + (axis * 10), 7, 7, bit_istrue(lim_pin_state, bit(axis)));
158+
}
159+
}
160+
161+
oled_y_pos = 14;
162+
163+
if (PROBE_PIN != UNDEFINED_PIN) {
164+
display.drawString(110, oled_y_pos, "P");
165+
draw_checkbox(120, oled_y_pos + 3, 7, 7, prb_pin_state);
166+
oled_y_pos += 10;
167+
}
168+
169+
#ifdef CONTROL_FEED_HOLD_PIN
170+
display.drawString(110, oled_y_pos, "H");
171+
draw_checkbox(120, oled_y_pos + 3, 7, 7, ctrl_pin_state.bit.feedHold);
172+
oled_y_pos += 10;
173+
#endif
174+
175+
#ifdef CONTROL_CYCLE_START_PIN
176+
display.drawString(110, oled_y_pos, "S");
177+
draw_checkbox(120, oled_y_pos + 3, 7, 7, ctrl_pin_state.bit.cycleStart);
178+
oled_y_pos += 10;
179+
#endif
180+
181+
#ifdef CONTROL_RESET_PIN
182+
display.drawString(110, oled_y_pos, "R");
183+
draw_checkbox(120, oled_y_pos + 3, 7, 7, ctrl_pin_state.bit.reset);
184+
oled_y_pos += 10;
185+
#endif
186+
187+
#ifdef CONTROL_SAFETY_DOOR_PIN
188+
display.drawString(110, oled_y_pos, "D");
189+
draw_checkbox(120, oled_y_pos + 3, 7, 7, ctrl_pin_state.bit.safetyDoor);
190+
#endif
205191
}
206192

207193
void displayUpdate(void* pvParameters) {
@@ -218,39 +204,43 @@ void displayUpdate(void* pvParameters) {
218204
while (true) {
219205
display.clear();
220206

221-
String state_string = getStateText();
222-
223-
state_string.toUpperCase();
207+
String state_string = "";
224208

225209
display.setTextAlignment(TEXT_ALIGN_LEFT);
226210
display.setFont(ArialMT_Plain_16);
227-
display.drawString(0, 0, state_string);
211+
display.drawString(0, 0, report_state_text());
228212

229213
if (get_sd_state(false) == SDState::BusyPrinting) {
230214
display.clear();
231-
display.setTextAlignment(TEXT_ALIGN_LEFT);
232-
display.setFont(ArialMT_Plain_16);
215+
display.setTextAlignment(TEXT_ALIGN_CENTER);
216+
display.setFont(ArialMT_Plain_10);
233217
state_string = "SD File";
234218
for (int i = 0; i < sd_file_ticker % 10; i++) {
235219
state_string += ".";
236220
}
237221
sd_file_ticker++;
238-
display.drawString(25, 0, state_string);
222+
display.drawString(63, 0, state_string);
223+
224+
char path[50];
225+
sd_get_current_filename(path);
226+
display.drawString(63, 12, path);
239227

240228
int progress = sd_report_perc_complete();
241229
// draw the progress bar
242230
display.drawProgressBar(0, 45, 120, 10, progress);
243231

244232
// draw the percentage as String
245-
display.setFont(ArialMT_Plain_16);
233+
display.setFont(ArialMT_Plain_10);
246234
display.setTextAlignment(TEXT_ALIGN_CENTER);
247235
display.drawString(64, 25, String(progress) + "%");
248236

249237
} else if (sys.state == State::Alarm) {
250238
displayRadioInfo();
251239
} else {
252240
displayDRO();
241+
displayRadioInfo();
253242
}
243+
254244
display.display();
255245

256246
vTaskDelayUntil(&xLastWakeTime, xDisplayFrequency);
@@ -260,20 +250,22 @@ void displayUpdate(void* pvParameters) {
260250
void display_init() {
261251
// Initialising the UI will init the display too.
262252
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Init Basic OLED SDA:%s SCL:%s", pinName(OLED_SDA), pinName(OLED_SCL));
263-
264253
display.init();
254+
265255
display.flipScreenVertically();
256+
266257
display.clear();
258+
267259
display.setTextAlignment(TEXT_ALIGN_CENTER);
268-
display.setFont(ArialMT_Plain_16);
260+
display.setFont(ArialMT_Plain_10);
269261

270262
String mach_name = MACHINE_NAME;
271263
// remove characters from the end until the string fits
272264
while (display.getStringWidth(mach_name) > 128) {
273265
mach_name = mach_name.substring(0, mach_name.length() - 1);
274266
}
275-
276267
display.drawString(63, 0, mach_name);
268+
277269
display.display();
278270

279271
xTaskCreatePinnedToCore(displayUpdate, // task
File renamed without changes.
File renamed without changes.

Grbl_Esp32/src/Grbl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
// Grbl versioning system
2424
const char* const GRBL_VERSION = "1.3a";
25-
const char* const GRBL_VERSION_BUILD = "20210320";
25+
const char* const GRBL_VERSION_BUILD = "20210329";
2626

2727
//#include <sdkconfig.h>
2828
#include <Arduino.h>

Grbl_Esp32/src/Limits.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,10 @@ bool limitsCheckTravel(float* target) {
406406
return false;
407407
}
408408

409+
bool limitsSwitchDefined(uint8_t axis, uint8_t gang_index) {
410+
return (limit_pins[axis][gang_index] != UNDEFINED_PIN);
411+
}
412+
409413
bool __attribute__((weak)) user_defined_homing(uint8_t cycle_mask) {
410414
return false;
411415
}

Grbl_Esp32/src/Limits.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ float limitsMinPosition(uint8_t axis);
5454

5555
// Internal factor used by limits_soft_check
5656
bool limitsCheckTravel(float* target);
57+
58+
// check if a switch has been defined
59+
bool limitsSwitchDefined(uint8_t axis, uint8_t gang_index);

0 commit comments

Comments
 (0)