From 9106943c465894bd1a8862b0a6d7ffdd89f8b643 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 2 Nov 2013 13:38:48 +0200 Subject: [PATCH] Add a function and command to find out if power is applied to the output --- arducontrol/commands.h | 2 ++ arducontrol/output.c | 17 ++++++++++++++++- arducontrol/output.h | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/arducontrol/commands.h b/arducontrol/commands.h index eae919c..7e2370a 100644 --- a/arducontrol/commands.h +++ b/arducontrol/commands.h @@ -5,6 +5,7 @@ enum Command { POWER_ON = 0x01, POWER_OFF = 0x02, + READ_POWER_STATE = 0x03, READ_TRACK_CURRENT = 0x08, SET_OVERCURRENT_LIMIT = 0x09, READ_INPUT_VOLTAGE = 0x0A, @@ -23,6 +24,7 @@ enum Command OVERCURRENT = 0xA0, TRACK_CURRENT = 0xC0, INPUT_VOLTAGE = 0xC1, + POWER_STATE = 0xC2, S88_DATA = 0xD0 }; diff --git a/arducontrol/output.c b/arducontrol/output.c index 3c94f70..38d1045 100644 --- a/arducontrol/output.c +++ b/arducontrol/output.c @@ -1,5 +1,5 @@ #include -#include "commands.h" +#include "interface.h" #include "output.h" #include "timer.h" @@ -36,6 +36,11 @@ void output_set_power(uint8_t p) PORTD &= ~BIT(ENABLE); } +uint8_t output_is_power_on() +{ + return (PORTD&BIT(ENABLE))!=0; +} + uint8_t output_command(const uint8_t *cmd_buf, uint8_t cmd_length) { if(cmd_buf[0]==POWER_ON || cmd_buf[0]==POWER_OFF) @@ -45,6 +50,16 @@ uint8_t output_command(const uint8_t *cmd_buf, uint8_t cmd_length) output_set_power(cmd_buf[0]==POWER_ON); } + else if(cmd_buf[0]==READ_POWER_STATE) + { + if(cmd_length!=1) + return LENGTH_ERROR; + + uint8_t reply[2]; + reply[0] = POWER_STATE; + reply[1] = output_is_power_on(); + interface_send(reply, 2); + } else return INVALID_COMMAND; diff --git a/arducontrol/output.h b/arducontrol/output.h index c94c665..988c16e 100644 --- a/arducontrol/output.h +++ b/arducontrol/output.h @@ -21,6 +21,7 @@ extern OutputPacket packet; void output_init(void); void clear_packet(void); void output_set_power(uint8_t); +uint8_t output_is_power_on(); uint8_t output_command(const uint8_t *, uint8_t); #endif -- 2.45.2