From 06ef60011e548f9734a83244f1038e90f353c50d Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 27 Jun 2018 11:54:45 -0400 Subject: [PATCH] gpiocmds: Add update_digital_out command Add a command that can immediately set the value of a digital output pin created with config_digital_out. Signed-off-by: Kevin O'Connor --- src/gpiocmds.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/gpiocmds.c b/src/gpiocmds.c index cc221fc3..105d9d88 100644 --- a/src/gpiocmds.c +++ b/src/gpiocmds.c @@ -68,6 +68,21 @@ command_schedule_digital_out(uint32_t *args) DECL_COMMAND(command_schedule_digital_out, "schedule_digital_out oid=%c clock=%u value=%c"); +void +command_update_digital_out(uint32_t *args) +{ + struct digital_out_s *d = oid_lookup(args[0], command_config_digital_out); + sched_del_timer(&d->timer); + uint8_t value = args[1]; + gpio_out_write(d->pin, value); + if (value != d->default_value && d->max_duration) { + d->timer.waketime = timer_read_time() + d->max_duration; + d->timer.func = digital_end_event; + sched_add_timer(&d->timer); + } +} +DECL_COMMAND(command_update_digital_out, "update_digital_out oid=%c value=%c"); + void digital_out_shutdown(void) {