Initial commit
First and incomplete version of the refactor, stage module works, including aborting moves.
This commit is contained in:
commit
2f78522064
16 changed files with 1264 additions and 0 deletions
131
src/main.cpp
Normal file
131
src/main.cpp
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
/*
|
||||
* Sangaboard firmware
|
||||
*
|
||||
* Refactored from bath_open_instrumentation_group/sangaboard/arduino_code
|
||||
*
|
||||
* This firmware was written by
|
||||
* Richard Bowman
|
||||
* Julian Stirling
|
||||
* Boyko Vodenicharski
|
||||
* Filip Ayazi
|
||||
*
|
||||
* Much of the code is based on older code written by
|
||||
* James Sharkey and Fergus Riche
|
||||
*
|
||||
* Released under GPL v3, 2021
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <stdint.h>
|
||||
#include "config.h"
|
||||
#include "main.h"
|
||||
|
||||
#ifdef HELP
|
||||
#include "modules/help/help.h"
|
||||
#endif
|
||||
|
||||
#ifdef STAGE
|
||||
#include "modules/stage/stage.h"
|
||||
#endif
|
||||
|
||||
Command registered_commands[MAX_COMMANDS];
|
||||
void (*registered_loop_functions[MAX_MODULES])(void);
|
||||
|
||||
uint16_t registered_commands_count = 0;
|
||||
uint8_t registered_loop_fn_count = 0;
|
||||
|
||||
const Command core_commands[] = {
|
||||
{"version", get_version},
|
||||
END_COMMAND};
|
||||
|
||||
void register_module(const Command commands[], void (*loop_fn)(void))
|
||||
{
|
||||
for (int i = 0; CHECK_END_COMMAND(commands[i]); i++)
|
||||
registered_commands[registered_commands_count++] = commands[i];
|
||||
|
||||
if (loop_fn)
|
||||
registered_loop_functions[registered_loop_fn_count++] = loop_fn;
|
||||
}
|
||||
|
||||
void handle_command(String received_command)
|
||||
{
|
||||
for (int i = 0; CHECK_END_COMMAND(registered_commands[i]); i++)
|
||||
{
|
||||
if (received_command.startsWith(registered_commands[i].command))
|
||||
return registered_commands[i].run(received_command.substring(registered_commands[i].command.length()));
|
||||
}
|
||||
|
||||
#ifdef HELP
|
||||
Serial.println(F("Type 'help' for a list of commands."));
|
||||
#else
|
||||
Serial.println(F("Invalid command"));
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8_t parse_arguments(String arguments[], String command, uint8_t max_args)
|
||||
{
|
||||
uint8_t from = 0;
|
||||
uint8_t parsed = 0;
|
||||
while (from < command.length() && parsed < max_args)
|
||||
{
|
||||
int space = command.indexOf(" ", from + 1);
|
||||
if (space == -1)
|
||||
space = command.length();
|
||||
arguments[parsed] = command.substring(from, space);
|
||||
arguments[parsed++].trim();
|
||||
|
||||
from = space;
|
||||
}
|
||||
|
||||
return parsed;
|
||||
}
|
||||
|
||||
void get_version(String)
|
||||
{
|
||||
Serial.println(F(VER_STRING));
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef UNIT_TEST
|
||||
void setup()
|
||||
{
|
||||
// initialise serial port
|
||||
Serial.begin(115200);
|
||||
while (!Serial)
|
||||
delay(1);
|
||||
|
||||
register_module(core_commands, NULL);
|
||||
|
||||
#ifdef HELP
|
||||
// D(help_commands_t[0].command);
|
||||
help_setup();
|
||||
#endif
|
||||
|
||||
//register modules
|
||||
#ifdef STAGE
|
||||
stage_setup();
|
||||
#endif
|
||||
|
||||
#ifdef LIGHT_SENSOR
|
||||
light_sensor_setup(); //TODO
|
||||
#endif
|
||||
|
||||
#ifdef ENDSTOPS
|
||||
light_sensor_setup(); //TODO
|
||||
#endif
|
||||
|
||||
registered_commands[registered_commands_count] = END_COMMAND;
|
||||
Serial.println(F(VERSION_STRING));
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (Serial.available())
|
||||
{
|
||||
handle_command(Serial.readStringUntil('\n'));
|
||||
}
|
||||
|
||||
for (int i = 0; i < registered_loop_fn_count; i++)
|
||||
registered_loop_functions[i]();
|
||||
}
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue