Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web server endpoints module interface #554

Merged
merged 16 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion uCNC/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ __NOTE__: Not all event hooks might be listed here. To find all available event
| cnc_dotasks | NULL | ENABLE_MAIN_LOOP_MODULES | Fires on the main loop running. Any repeating task should be hooked here |
| cnc_io_dotasks | NULL | ENABLE_MAIN_LOOP_MODULES | Fires on the main IO loop running. This is similar to cnc_dotasks, the main difference is that this task will run also during delays |
| cnc_stop | NULL | ENABLE_MAIN_LOOP_MODULES | Fires when a halt/stop condition is triggered |
| cnc_exec_cmd_error | NULL | ENABLE_MAIN_LOOP_MODULES | Fires when an invalid command is received |
| cnc_parse_cmd_error | NULL | ENABLE_MAIN_LOOP_MODULES | Fires when an invalid command is received |
| cnc_alarm | NULL | ENABLE_MAIN_LOOP_MODULES | Fires when an alarm is triggered |
| settings_change | settings_args_t* | ENABLE_SETTINGS_MODULES | Fires when a $ setting is changed. Arg is a pointer to a settings_args_t struct |
| settings_load | settings_args_t* | ENABLE_SETTINGS_MODULES | Fires when settings are loaded from memory. Arg is a pointer to a settings_args_t struct |
Expand Down
22 changes: 11 additions & 11 deletions uCNC/src/cnc.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ static bool cnc_check_interlocking(void);
static void cnc_exec_rt_commands(void);
static void cnc_io_dotasks(void);
static void cnc_reset(void);
static bool cnc_exec_cmd(void);
static void cnc_run_startup_blocks(void);

#ifdef ENABLE_MAIN_LOOP_MODULES
Expand Down Expand Up @@ -90,10 +89,10 @@ WEAK_EVENT_HANDLER(cnc_stop)
DEFAULT_EVENT_HANDLER(cnc_stop);
}

// event_cnc_exec_cmd_error_handler
WEAK_EVENT_HANDLER(cnc_exec_cmd_error)
// event_cnc_parse_cmd_error_handler
WEAK_EVENT_HANDLER(cnc_parse_cmd_error)
{
DEFAULT_EVENT_HANDLER(cnc_exec_cmd_error);
DEFAULT_EVENT_HANDLER(cnc_parse_cmd_error);
}

// event_cnc_alarm
Expand Down Expand Up @@ -138,7 +137,8 @@ void cnc_run(void)
cnc_state.loop_state = LOOP_RUNNING;
do
{
} while (cnc_exec_cmd());
cnc_parse_cmd();
} while (cnc_dotasks());

cnc_state.loop_state = LOOP_FAULT;
int8_t alarm = cnc_state.alarm;
Expand Down Expand Up @@ -174,15 +174,15 @@ void cnc_run(void)
} while (cnc_state.loop_state == LOOP_REQUIRE_RESET || cnc_get_exec_state(EXEC_KILL));
}

bool cnc_exec_cmd(void)
uint8_t cnc_parse_cmd(void)
{
#ifdef ENABLE_PARSING_TIME_DEBUG
uint32_t exec_time;
#endif
uint8_t error = 0;
// process gcode commands
if (serial_available())
{
uint8_t error = 0;
// protocol_echo();
uint8_t c = serial_peek();
switch (c)
Expand Down Expand Up @@ -220,12 +220,12 @@ bool cnc_exec_cmd(void)
parser_sync_position();
protocol_send_error(error);
#ifdef ENABLE_MAIN_LOOP_MODULES
EVENT_INVOKE(cnc_exec_cmd_error, &error);
EVENT_INVOKE(cnc_parse_cmd_error, &error);
#endif
}
}

return cnc_dotasks();
return error;
}

bool cnc_dotasks(void)
Expand Down Expand Up @@ -1053,13 +1053,13 @@ void cnc_run_startup_blocks(void)
if (settings_check_startup_gcode(STARTUP_BLOCK0_ADDRESS_OFFSET))
{
serial_stream_eeprom(STARTUP_BLOCK0_ADDRESS_OFFSET);
cnc_exec_cmd();
cnc_parse_cmd();
}

if (settings_check_startup_gcode(STARTUP_BLOCK1_ADDRESS_OFFSET))
{
serial_stream_eeprom(STARTUP_BLOCK1_ADDRESS_OFFSET);
cnc_exec_cmd();
cnc_parse_cmd();
}

// reset streams
Expand Down
5 changes: 3 additions & 2 deletions uCNC/src/cnc.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ extern "C"
void cnc_delay_ms(uint32_t miliseconds);
void cnc_store_motion(void);
void cnc_restore_motion(void);
uint8_t cnc_parse_cmd(void);

uint8_t cnc_get_exec_state(uint8_t statemask);
void cnc_set_exec_state(uint8_t statemask);
Expand All @@ -185,8 +186,8 @@ extern "C"
DECL_EVENT_HANDLER(cnc_io_dotasks);
// event_cnc_stop_handler
DECL_EVENT_HANDLER(cnc_stop);
// event_cnc_exec_cmd_error_handler
DECL_EVENT_HANDLER(cnc_exec_cmd_error);
// event_cnc_parse_cmd_error_handler
DECL_EVENT_HANDLER(cnc_parse_cmd_error);
// event_cnc_alarm
DECL_EVENT_HANDLER(cnc_alarm);
#endif
Expand Down
1 change: 1 addition & 0 deletions uCNC/src/hal/boards/esp32/esp32.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ board = esp32dev
build_flags = -mlongcalls -Wno-frame-address -ffunction-sections -fdata-sections -ggdb -Os -freorder-blocks -Wwrite-strings -fstack-protector -fstrict-volatile-bitfields -Wall -fno-jump-tables -fno-tree-switch-conversion -std=gnu++11 -fexceptions -MMD -c -DUSE_ARDUINO_EEPROM_LIBRARY -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE -DENABLE_WIFI -DENABLE_BLUETOOTH
board_build.f_flash = 80000000L
board_build.f_cpu = 240000000L
board_build.filesystem = littlefs
board_build.partitions = min_spiffs.csv
monitor_filters=esp32_exception_decoder
upload_speed = 921600
Expand Down
1 change: 1 addition & 0 deletions uCNC/src/hal/boards/esp8266/esp8266.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ board = d1
build_flags = -DBOARD=BOARD_WEMOS_D1 -DENABLE_WIFI
upload_speed = 256000
board_build.f_cpu = 160000000L
board_build.ldscript=eagle.flash.2m512.ld
2 changes: 1 addition & 1 deletion uCNC/src/hal/boards/rp2040/rp2040.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ platform_packages =
; board = pico
framework = arduino
board_build.core = earlephilhower
; board_build.filesystem_size = 0.5m
board_build.filesystem_size = 0.5m
; change microcontroller
board_build.mcu = rp2040
; change MCU frequency
Expand Down
Loading