Skip to content

Commit e51ae8c

Browse files
bdringMitchBradleymarcow1601
authored
Devt (#842)
* Oled2 (#834) * WIP * WIP * Update platformio.ini * WIP * Cleanup * Update platformio.ini * Turn off soft limits with max travel (#836) #831 * Yalang YL620 VFD (#838) * New SpindleType YL620 Files for new SpindleType Yalang 620. So far the contents are a duplicate of H2ASpindle.h and H2ASpindle.cpp * Added register documentation and implemented read and write data packets * Some fixes, mostly regarding RX packet length Co-authored-by: Mitch Bradley <[email protected]> Co-authored-by: marcosprojects <[email protected]>
1 parent eaffb96 commit e51ae8c

11 files changed

+621
-21
lines changed

Grbl_Esp32/Custom/oled_basic.cpp

Lines changed: 288 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,288 @@
1+
/*
2+
oled_basic.cpp
3+
Part of Grbl_ESP32
4+
5+
copyright (c) 2018 - Bart Dring This file was modified for use on the ESP32
6+
CPU. Do not use this with Grbl for atMega328P
7+
8+
Grbl is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU General Public License as published by
10+
the Free Software Foundation, either version 3 of the License, or
11+
(at your option) any later version.
12+
13+
Grbl is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Public License for more details.
17+
18+
You should have received a copy of the GNU General Public License
19+
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
20+
21+
--------------------------------------------------------------
22+
23+
This is a minimal implentation of a display as a test project.
24+
It is designed to be used with a machine that has no easily accessible serial connection
25+
It shows basic status and connection information.
26+
27+
When in alarm mode it will show the current Wifi/BT paramaters and status
28+
Most machines will start in alarm mode (needs homing)
29+
If the machine is running a job from SD it will show the progress
30+
In other modes it will show state and 3 axis DROs
31+
Thats All!
32+
33+
Library Infor:
34+
https://github.com/ThingPulse/esp8266-oled-ssd1306
35+
36+
Install to PlatformIO with this typed at the terminal
37+
platformio lib install 562
38+
39+
Add this to your machine definition file
40+
#define DISPLAY_CODE_FILENAME "Custom/oled_basic.cpp"
41+
42+
*/
43+
44+
// Include the correct display library
45+
46+
#include "SSD1306Wire.h" // legacy: #include "SSD1306.h"
47+
#include "../src/WebUI/WebSettings.h"
48+
49+
#ifndef OLED_ADDRESS
50+
# define OLED_ADDRESS 0x3c
51+
#endif
52+
53+
#ifndef OLED_SDA
54+
# define OLED_SDA GPIO_NUM_14
55+
#endif
56+
57+
#ifndef OLED_SCL
58+
# define OLED_SCL GPIO_NUM_13
59+
#endif
60+
61+
#ifndef OLED_GEOMETRY
62+
# define OLED_GEOMETRY GEOMETRY_128_64
63+
#endif
64+
65+
SSD1306Wire display(OLED_ADDRESS, OLED_SDA, OLED_SCL, OLED_GEOMETRY);
66+
67+
static TaskHandle_t displayUpdateTaskHandle = 0;
68+
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+
// This displays the status of the ESP32 Radios...BT, WiFi, etc
138+
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);
147+
148+
#ifdef ENABLE_BLUETOOTH
149+
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);
154+
}
155+
#endif
156+
#ifdef ENABLE_WIFI
157+
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+
//}
168+
} 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);
175+
}
176+
#endif
177+
178+
#ifdef WIFI_OR_BLUETOOTH
179+
if (WebUI::wifi_radio_mode->get() == ESP_RADIO_OFF) {
180+
display.drawString(0, row1, "Radio Mode: None");
181+
}
182+
#else
183+
display.drawString(0, row1, "Wifi and Bluetooth Disabled");
184+
#endif
185+
}
186+
187+
void displayDRO() {
188+
char axisVal[20];
189+
190+
display.setFont(ArialMT_Plain_16);
191+
display.setTextAlignment(TEXT_ALIGN_LEFT);
192+
display.drawString(0, 13, String('X') + ":");
193+
display.drawString(0, 30, "Y:");
194+
display.drawString(0, 47, "Z:");
195+
196+
display.setTextAlignment(TEXT_ALIGN_RIGHT);
197+
snprintf(axisVal, 20 - 1, "%.3f", getPosition(X_AXIS, true));
198+
display.drawString(100, 13, axisVal);
199+
200+
snprintf(axisVal, 20 - 1, "%.3f", getPosition(Y_AXIS, true));
201+
display.drawString(100, 30, axisVal);
202+
203+
snprintf(axisVal, 20 - 1, "%.3f", getPosition(Z_AXIS, true));
204+
display.drawString(100, 47, axisVal);
205+
}
206+
207+
void displayUpdate(void* pvParameters) {
208+
TickType_t xLastWakeTime;
209+
const TickType_t xDisplayFrequency = 100; // in ticks (typically ms)
210+
xLastWakeTime = xTaskGetTickCount(); // Initialise the xLastWakeTime variable with the current time.
211+
212+
vTaskDelay(2500);
213+
uint16_t sd_file_ticker = 0;
214+
215+
display.init();
216+
display.flipScreenVertically();
217+
218+
while (true) {
219+
display.clear();
220+
221+
String state_string = getStateText();
222+
223+
state_string.toUpperCase();
224+
225+
display.setTextAlignment(TEXT_ALIGN_LEFT);
226+
display.setFont(ArialMT_Plain_16);
227+
display.drawString(0, 0, state_string);
228+
229+
if (get_sd_state(false) == SDState::BusyPrinting) {
230+
display.clear();
231+
display.setTextAlignment(TEXT_ALIGN_LEFT);
232+
display.setFont(ArialMT_Plain_16);
233+
state_string = "SD File";
234+
for (int i = 0; i < sd_file_ticker % 10; i++) {
235+
state_string += ".";
236+
}
237+
sd_file_ticker++;
238+
display.drawString(25, 0, state_string);
239+
240+
int progress = sd_report_perc_complete();
241+
// draw the progress bar
242+
display.drawProgressBar(0, 45, 120, 10, progress);
243+
244+
// draw the percentage as String
245+
display.setFont(ArialMT_Plain_16);
246+
display.setTextAlignment(TEXT_ALIGN_CENTER);
247+
display.drawString(64, 25, String(progress) + "%");
248+
249+
} else if (sys.state == State::Alarm) {
250+
displayRadioInfo();
251+
} else {
252+
displayDRO();
253+
}
254+
display.display();
255+
256+
vTaskDelayUntil(&xLastWakeTime, xDisplayFrequency);
257+
}
258+
}
259+
260+
void display_init() {
261+
// Initialising the UI will init the display too.
262+
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Init Basic OLED SDA:%s SCL:%s", pinName(OLED_SDA), pinName(OLED_SCL));
263+
264+
display.init();
265+
display.flipScreenVertically();
266+
display.clear();
267+
display.setTextAlignment(TEXT_ALIGN_CENTER);
268+
display.setFont(ArialMT_Plain_16);
269+
270+
String mach_name = MACHINE_NAME;
271+
// remove characters from the end until the string fits
272+
while (display.getStringWidth(mach_name) > 128) {
273+
mach_name = mach_name.substring(0, mach_name.length() - 1);
274+
}
275+
276+
display.drawString(63, 0, mach_name);
277+
display.display();
278+
279+
xTaskCreatePinnedToCore(displayUpdate, // task
280+
"displayUpdateTask", // name for task
281+
4096, // size of task stack
282+
NULL, // parameters
283+
1, // priority
284+
&displayUpdateTaskHandle,
285+
CONFIG_ARDUINO_RUNNING_CORE // must run the task on same core
286+
// core
287+
);
288+
}

Grbl_Esp32/src/CustomCode.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@
66
#ifdef CUSTOM_CODE_FILENAME
77
# include CUSTOM_CODE_FILENAME
88
#endif
9+
10+
#ifdef DISPLAY_CODE_FILENAME
11+
# include DISPLAY_CODE_FILENAME
12+
#endif

Grbl_Esp32/src/Grbl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ void grbl_init() {
3131
WiFi.enableAP(false);
3232
WiFi.mode(WIFI_OFF);
3333
serial_init(); // Setup serial baud rate and interrupts
34+
display_init();
3435
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Grbl_ESP32 Ver %s Date %s", GRBL_VERSION, GRBL_VERSION_BUILD); // print grbl_esp32 verion info
3536
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Compiled with ESP32 SDK:%s", ESP.getSdkVersion()); // print the SDK version
3637
// show the map name at startup
@@ -116,6 +117,7 @@ void run_once() {
116117

117118
void __attribute__((weak)) machine_init() {}
118119

120+
void __attribute__((weak)) display_init() {}
119121
/*
120122
setup() and loop() in the Arduino .ino implements this control flow:
121123

Grbl_Esp32/src/Grbl.h

Lines changed: 5 additions & 3 deletions
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 = "20210311";
25+
const char* const GRBL_VERSION_BUILD = "20210320";
2626

2727
//#include <sdkconfig.h>
2828
#include <Arduino.h>
@@ -65,6 +65,8 @@ const char* const GRBL_VERSION_BUILD = "20210311";
6565

6666
#include "UserOutput.h"
6767

68+
#include <Wire.h>
69+
6870
// Do not guard this because it is needed for local files too
6971
#include "SDCard.h"
7072

@@ -90,8 +92,8 @@ const char* const GRBL_VERSION_BUILD = "20210311";
9092
void grbl_init();
9193
void run_once();
9294

93-
// Called if USE_MACHINE_INIT is defined
94-
void machine_init();
95+
void machine_init(); // weak definition in Grbl.cpp
96+
void display_init(); // weak definition in Grbl.cpp
9597

9698
bool user_defined_homing(uint8_t cycle_mask); // weak definition in Limits.cpp
9799

Grbl_Esp32/src/Limits.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,13 +392,14 @@ float limitsMinPosition(uint8_t axis) {
392392

393393
// Checks and reports if target array exceeds machine travel limits.
394394
// Return true if exceeding limits
395+
// Set $<axis>/MaxTravel=0 to selectively remove an axis from soft limit checks
395396
bool limitsCheckTravel(float* target) {
396397
uint8_t idx;
397398
auto n_axis = number_axis->get();
398399
for (idx = 0; idx < n_axis; idx++) {
399400
float max_mpos, min_mpos;
400401

401-
if (target[idx] < limitsMinPosition(idx) || target[idx] > limitsMaxPosition(idx)) {
402+
if ((target[idx] < limitsMinPosition(idx) || target[idx] > limitsMaxPosition(idx)) && axis_settings[idx]->max_travel->get() > 0) {
402403
return true;
403404
}
404405
}

Grbl_Esp32/src/SettingsDefinitions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ void make_settings() {
301301
}
302302
for (axis = MAX_N_AXIS - 1; axis >= 0; axis--) {
303303
def = &axis_defaults[axis];
304-
auto setting = new FloatSetting(GRBL, WG, makeGrblName(axis, 130), makename(def->name, "MaxTravel"), def->max_travel, 1.0, 100000.0);
304+
auto setting = new FloatSetting(GRBL, WG, makeGrblName(axis, 130), makename(def->name, "MaxTravel"), def->max_travel, 0, 100000.0);
305305
setting->setAxis(axis);
306306
axis_settings[axis]->max_travel = setting;
307307
}

Grbl_Esp32/src/Spindles/Spindle.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "H2ASpindle.h"
3939
#include "BESCSpindle.h"
4040
#include "10vSpindle.h"
41+
#include "YL620Spindle.h"
4142

4243
namespace Spindles {
4344
// An instance of each type of spindle is created here.
@@ -51,6 +52,7 @@ namespace Spindles {
5152
H2A h2a;
5253
BESC besc;
5354
_10v _10v;
55+
YL620 yl620;
5456

5557
void Spindle::select() {
5658
switch (static_cast<SpindleType>(spindle_type->get())) {
@@ -78,6 +80,9 @@ namespace Spindles {
7880
case SpindleType::H2A:
7981
spindle = &h2a;
8082
break;
83+
case SpindleType::YL620:
84+
spindle = &yl620;
85+
break;
8186
case SpindleType::NONE:
8287
default:
8388
spindle = &null;

0 commit comments

Comments
 (0)