38
38
39
39
Add this to your machine definition file
40
40
#define DISPLAY_CODE_FILENAME "Custom/oled_basic.cpp"
41
-
42
41
*/
43
42
44
43
// Include the correct display library
45
44
46
- #include " SSD1306Wire.h" // legacy: #include "SSD1306.h"
45
+ #include " SSD1306Wire.h"
47
46
#include " ../src/WebUI/WebSettings.h"
48
47
49
48
#ifndef OLED_ADDRESS
@@ -66,142 +65,129 @@ SSD1306Wire display(OLED_ADDRESS, OLED_SDA, OLED_SCL, OLED_GEOMETRY);
66
65
67
66
static TaskHandle_t displayUpdateTaskHandle = 0 ;
68
67
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
-
137
68
// This displays the status of the ESP32 Radios...BT, WiFi, etc
138
69
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 = " " ;
147
73
148
74
#ifdef ENABLE_BLUETOOTH
149
75
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 ();
154
77
}
155
78
#endif
156
79
#ifdef ENABLE_WIFI
157
80
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 ();
168
83
} 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 ();
175
86
}
176
87
#endif
177
88
178
89
#ifdef WIFI_OR_BLUETOOTH
179
90
if (WebUI::wifi_radio_mode->get () == ESP_RADIO_OFF) {
180
- display. drawString ( 0 , row1, " Radio Mode: None" ) ;
91
+ radio_name = " Radio Mode: None" ;
181
92
}
182
93
#else
183
- display. drawString ( 0 , row1, " Wifi and Bluetooth Disabled" ) ;
94
+ radio_name = " Radio Mode: Disabled" ;
184
95
#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
185
119
}
186
120
187
121
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];
189
125
190
- display.setFont (ArialMT_Plain_16);
191
126
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);
195
128
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
+ }
199
143
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 );
202
146
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
205
191
}
206
192
207
193
void displayUpdate (void * pvParameters) {
@@ -218,39 +204,43 @@ void displayUpdate(void* pvParameters) {
218
204
while (true ) {
219
205
display.clear ();
220
206
221
- String state_string = getStateText ();
222
-
223
- state_string.toUpperCase ();
207
+ String state_string = " " ;
224
208
225
209
display.setTextAlignment (TEXT_ALIGN_LEFT);
226
210
display.setFont (ArialMT_Plain_16);
227
- display.drawString (0 , 0 , state_string );
211
+ display.drawString (0 , 0 , report_state_text () );
228
212
229
213
if (get_sd_state (false ) == SDState::BusyPrinting) {
230
214
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 );
233
217
state_string = " SD File" ;
234
218
for (int i = 0 ; i < sd_file_ticker % 10 ; i++) {
235
219
state_string += " ." ;
236
220
}
237
221
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);
239
227
240
228
int progress = sd_report_perc_complete ();
241
229
// draw the progress bar
242
230
display.drawProgressBar (0 , 45 , 120 , 10 , progress);
243
231
244
232
// draw the percentage as String
245
- display.setFont (ArialMT_Plain_16 );
233
+ display.setFont (ArialMT_Plain_10 );
246
234
display.setTextAlignment (TEXT_ALIGN_CENTER);
247
235
display.drawString (64 , 25 , String (progress) + " %" );
248
236
249
237
} else if (sys.state == State::Alarm) {
250
238
displayRadioInfo ();
251
239
} else {
252
240
displayDRO ();
241
+ displayRadioInfo ();
253
242
}
243
+
254
244
display.display ();
255
245
256
246
vTaskDelayUntil (&xLastWakeTime, xDisplayFrequency);
@@ -260,20 +250,22 @@ void displayUpdate(void* pvParameters) {
260
250
void display_init () {
261
251
// Initialising the UI will init the display too.
262
252
grbl_msg_sendf (CLIENT_SERIAL, MsgLevel::Info, " Init Basic OLED SDA:%s SCL:%s" , pinName (OLED_SDA), pinName (OLED_SCL));
263
-
264
253
display.init ();
254
+
265
255
display.flipScreenVertically ();
256
+
266
257
display.clear ();
258
+
267
259
display.setTextAlignment (TEXT_ALIGN_CENTER);
268
- display.setFont (ArialMT_Plain_16 );
260
+ display.setFont (ArialMT_Plain_10 );
269
261
270
262
String mach_name = MACHINE_NAME;
271
263
// remove characters from the end until the string fits
272
264
while (display.getStringWidth (mach_name) > 128 ) {
273
265
mach_name = mach_name.substring (0 , mach_name.length () - 1 );
274
266
}
275
-
276
267
display.drawString (63 , 0 , mach_name);
268
+
277
269
display.display ();
278
270
279
271
xTaskCreatePinnedToCore (displayUpdate, // task
0 commit comments