#define ENABLE PORTD3
#define BIT(x) (1<<(x))
+enum State
+{
+ IDLE,
+ READY,
+ SENDING
+};
+
OutputPacket packet;
+volatile uint8_t packet_state = IDLE;
static uint8_t out_bit;
static uint8_t out_time;
static uint8_t out_data;
timer_start_hz(2, 80000, 1);
}
-void clear_packet(void)
+OutputPacket *output_create_packet(void)
{
- packet.ready = 0;
- packet.sending = 0;
- packet.done = 0;
+ while(packet_state!=IDLE) ;
+ return &packet;
+}
+
+void output_send_packet(void)
+{
+ if(packet_state!=IDLE)
+ return;
+
+ packet_state = READY;
}
void output_set_power(uint8_t p)
if(packet.repeat_count<0xFF)
--packet.repeat_count;
delay_time = packet.repeat_delay;
- packet.sending = 0;
+ packet_state = READY;
}
else
{
delay_time = packet.final_delay;
- packet.done = 1;
+ packet_state = IDLE;
}
}
else
return;
}
- if(packet.ready && !packet.sending)
+ if(packet_state==READY)
{
- packet.sending = 1;
+ packet_state = SENDING;
out_bit = 0;
out_time = packet.bit_duration;
out_data = packet.data[0];