stepper: Introduce stepper_get_position command and remove from endstop.c

Move the logic to calculate and report the stepper's current position
from endstop.c to stepper.c.  This localizes the stepper code into
stepper.c.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2017-03-05 15:00:15 -05:00
parent 8d6ecd9af8
commit a38437f378
6 changed files with 54 additions and 28 deletions

View file

@ -42,7 +42,7 @@ void
command_config_end_stop(uint32_t *args)
{
struct end_stop *e = oid_alloc(args[0], command_config_end_stop, sizeof(*e));
struct stepper *s = oid_lookup(args[3], command_config_stepper);
struct stepper *s = stepper_oid_lookup(args[3]);
e->time.func = end_stop_event;
e->stepper = s;
e->pin = gpio_in_setup(args[1], args[2]);
@ -73,14 +73,12 @@ static void
end_stop_report(uint8_t oid, struct end_stop *e)
{
irq_disable();
uint32_t position = stepper_get_position(e->stepper);
uint8_t eflags = e->flags;
e->flags &= ~ESF_REPORT;
irq_enable();
sendf("end_stop_state oid=%c homing=%c pin=%c pos=%i"
, oid, !!(eflags & ESF_HOMING), gpio_in_read(e->pin)
, position - STEPPER_POSITION_BIAS);
sendf("end_stop_state oid=%c homing=%c pin=%c"
, oid, !!(eflags & ESF_HOMING), gpio_in_read(e->pin));
}
void