From: Mikko Rasa Date: Sun, 3 Nov 2013 17:05:33 +0000 (+0200) Subject: Add a subsystem by which other modules can sync to the output X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=b70546e9e5c62a1a89c3e9aa0e8f64cc4a937ab2;p=model-railway-devices.git Add a subsystem by which other modules can sync to the output --- diff --git a/arducontrol/output.c b/arducontrol/output.c index e017560..508b411 100644 --- a/arducontrol/output.c +++ b/arducontrol/output.c @@ -17,6 +17,7 @@ enum State OutputPacket packets[4]; uint8_t chain_length; uint8_t current_packet; +volatile uint8_t trigger_value; volatile uint8_t packet_state = IDLE; static uint8_t out_bit; static uint8_t out_time; @@ -35,13 +36,15 @@ OutputPacket *output_create_packet(void) { while(packet_state!=IDLE) ; chain_length = 1; + packets[0].trigger_position = 0xFF; return &packets[0]; } OutputPacket *output_create_chained_packet(void) { - ++chain_length; - return &packets[chain_length-1]; + uint8_t i = chain_length++; + packets[i].trigger_position = 0xFF; + return &packets[i]; } void output_send_packet(void) @@ -50,9 +53,15 @@ void output_send_packet(void) return; current_packet = 0; + trigger_value = 0; packet_state = READY; } +uint8_t output_get_trigger(void) +{ + return trigger_value; +} + void output_set_power(uint8_t p) { if(p==POWER_ON) @@ -129,6 +138,9 @@ static inline void output_tick(void) else PORTD &= ~BIT(POLARITY); + if(out_bit==packet->trigger_position) + trigger_value = packet->trigger_value; + out_time = packet->bit_duration; } diff --git a/arducontrol/output.h b/arducontrol/output.h index 2fde262..0a76c5f 100644 --- a/arducontrol/output.h +++ b/arducontrol/output.h @@ -11,12 +11,15 @@ typedef struct uint8_t repeat_count; uint8_t repeat_delay; uint8_t final_delay; + uint8_t trigger_position; + uint8_t trigger_value; } OutputPacket; void output_init(void); OutputPacket *output_create_packet(void); OutputPacket *output_create_chained_packet(void); void output_send_packet(void); +uint8_t output_get_trigger(void); void output_set_power(uint8_t); uint8_t output_is_power_on(); uint8_t output_command(const uint8_t *, uint8_t);