Details | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 159 | arune | 1 | /** |
| 322 | eqlazer | 2 | * CanIRreceive |
| 3 | * Receives IR data and sends packages to CAN |
||
| 4 | * |
||
| 159 | arune | 5 | * @date 2006-11-21 |
| 322 | eqlazer | 6 | * @author Jimmy Myhrman, Anders Runeson |
| 7 | * Converted to BIOS version by Erik Larsson 2007-02-12 |
||
| 8 | * |
||
| 159 | arune | 9 | */ |
| 10 | |||
| 11 | /*----------------------------------------------------------------------------- |
||
| 12 | * Includes |
||
| 13 | *---------------------------------------------------------------------------*/ |
||
| 14 | /* system files */ |
||
| 15 | #include <avr/io.h> |
||
| 16 | #include <avr/interrupt.h> |
||
| 17 | #include <stdio.h> |
||
| 18 | /* lib files */ |
||
| 322 | eqlazer | 19 | #include <bios.h> |
| 159 | arune | 20 | #include <irreceiver.h> |
| 322 | eqlazer | 21 | #include <eqlazer_funcdefs.h> |
| 159 | arune | 22 | |
| 168 | arune | 23 | #define STATE_IDLE 0 |
| 24 | #define STATE_IR_REPEAT 1 |
||
| 159 | arune | 25 | |
| 26 | /*----------------------------------------------------------------------------- |
||
| 27 | * Main Program |
||
| 28 | *---------------------------------------------------------------------------*/ |
||
| 29 | int main(void) { |
||
| 322 | eqlazer | 30 | |
| 203 | arune | 31 | sei(); |
| 322 | eqlazer | 32 | |
| 159 | arune | 33 | IRDDR &= ~(1<<IRBIT); |
| 322 | eqlazer | 34 | |
| 159 | arune | 35 | uint32_t timeStamp = 0; |
| 168 | arune | 36 | uint32_t irTimeoutTimeStamp = 0; |
| 322 | eqlazer | 37 | |
| 159 | arune | 38 | Can_Message_t txMsg; |
| 39 | Can_Message_t rxMsg; |
||
| 322 | eqlazer | 40 | txMsg.Id = (CLASS_SNS << CLASS_MASK_BITS)|(SNS_IR_RECEIVE << TYPE_MASK_BITS)|(NODE_ID); |
| 41 | |||
| 159 | arune | 42 | uint8_t ir_protocol, ir_address, ir_command; |
| 168 | arune | 43 | uint8_t state = STATE_IDLE; |
| 322 | eqlazer | 44 | |
| 159 | arune | 45 | /* main loop */ |
| 46 | while (1) { |
||
| 168 | arune | 47 | if (state == STATE_IDLE) { |
| 48 | if (checkIr(&ir_protocol, &ir_address, &ir_command) == IR_OK) { |
||
| 49 | txMsg.Data.bytes[0] = 0x00; |
||
| 50 | txMsg.Data.bytes[1] = ir_protocol; |
||
| 51 | txMsg.Data.bytes[2] = ir_address; |
||
| 52 | txMsg.Data.bytes[3] = ir_command; |
||
| 53 | txMsg.DataLength = 4; |
||
| 322 | eqlazer | 54 | bios->can_send(&txMsg); |
| 55 | irTimeoutTimeStamp = bios->timebase_get(); |
||
| 168 | arune | 56 | state = STATE_IR_REPEAT; |
| 57 | } |
||
| 58 | } else if (state == STATE_IR_REPEAT) { |
||
| 59 | //kolla efter ny ir, om ingen ny ir och timeout så sätt state till IDLE |
||
| 322 | eqlazer | 60 | if (bios->timebase_get() - irTimeoutTimeStamp >= 105) { //getLastProtoTimeout() |
| 168 | arune | 61 | state = STATE_IDLE; |
| 62 | txMsg.Data.bytes[0] = 0x0f; |
||
| 322 | eqlazer | 63 | bios->can_send(&txMsg); |
| 168 | arune | 64 | } |
| 200 | arune | 65 | if (checkIrIdle() == IR_OK) { //funktion som borde finnas i irreceiver.c |
| 322 | eqlazer | 66 | irTimeoutTimeStamp = bios->timebase_get(); |
| 168 | arune | 67 | } |
| 159 | arune | 68 | } |
| 69 | } |
||
| 322 | eqlazer | 70 | |
| 159 | arune | 71 | return 0; |
| 72 | } |