mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-08-29 17:19:50 +02:00
User macro button (#685)
* Test Macro Button Idea * Updates * Formating
This commit is contained in:
@@ -50,9 +50,10 @@ Some features should not be changed. See notes below.
|
|||||||
|
|
||||||
// Inverts pin logic of the control command pins based on a mask. This essentially means you can use
|
// Inverts pin logic of the control command pins based on a mask. This essentially means you can use
|
||||||
// normally-closed switches on the specified pins, rather than the default normally-open switches.
|
// normally-closed switches on the specified pins, rather than the default normally-open switches.
|
||||||
// The mask order is Cycle Start | Feed Hold | Reset | Safety Door
|
// The mask order is ...
|
||||||
|
// Macro3 | Macro2 | Macro 1| Macr0 |Cycle Start | Feed Hold | Reset | Safety Door
|
||||||
// For example B1101 will invert the function of the Reset pin.
|
// For example B1101 will invert the function of the Reset pin.
|
||||||
#define INVERT_CONTROL_PIN_MASK B1111
|
#define INVERT_CONTROL_PIN_MASK B00001111
|
||||||
|
|
||||||
#define ENABLE_CONTROL_SW_DEBOUNCE // Default disabled. Uncomment to enable.
|
#define ENABLE_CONTROL_SW_DEBOUNCE // Default disabled. Uncomment to enable.
|
||||||
#define CONTROL_SW_DEBOUNCE_PERIOD 32 // in milliseconds default 32 microseconds
|
#define CONTROL_SW_DEBOUNCE_PERIOD 32 // in milliseconds default 32 microseconds
|
||||||
|
@@ -647,3 +647,19 @@
|
|||||||
#ifndef USER_ANALOG_PIN_3_FREQ
|
#ifndef USER_ANALOG_PIN_3_FREQ
|
||||||
# define USER_ANALOG_PIN_3_FREQ 5000
|
# define USER_ANALOG_PIN_3_FREQ 5000
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef DEFAULT_USER_MACRO0
|
||||||
|
# define DEFAULT_USER_MACRO0 ""
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef DEFAULT_USER_MACRO1
|
||||||
|
# define DEFAULT_USER_MACRO1 ""
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef DEFAULT_USER_MACRO2
|
||||||
|
# define DEFAULT_USER_MACRO2 ""
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef DEFAULT_USER_MACRO3
|
||||||
|
# define DEFAULT_USER_MACRO3 ""
|
||||||
|
#endif
|
@@ -8,7 +8,7 @@
|
|||||||
// !!! For initial testing, start with test_drive.h which disables
|
// !!! For initial testing, start with test_drive.h which disables
|
||||||
// all I/O pins
|
// all I/O pins
|
||||||
// #include "Machines/atari_1020.h"
|
// #include "Machines/atari_1020.h"
|
||||||
# include "Machines/test_drive.h"
|
# include "Machines/6_pack_stepstick_XYZ_v1.h"
|
||||||
|
|
||||||
// !!! For actual use, change the line above to select a board
|
// !!! For actual use, change the line above to select a board
|
||||||
// from Machines/, for example:
|
// from Machines/, for example:
|
||||||
|
@@ -106,11 +106,14 @@ Socket #5
|
|||||||
#define Z_LIMIT_PIN GPIO_NUM_35
|
#define Z_LIMIT_PIN GPIO_NUM_35
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// // 4x Input Module in Socket #2
|
// // 4x Input Module in Socket #2
|
||||||
// // https://github.com/bdring/6-Pack_CNC_Controller/wiki/4x-Switch-Input-module
|
// // https://github.com/bdring/6-Pack_CNC_Controller/wiki/4x-Switch-Input-module
|
||||||
// #define X_LIMIT_PIN GPIO_NUM_2
|
#define MACRO_BUTTON_0_PIN GPIO_NUM_2
|
||||||
// #define Y_LIMIT_PIN GPIO_NUM_25
|
#define MACRO_BUTTON_1_PIN GPIO_NUM_25
|
||||||
// #define Z_LIMIT_PIN GPIO_NUM_39
|
#define MACRO_BUTTON_2_PIN GPIO_NUM_39
|
||||||
|
#define MACRO_BUTTON_3_PIN GPIO_NUM_36
|
||||||
|
|
||||||
// 5V output CNC module in socket #4
|
// 5V output CNC module in socket #4
|
||||||
// https://github.com/bdring/6-Pack_CNC_Controller/wiki/4x-5V-Buffered-Output-Module
|
// https://github.com/bdring/6-Pack_CNC_Controller/wiki/4x-5V-Buffered-Output-Module
|
||||||
|
@@ -80,6 +80,11 @@ AxisSettings* c_axis_settings;
|
|||||||
|
|
||||||
AxisSettings* axis_settings[MAX_N_AXIS];
|
AxisSettings* axis_settings[MAX_N_AXIS];
|
||||||
|
|
||||||
|
StringSetting* user_macro0;
|
||||||
|
StringSetting* user_macro1;
|
||||||
|
StringSetting* user_macro2;
|
||||||
|
StringSetting* user_macro3;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char* name;
|
const char* name;
|
||||||
float steps_per_mm;
|
float steps_per_mm;
|
||||||
@@ -389,10 +394,15 @@ void make_settings() {
|
|||||||
|
|
||||||
stallguard_debug_mask = new AxisMaskSetting(EXTENDED, WG, NULL, "Report/StallGuard", 0, postTMC);
|
stallguard_debug_mask = new AxisMaskSetting(EXTENDED, WG, NULL, "Report/StallGuard", 0, postTMC);
|
||||||
|
|
||||||
homing_cycle[0] = new AxisMaskSetting(EXTENDED, WG, NULL, "Homing/Cycle0", DEFAULT_HOMING_CYCLE_0);
|
|
||||||
homing_cycle[1] = new AxisMaskSetting(EXTENDED, WG, NULL, "Homing/Cycle1", DEFAULT_HOMING_CYCLE_1);
|
|
||||||
homing_cycle[2] = new AxisMaskSetting(EXTENDED, WG, NULL, "Homing/Cycle2", DEFAULT_HOMING_CYCLE_2);
|
|
||||||
homing_cycle[3] = new AxisMaskSetting(EXTENDED, WG, NULL, "Homing/Cycle3", DEFAULT_HOMING_CYCLE_3);
|
|
||||||
homing_cycle[4] = new AxisMaskSetting(EXTENDED, WG, NULL, "Homing/Cycle4", DEFAULT_HOMING_CYCLE_4);
|
|
||||||
homing_cycle[5] = new AxisMaskSetting(EXTENDED, WG, NULL, "Homing/Cycle5", DEFAULT_HOMING_CYCLE_5);
|
homing_cycle[5] = new AxisMaskSetting(EXTENDED, WG, NULL, "Homing/Cycle5", DEFAULT_HOMING_CYCLE_5);
|
||||||
|
homing_cycle[4] = new AxisMaskSetting(EXTENDED, WG, NULL, "Homing/Cycle4", DEFAULT_HOMING_CYCLE_4);
|
||||||
|
homing_cycle[3] = new AxisMaskSetting(EXTENDED, WG, NULL, "Homing/Cycle3", DEFAULT_HOMING_CYCLE_3);
|
||||||
|
homing_cycle[2] = new AxisMaskSetting(EXTENDED, WG, NULL, "Homing/Cycle2", DEFAULT_HOMING_CYCLE_2);
|
||||||
|
homing_cycle[1] = new AxisMaskSetting(EXTENDED, WG, NULL, "Homing/Cycle1", DEFAULT_HOMING_CYCLE_1);
|
||||||
|
homing_cycle[0] = new AxisMaskSetting(EXTENDED, WG, NULL, "Homing/Cycle0", DEFAULT_HOMING_CYCLE_0);
|
||||||
|
|
||||||
|
user_macro3 = new StringSetting(EXTENDED, WG, NULL, "User/Macro3", DEFAULT_USER_MACRO3);
|
||||||
|
user_macro2 = new StringSetting(EXTENDED, WG, NULL, "User/Macro2", DEFAULT_USER_MACRO2);
|
||||||
|
user_macro1 = new StringSetting(EXTENDED, WG, NULL, "User/Macro1", DEFAULT_USER_MACRO1);
|
||||||
|
user_macro0 = new StringSetting(EXTENDED, WG, NULL, "User/Macro0", DEFAULT_USER_MACRO0);
|
||||||
}
|
}
|
||||||
|
@@ -60,3 +60,8 @@ extern IntSetting* spindle_pwm_bit_precision;
|
|||||||
extern EnumSetting* spindle_type;
|
extern EnumSetting* spindle_type;
|
||||||
|
|
||||||
extern AxisMaskSetting* stallguard_debug_mask;
|
extern AxisMaskSetting* stallguard_debug_mask;
|
||||||
|
|
||||||
|
extern StringSetting* user_macro0;
|
||||||
|
extern StringSetting* user_macro1;
|
||||||
|
extern StringSetting* user_macro2;
|
||||||
|
extern StringSetting* user_macro3;
|
||||||
|
@@ -63,22 +63,22 @@ void system_ini() { // Renamed from system_init() due to conflict with esp32 fi
|
|||||||
attachInterrupt(digitalPinToInterrupt(CONTROL_CYCLE_START_PIN), isr_control_inputs, CHANGE);
|
attachInterrupt(digitalPinToInterrupt(CONTROL_CYCLE_START_PIN), isr_control_inputs, CHANGE);
|
||||||
#endif
|
#endif
|
||||||
#ifdef MACRO_BUTTON_0_PIN
|
#ifdef MACRO_BUTTON_0_PIN
|
||||||
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Macro Pin 0");
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Macro Pin 0 %s", pinName(MACRO_BUTTON_0_PIN).c_str());
|
||||||
pinMode(MACRO_BUTTON_0_PIN, INPUT_PULLUP);
|
pinMode(MACRO_BUTTON_0_PIN, INPUT_PULLUP);
|
||||||
attachInterrupt(digitalPinToInterrupt(MACRO_BUTTON_0_PIN), isr_control_inputs, CHANGE);
|
attachInterrupt(digitalPinToInterrupt(MACRO_BUTTON_0_PIN), isr_control_inputs, CHANGE);
|
||||||
#endif
|
#endif
|
||||||
#ifdef MACRO_BUTTON_1_PIN
|
#ifdef MACRO_BUTTON_1_PIN
|
||||||
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Macro Pin 1");
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Macro Pin 1 %s", pinName(MACRO_BUTTON_1_PIN).c_str());
|
||||||
pinMode(MACRO_BUTTON_1_PIN, INPUT_PULLUP);
|
pinMode(MACRO_BUTTON_1_PIN, INPUT_PULLUP);
|
||||||
attachInterrupt(digitalPinToInterrupt(MACRO_BUTTON_1_PIN), isr_control_inputs, CHANGE);
|
attachInterrupt(digitalPinToInterrupt(MACRO_BUTTON_1_PIN), isr_control_inputs, CHANGE);
|
||||||
#endif
|
#endif
|
||||||
#ifdef MACRO_BUTTON_2_PIN
|
#ifdef MACRO_BUTTON_2_PIN
|
||||||
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Macro Pin 2");
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Macro Pin 2 %s", pinName(MACRO_BUTTON_2_PIN).c_str());
|
||||||
pinMode(MACRO_BUTTON_2_PIN, INPUT_PULLUP);
|
pinMode(MACRO_BUTTON_2_PIN, INPUT_PULLUP);
|
||||||
attachInterrupt(digitalPinToInterrupt(MACRO_BUTTON_2_PIN), isr_control_inputs, CHANGE);
|
attachInterrupt(digitalPinToInterrupt(MACRO_BUTTON_2_PIN), isr_control_inputs, CHANGE);
|
||||||
#endif
|
#endif
|
||||||
#ifdef MACRO_BUTTON_3_PIN
|
#ifdef MACRO_BUTTON_3_PIN
|
||||||
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Macro Pin 3");
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Macro Pin 3 %s", pinName(MACRO_BUTTON_3_PIN).c_str());
|
||||||
pinMode(MACRO_BUTTON_3_PIN, INPUT_PULLUP);
|
pinMode(MACRO_BUTTON_3_PIN, INPUT_PULLUP);
|
||||||
attachInterrupt(digitalPinToInterrupt(MACRO_BUTTON_3_PIN), isr_control_inputs, CHANGE);
|
attachInterrupt(digitalPinToInterrupt(MACRO_BUTTON_3_PIN), isr_control_inputs, CHANGE);
|
||||||
#endif
|
#endif
|
||||||
@@ -87,7 +87,7 @@ void system_ini() { // Renamed from system_init() due to conflict with esp32 fi
|
|||||||
control_sw_queue = xQueueCreate(10, sizeof(int));
|
control_sw_queue = xQueueCreate(10, sizeof(int));
|
||||||
xTaskCreate(controlCheckTask,
|
xTaskCreate(controlCheckTask,
|
||||||
"controlCheckTask",
|
"controlCheckTask",
|
||||||
2048,
|
3096,
|
||||||
NULL,
|
NULL,
|
||||||
5, // priority
|
5, // priority
|
||||||
NULL);
|
NULL);
|
||||||
@@ -332,4 +332,39 @@ uint8_t sys_calc_pwm_precision(uint32_t freq) {
|
|||||||
|
|
||||||
return precision - 1;
|
return precision - 1;
|
||||||
}
|
}
|
||||||
void __attribute__((weak)) user_defined_macro(uint8_t index);
|
void __attribute__((weak)) user_defined_macro(uint8_t index) {
|
||||||
|
// must be in Idle
|
||||||
|
if (sys.state != State::Idle) {
|
||||||
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Macro button only permitted in idle");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String user_macro;
|
||||||
|
char line[255];
|
||||||
|
switch (index) {
|
||||||
|
case 0:
|
||||||
|
user_macro = user_macro0->get();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
user_macro = user_macro1->get();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
user_macro = user_macro2->get();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
user_macro = user_macro3->get();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user_macro == "") {
|
||||||
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Macro User/Macro%d empty", index);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
user_macro.replace('&', '\n');
|
||||||
|
user_macro.toCharArray(line, 255, 0);
|
||||||
|
strcat(line, "\r");
|
||||||
|
WebUI::inputBuffer.push(line);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user