From 8d6ecd9af87d3e0da312588bacb1c43332412107 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sun, 5 Mar 2017 14:10:19 -0500 Subject: endstop: No need to store pin_value The pin_value can be stored in the existing flags variable. Signed-off-by: Kevin O'Connor --- src/endstop.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/endstop.c') diff --git a/src/endstop.c b/src/endstop.c index ae41656a..3701f642 100644 --- a/src/endstop.c +++ b/src/endstop.c @@ -16,10 +16,10 @@ struct end_stop { uint32_t rest_time; struct stepper *stepper; struct gpio_in pin; - uint8_t pin_value, flags; + uint8_t flags; }; -enum { ESF_HOMING=1, ESF_REPORT=2 }; +enum { ESF_PIN_HIGH=1<<0, ESF_HOMING=1<<1, ESF_REPORT=1<<2 }; // Timer callback for an end stop static uint_fast8_t @@ -27,7 +27,8 @@ end_stop_event(struct timer *t) { struct end_stop *e = container_of(t, struct end_stop, time); uint8_t val = gpio_in_read(e->pin); - if (val != e->pin_value) { + if ((val ? ~e->flags : e->flags) & ESF_PIN_HIGH) { + // No match - reschedule for the next attempt e->time.waketime += e->rest_time; return SF_RESCHEDULE; } @@ -62,8 +63,7 @@ command_end_stop_home(uint32_t *args) e->flags = 0; return; } - e->pin_value = args[3]; - e->flags = ESF_HOMING; + e->flags = ESF_HOMING | (args[3] ? ESF_PIN_HIGH : 0); sched_timer(&e->time); } DECL_COMMAND(command_end_stop_home, -- cgit v1.2.3-70-g09d2