]> git.tdb.fi Git - model-railway-devices.git/commitdiff
Add a subsystem by which other modules can sync to the output
authorMikko Rasa <tdb@tdb.fi>
Sun, 3 Nov 2013 17:05:33 +0000 (19:05 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 3 Nov 2013 17:05:33 +0000 (19:05 +0200)
arducontrol/output.c
arducontrol/output.h

index e017560c5cf6e12930f3b65003b4eae1823868b0..508b411953f2ec7230b0c66568d87a93af0e6da3 100644 (file)
@@ -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;
                }
 
index 2fde2627f3f05d2818b6a581eb0883309dbd2b97..0a76c5f2a4c25019b25ca4a7043ee69b995e1b63 100644 (file)
@@ -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);