Hardware UART comms + partial v5 modules support

This commit is contained in:
Filip Ayazi 2022-09-03 22:04:28 +01:00
parent dfd4a99f1f
commit fde7a90480
10 changed files with 296 additions and 120 deletions

View file

@ -32,10 +32,22 @@
#include "modules/endstops/endstops.h"
#endif
#ifdef STEPSTICK
#include "modules/stepstick/stepstick.h"
#endif
#ifdef ILLUMINATION
#include "modules/illumination/illumination.h"
#endif
#ifdef LIGHT_SENSOR
#include "modules/light_sensor/light_sensor.h"
#endif
#ifdef BOARD_SANGABOARDv5
//arduino::UART PiSerial(8, 9, NC, NC); //TODO this shouldn't be here
#endif
const Command *registered_commands[MAX_COMMANDS];
void (*registered_loop_functions[MAX_MODULES])(void);
@ -65,9 +77,9 @@ void handle_command(String received_command)
}
#ifdef HELP
Serial.println(F("Type 'help' for a list of commands."));
SERIAL_PORT.println(F("Type 'help' for a list of commands."));
#else
Serial.println(F("Invalid command"));
SERIAL_PORT.println(F("Invalid command"));
#endif
}
@ -96,40 +108,41 @@ uint8_t parse_arguments(char **arguments, String command, uint8_t max_args)
void get_version(String)
{
Serial.println(F(VERSION_STRING));
SERIAL_PORT.println(F(VERSION_STRING));
return;
}
void get_modules(String)
{
#if defined(LIGHTSENSOR) && defined(LIGHT_SENSOR_ADAFRUIT_TSL2591)
Serial.println(F("Light Sensor: TSL2591"));
SERIAL_PORT.println(F("Light Sensor: TSL2591"));
#elif defined(LIGHTSENSOR) && defined(LIGHT_SENSOR_ADAFRUIT_ADS1115)
Serial.println(F("Light Sensor: ADS1115"));
SERIAL_PORT.println(F("Light Sensor: ADS1115"));
#endif
#if defined(ENDSTOPS)
Serial.print("Endstops:");
SERIAL_PORT.print("Endstops:");
#ifdef ENDSTOPS_MIN
Serial.print(" min");
SERIAL_PORT.print(" min");
#endif
#ifdef ENDSTOPS_MAX
Serial.print(" max");
SERIAL_PORT.print(" max");
#endif
#ifdef ENDSTOPS_SOFT
Serial.print(" soft");
SERIAL_PORT.print(" soft");
#endif
Serial.println();
SERIAL_PORT.println();
#endif
Serial.println("--END--");
SERIAL_PORT.println("--END--");
}
#ifndef UNIT_TEST
void setup()
{
// initialise serial port
Serial.begin(115200);
while (!Serial)
//SERIAL_PORT.begin(115200);
SERIAL_PORT.begin(115200);
while (!SERIAL_PORT)
delay(1);
register_module(core_commands, NULL);
@ -151,15 +164,23 @@ void setup()
endstops_setup();
#endif
#ifdef STEPSTICK
stepstick_setup();
#endif
#ifdef ILLUMINATION
illumination_setup();
#endif
registered_commands[registered_commands_count] = &end_command;
Serial.println(F(VERSION_STRING));
SERIAL_PORT.println(F(VERSION_STRING));
}
void loop()
{
if (Serial.available())
if (SERIAL_PORT.available())
{
handle_command(Serial.readStringUntil('\n'));
handle_command(SERIAL_PORT.readStringUntil('\n'));
}
for (int i = 0; i < registered_loop_fn_count; i++)

View file

@ -13,6 +13,10 @@
}
#define CHECK_END_COMMAND(C) check_end_command(C)
#ifdef BOARD_SANGABOARDv5
extern arduino::UART PiSerial;
#endif
struct Command
{
const char * command;

View file

@ -99,7 +99,7 @@ void endstops_loop()
homing_final = false;
min_step_delay = previous_step_delay;
home_retreat();
Serial.println("done.");
SERIAL_PORT.println("done.");
return;
}
}
@ -121,8 +121,8 @@ int8_t endstops_check()
if (endstop_break != 0 && stage_moving)
{
Serial.print(F("Endstop hit:"));
Serial.println(endstop_break);
SERIAL_PORT.print(F("Endstop hit:"));
SERIAL_PORT.println(endstop_break);
//if we have both min/max endstops, axis_max is adjusted to the correct value
//if we only have min, we go from 0 -> predefined axis_max
//if we only have max, we go from 0 -> predefined axis_max
@ -154,16 +154,16 @@ void endstops_status(String command)
EACH_MOTOR
{
if (i > 0)
Serial.print(" ");
SERIAL_PORT.print(" ");
if (endstop_triggered(i, -1))
Serial.print("-1");
SERIAL_PORT.print("-1");
else if (endstop_triggered(i, 1))
Serial.print("1");
SERIAL_PORT.print("1");
else
Serial.print("0");
SERIAL_PORT.print("0");
}
Serial.println();
SERIAL_PORT.println();
}
void print_axes_max(String command)
@ -171,10 +171,10 @@ void print_axes_max(String command)
EACH_MOTOR
{
if (i > 0)
Serial.print(" ");
Serial.print(axis_max[i]);
SERIAL_PORT.print(" ");
SERIAL_PORT.print(axis_max[i]);
}
Serial.println();
SERIAL_PORT.println();
}
void home_start(uint8_t axes, int8_t direction)
@ -226,7 +226,7 @@ void home_final()
void endstops_home_min(String command)
{
#ifndef ENDSTOPS_MIN
Serial.println(F("Min endstops not installed"));
SERIAL_PORT.println(F("Min endstops not installed"));
return;
#endif
if (command.equals("home_min"))
@ -241,7 +241,7 @@ void endstops_home_min(String command)
void endstops_home_max(String command)
{
#ifndef ENDSTOPS_MAX
Serial.println(F("Max endstops not installed"));
SERIAL_PORT.println(F("Max endstops not installed"));
return;
#endif
if (command.equals("home_max"))
@ -293,10 +293,10 @@ void endstops_setup()
}
//endstops? - get triggered endstops in (1,0,-1) format for max, none, min"));
// Serial.println(F("home_min <axes?> - home given (00000zyx byte, e.g. 1 for x) or all axes to their min position"));
// Serial.println(F("home_max <axes?> - home given (00000zyx byte, e.g. 3 for x and y) or all axes to their max position"));
// Serial.println(F("max_p? - return positions of max endstops"));
// Serial.println(F("max <d> <d> <d>
// SERIAL_PORT.println(F("home_min <axes?> - home given (00000zyx byte, e.g. 1 for x) or all axes to their min position"));
// SERIAL_PORT.println(F("home_max <axes?> - home given (00000zyx byte, e.g. 3 for x and y) or all axes to their max position"));
// SERIAL_PORT.println(F("max_p? - return positions of max endstops"));
// SERIAL_PORT.println(F("max <d> <d> <d>
extern const Command endstops_commands[] = {
{"endstops?", endstops_status},
{"home_min", endstops_home_min},

View file

@ -9,73 +9,78 @@ void help_setup()
void help(String command)
{
Serial.println("");
Serial.print("Board: ");
Serial.println(F(BOARD_STRING));
SERIAL_PORT.println("");
SERIAL_PORT.print("Board: ");
SERIAL_PORT.println(F(BOARD_STRING));
#ifdef LIGHT_SENSOR
#if defined ADAFRUIT_TSL2591
Serial.println(F("Compiled with Adafruit TSL2591 support"));
SERIAL_PORT.println(F("Compiled with Adafruit TSL2591 support"));
#elif defined ADAFRUIT_ADS1115
Serial.println(F("Compiled with Adafruit ADS1115 support"));
SERIAL_PORT.println(F("Compiled with Adafruit ADS1115 support"));
#endif
#endif //LIGHT_SENSOR
#ifdef ENDSTOPS
#ifdef ENDSTOPS_MIN
Serial.println(F("Compiled with min endstops support"));
SERIAL_PORT.println(F("Compiled with min endstops support"));
#endif
#ifdef ENDSTOPS_MAX
Serial.println(F("Compiled with max endstops support"));
SERIAL_PORT.println(F("Compiled with max endstops support"));
#endif
#endif //ENDSTOPS
Serial.println("");
Serial.println(F("Commands (terminated by a newline character):"));
SERIAL_PORT.println("");
SERIAL_PORT.println(F("Commands (terminated by a newline character):"));
#ifdef STAGE
Serial.println(F("mrx <d> - relative move in x"));
Serial.println(F("mry <d> - relative move in y"));
Serial.println(F("mrz <d> - relative move in z"));
Serial.println(F("mr <d> <d> <d> - relative move in all 3 axes"));
Serial.println(F("release - de-energise all motors"));
Serial.println(F("p? - print position (3 space-separated integers"));
Serial.println(F("ramp_time <d> - set the time taken to accelerate/decelerate in us"));
Serial.println(F("min_step_delay <d> - set the minimum time between steps in us."));
Serial.println(F("dt <d> - set the minimum time between steps in us."));
Serial.println(F("ramp_time? - get the time taken to accelerate/decelerate in us"));
Serial.println(F("min_step_delay? - get the minimum time between steps in us."));
Serial.println(F("zero - set the current position to zero."));
Serial.println(F("stop - stop a move in progress."));
Serial.println(F("blocking_moves? - get blocking moves enabled"));
Serial.println(F("blocking_moves <bool> - enable/disable blocking moves"));
Serial.println(F("moving? - check if a move is in progress"));
Serial.println(F("notify_on_stop - respond with stopped when current move finishes"));
SERIAL_PORT.println(F("mrx <d> - relative move in x"));
SERIAL_PORT.println(F("mry <d> - relative move in y"));
SERIAL_PORT.println(F("mrz <d> - relative move in z"));
SERIAL_PORT.println(F("mr <d> <d> <d> - relative move in all 3 axes"));
SERIAL_PORT.println(F("release - de-energise all motors"));
SERIAL_PORT.println(F("p? - print position (3 space-separated integers"));
SERIAL_PORT.println(F("ramp_time <d> - set the time taken to accelerate/decelerate in us"));
SERIAL_PORT.println(F("min_step_delay <d> - set the minimum time between steps in us."));
SERIAL_PORT.println(F("dt <d> - set the minimum time between steps in us."));
SERIAL_PORT.println(F("ramp_time? - get the time taken to accelerate/decelerate in us"));
SERIAL_PORT.println(F("min_step_delay? - get the minimum time between steps in us."));
SERIAL_PORT.println(F("zero - set the current position to zero."));
SERIAL_PORT.println(F("stop - stop a move in progress."));
SERIAL_PORT.println(F("blocking_moves? - get blocking moves enabled"));
SERIAL_PORT.println(F("blocking_moves <bool> - enable/disable blocking moves"));
SERIAL_PORT.println(F("moving? - check if a move is in progress"));
SERIAL_PORT.println(F("notify_on_stop - respond with stopped when current move finishes"));
#endif //STAGE
#ifdef LIGHT_SENSOR
Serial.println(F("light_sensor_gain <d> - set the gain of the light sensor"));
Serial.println(F("light_sensor_gain? - get the gain of the light sensor"));
Serial.println(F("light_sensor_gain_values? - get the allowable gain values of the light sensor"));
Serial.println(F("light_sensor_integration_time? - get the integration time in milliseconds"));
Serial.println(F("light_sensor_intensity? - read the current value from the full spectrum diode"));
SERIAL_PORT.println(F("light_sensor_gain <d> - set the gain of the light sensor"));
SERIAL_PORT.println(F("light_sensor_gain? - get the gain of the light sensor"));
SERIAL_PORT.println(F("light_sensor_gain_values? - get the allowable gain values of the light sensor"));
SERIAL_PORT.println(F("light_sensor_integration_time? - get the integration time in milliseconds"));
SERIAL_PORT.println(F("light_sensor_intensity? - read the current value from the full spectrum diode"));
#endif //LIGHT_SENSOR
#if defined(ENDSTOPS_MIN) || defined(ENDSTOPS_MAX)
Serial.println(F("endstops? - get triggered endstops in (1,0,-1) format for max, none, min"));
Serial.println(F("home_min <axes?> - home given (00000zyx byte, e.g. 1 for x) or all axes to their min position"));
Serial.println(F("home_max <axes?> - home given (00000zyx byte, e.g. 3 for x and y) or all axes to their max position"));
Serial.println(F("max_p? - return positions of max endstops"));
Serial.println(F("max <d> <d> <d> - set maximum positions"));
SERIAL_PORT.println(F("endstops? - get triggered endstops in (1,0,-1) format for max, none, min"));
SERIAL_PORT.println(F("home_min <axes?> - home given (00000zyx byte, e.g. 1 for x) or all axes to their min position"));
SERIAL_PORT.println(F("home_max <axes?> - home given (00000zyx byte, e.g. 3 for x and y) or all axes to their max position"));
SERIAL_PORT.println(F("max_p? - return positions of max endstops"));
SERIAL_PORT.println(F("max <d> <d> <d> - set maximum positions"));
#endif
//Serial.println(F("test_mode <s> - set test_mode <on> <off>"));
Serial.println(F("version - get firmware version string"));
Serial.println("");
Serial.println("Input Key:");
Serial.println(F("<d> - a decimal integer."));
Serial.println("");
Serial.println("--END--");
#ifdef STEPSTICK
SERIAL_PORT.println(F("stepstick_move <f> <d> - move stepper by <d> with max speed <f>"));
SERIAL_PORT.println(F("stepstick_release - release stepstick stepper"));
SERIAL_PORT.println(F("stepstick_stop - abort stepstick move"));
#endif
//SERIAL_PORT.println(F("test_mode <s> - set test_mode <on> <off>"));
SERIAL_PORT.println(F("version - get firmware version string"));
SERIAL_PORT.println("");
SERIAL_PORT.println("Input Key:");
SERIAL_PORT.println(F("<d> - a decimal integer."));
SERIAL_PORT.println("");
SERIAL_PORT.println("--END--");
}
#endif //HELP

View file

@ -0,0 +1,41 @@
#include "config.h"
#ifdef ILLUMINATION
#include "illumination.h"
#ifdef SUPPORT_EEPROM
#include <EEPROM.h>
#else
#include "dummyEEPROM.h"
#endif
#define WIRING_PWM_LED_NUM 1
#define WIRING_PWM_LEDS {25}
//TODO: implement some fancier features of TMC controllers
const uint8_t pwm_led_pins[] = WIRING_PWM_LEDS;
void illumination_pwm(String command)
{
//TODO: make this properly, this is just a test for hacked on/off
char * args[2];
parse_arguments(args, command, 2);
if (atof(args[1]) < 0.001)
{
digitalWrite(pwm_led_pins[0], LOW);//start with motor disabled
}
else
{
digitalWrite(pwm_led_pins[0], HIGH);
}
SERIAL_PORT.println("Illumination set");
free(args[0]);
free(args[1]);
}
void illumination_setup()
{
pinMode(pwm_led_pins[0], OUTPUT);
register_module(illumination_commands, NULL);
}
extern const Command illumination_commands[] = {
{"led_pwm", illumination_pwm},
END_COMMAND};
#endif

View file

@ -0,0 +1,13 @@
#include "config.h"
#ifdef ILLUMINATION
#ifndef ILLUMINATION_H
#include "config.h"
#include "main.h"
#include <Arduino.h>
void illumination_pwm(String command);
void illumination_setup();
extern const Command illumination_commands[];
#define ILLUMINATION_H
#endif
#endif

View file

@ -54,35 +54,35 @@ void setup_light_sensor_device()
}
else
{
Serial.println(F("No light sensor found. NB your board will start up faster if you recompile without light sensor support."));
SERIAL_PORT.println(F("No light sensor found. NB your board will start up faster if you recompile without light sensor support."));
}
}
void print_light_sensor_gain()
{
// Print the current gain value of the light sensor
Serial.print(F("light sensor gain "));
SERIAL_PORT.print(F("light sensor gain "));
tsl2591Gain_t gain = tsl.getGain();
switch (gain)
{
case TSL2591_GAIN_LOW:
Serial.println(F("1x (Low)"));
SERIAL_PORT.println(F("1x (Low)"));
break;
case TSL2591_GAIN_MED:
Serial.println(F("25x (Medium)"));
SERIAL_PORT.println(F("25x (Medium)"));
break;
case TSL2591_GAIN_HIGH:
Serial.println(F("428x (High)"));
SERIAL_PORT.println(F("428x (High)"));
break;
case TSL2591_GAIN_MAX:
Serial.println(F("9876x (Max)"));
SERIAL_PORT.println(F("9876x (Max)"));
break;
}
}
void light_sensor_gain_values(String command)
{
// Print the allowable gain values of the light sensor
Serial.println(F("light sensor gains: 1x, 25x, 428x, 9876x"));
SERIAL_PORT.println(F("light sensor gains: 1x, 25x, 428x, 9876x"));
}
void set_light_sensor_gain(int newgain)
@ -103,7 +103,7 @@ void set_light_sensor_gain(int newgain)
tsl.setGain(TSL2591_GAIN_MAX);
break;
default:
Serial.println(F("Error: gain may only be 1, 25, 428, or 9876."));
SERIAL_PORT.println(F("Error: gain may only be 1, 25, 428, or 9876."));
return;
}
print_light_sensor_gain();
@ -112,16 +112,16 @@ void set_light_sensor_gain(int newgain)
void light_sensor_integration_time(String command)
{
// Print the current integration time in milliseconds.
Serial.print(F("light sensor integration time "));
Serial.print((tsl.getTiming() + 1) * 100, DEC);
Serial.println(F(" ms"));
SERIAL_PORT.print(F("light sensor integration time "));
SERIAL_PORT.print((tsl.getTiming() + 1) * 100, DEC);
SERIAL_PORT.println(F(" ms"));
}
void light_sensor_intensity(String command)
{
// Print the current light value
uint16_t x = tsl.getLuminosity(TSL2591_FULLSPECTRUM);
Serial.println(x, DEC);
SERIAL_PORT.println(x, DEC);
}
#endif // ADAFRUIT_TSL2591
@ -137,34 +137,34 @@ void setup_light_sensor_device()
void print_light_sensor_gain()
{
// Print the current gain value of the light sensor
Serial.print(F("light sensor gain "));
SERIAL_PORT.print(F("light sensor gain "));
adsGain_t gain = ads.getGain();
switch (gain)
{
case GAIN_TWOTHIRDS:
Serial.println(F("0.66x (specify 0)"));
SERIAL_PORT.println(F("0.66x (specify 0)"));
break;
case GAIN_ONE:
Serial.println(F("1x"));
SERIAL_PORT.println(F("1x"));
break;
case GAIN_TWO:
Serial.println(F("2x"));
SERIAL_PORT.println(F("2x"));
break;
case GAIN_FOUR:
Serial.println(F("4x"));
SERIAL_PORT.println(F("4x"));
break;
case GAIN_EIGHT:
Serial.println(F("8x"));
SERIAL_PORT.println(F("8x"));
break;
case GAIN_SIXTEEN:
Serial.println(F("16x"));
SERIAL_PORT.println(F("16x"));
break;
}
}
void light_sensor_gain_values(String command)
{
// Print the allowable gain values of the light sensor
Serial.println(F("light sensor gains: 0.66x (specify 0), 1x, 2x, 4x, 8x, 16x"));
SERIAL_PORT.println(F("light sensor gains: 0.66x (specify 0), 1x, 2x, 4x, 8x, 16x"));
}
void set_light_sensor_gain(int newgain)
@ -191,7 +191,7 @@ void set_light_sensor_gain(int newgain)
ads.setGain(GAIN_SIXTEEN);
break;
default:
Serial.println(F("Error: gain may only be 0, 1, 2, 4, 8, 16 (0 means 2/3)."));
SERIAL_PORT.println(F("Error: gain may only be 0, 1, 2, 4, 8, 16 (0 means 2/3)."));
return;
}
print_light_sensor_gain();
@ -200,15 +200,22 @@ void set_light_sensor_gain(int newgain)
void light_sensor_integration_time(String command)
{
// Print the current integration time in milliseconds.
Serial.println(F("integration time not supported for ADS1115"));
SERIAL_PORT.println(F("integration time not supported for ADS1115"));
}
void light_sensor_intensity(String command)
{
int ch;
char *args[1];
parse_arguments(args, command, 1);
ch = atoi(args[0]);
free(args[0]);
// Print the current light value
// uint16_t x = ads.readADC_SingleEnded(0); //single ended measurement on pin 0
uint16_t x = ads.readADC_Differential_0_1(); //differential measurement on pins 0,1
Serial.println(x, DEC);
uint16_t x = ads.readADC_SingleEnded(ch); //single ended measurement on pin ch (0-3)
//uint16_t x = ads.readADC_Differential_0_1(); //differential measurement on pins 0,1
SERIAL_PORT.println(x, DEC);
}
#endif // ADAFRUIT_ADS1115
#endif

View file

@ -76,10 +76,10 @@ void print_position()
EACH_MOTOR
{
if (i > 0)
Serial.print(" ");
Serial.print(current_pos[i]);
SERIAL_PORT.print(" ");
SERIAL_PORT.print(current_pos[i]);
}
Serial.println();
SERIAL_PORT.println();
}
unsigned long move_start_time = 0;
@ -124,7 +124,7 @@ void start_move(long displ[n_motors])
}
else
{
Serial.println("done.");
SERIAL_PORT.println("done.");
}
}
@ -183,7 +183,7 @@ void stage_loop()
if (!stage_moving && notify_on_stop)
{
Serial.println("stopped");
SERIAL_PORT.println("stopped");
notify_on_stop = false;
}
}
@ -233,7 +233,7 @@ void stage_release(String command)
{
releaseMotor(i);
}
Serial.println("done");
SERIAL_PORT.println("done");
}
void stage_p(String command)
@ -247,14 +247,14 @@ void stage_min_step_delay(String command)
parse_arguments(args, command, 1);
if (args[0][0] == '?')
{
Serial.print("minimum step delay ");
Serial.println(min_step_delay);
SERIAL_PORT.print("minimum step delay ");
SERIAL_PORT.println(min_step_delay);
}
else
{
min_step_delay = atol(args[0]);
EEPROM.put(min_step_delay_eeprom, min_step_delay);
Serial.println("done.");
SERIAL_PORT.println("done.");
}
free(args[0]);
}
@ -265,14 +265,14 @@ void stage_ramp_time(String command)
parse_arguments(args, command, 1);
if (args[0][0] == '?')
{
Serial.print("ramp_time ");
Serial.println(ramp_time);
SERIAL_PORT.print("ramp_time ");
SERIAL_PORT.println(ramp_time);
}
else
{
ramp_time = atol(args[0]);
EEPROM.put(ramp_time_eeprom, ramp_time);
Serial.println("done.");
SERIAL_PORT.println("done.");
}
free(args[0]);
}
@ -283,41 +283,41 @@ void update_blocking_moves(String command)
parse_arguments(args, command, 1);
if (args[0][0] == '?')
{
Serial.print("blocking_moves ");
Serial.println(non_blocking_moves ? "false" : "true");
SERIAL_PORT.print("blocking_moves ");
SERIAL_PORT.println(non_blocking_moves ? "false" : "true");
}
else
{
non_blocking_moves = !(args[0][0] == 't');
EEPROM.put(non_blocking_moves_eeprom, non_blocking_moves);
Serial.println("done.");
SERIAL_PORT.println("done.");
}
}
void stage_zero(String command)
{
EACH_MOTOR current_pos[i] = 0;
Serial.println(F("position reset to 0 0 0"));
SERIAL_PORT.println(F("position reset to 0 0 0"));
EEPROM.put(0, current_pos);
}
void stage_stop(String command)
{
stage_moving = false;
Serial.println("Move aborted");
SERIAL_PORT.println("Move aborted");
}
void is_stage_moving(String command)
{
//TODO: should I bother checking for a ?
Serial.println(stage_moving ? "true" : "false");
SERIAL_PORT.println(stage_moving ? "true" : "false");
}
void activate_notify_on_stop(String command)
{
if (!stage_moving)
{
Serial.println("Error: stage is not moving");
SERIAL_PORT.println("Error: stage is not moving");
}
else
{

View file

@ -0,0 +1,68 @@
#include "config.h"
#define STEPSTICK //TODO: remove
#ifdef STEPSTICK
#include "stepstick.h"
#ifdef SUPPORT_EEPROM
#include <EEPROM.h>
#else
#include "dummyEEPROM.h"
#endif
#include <AccelStepper.h>
//TODO: implement some fancier features of TMC controllers
const uint8_t stepstick_pins[] = WIRING_STEPSTICK;
AccelStepper stepper(AccelStepper::DRIVER, stepstick_pins[1], stepstick_pins[2]);
bool moving = false;
void stepstick_release(String command)
{
digitalWrite(stepstick_pins[0], HIGH);//start with motor disabled
SERIAL_PORT.println("Stepstick released");
}
void stepstick_stop(String command)
{
stepper.stop();
SERIAL_PORT.println("Stepstick stopping");
}
void stepstick_move(String command)
{
digitalWrite(stepstick_pins[0], LOW);
char * args[2];
parse_arguments(args, command, 2);
float speed = atof(args[0]);
long distance = atol(args[1]);
stepper.setMaxSpeed(speed);
stepper.moveTo(stepper.currentPosition() + distance);
free(args[0]);
free(args[1]);
SERIAL_PORT.println("Stepstick started");
moving = true;
}
void stepstick_setup()
{
pinMode(stepstick_pins[0], OUTPUT);
digitalWrite(stepstick_pins[0], HIGH);//start with motor disabled
register_module(stepstick_commands, stepstick_loop);
stepper.setAcceleration(50000);//256 microsteps
}
void stepstick_loop()
{
stepper.run();
if (stepper.distanceToGo() == 0 && moving)
{
moving = false;
SERIAL_PORT.println("Stepstick stopped");
}
}
extern const Command stepstick_commands[] = {
{"stepstick_move", stepstick_move},
{"stepstick_release", stepstick_release},
{"stepstick_stop", stepstick_stop},
END_COMMAND};
#endif

View file

@ -0,0 +1,17 @@
#include "config.h"
#ifdef STEPSTICK
#ifndef STEPSTICK_H
#include "config.h"
#include "main.h"
#include <Arduino.h>
void stepstick_setup();
void stepstick_loop();
void stepstick_move(String command);
void stepstick_release(String command);
void stepstick_stop(String command);
extern const Command stepstick_commands[];
#define STEPSTICK_H
#endif
#endif