Subversion Repositories HomeAutomation

Rev

Rev 221 | Blame | Last modification | View Log | SVN | RSS feed

  1. /**
  2.  * CanIRreceive
  3.  * Receives IR data and sends packages to CAN
  4.  *
  5.  * @date    2006-11-21
  6.  * @author  Jimmy Myhrman, Anders Runeson
  7.  * Converted to BIOS version by Erik Larsson 2007-02-12
  8.  *
  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 */
  19. #include <bios.h>
  20. #include <irreceiver.h>
  21. #include <eqlazer_funcdefs.h>
  22.  
  23. #define STATE_IDLE      0
  24. #define STATE_IR_REPEAT 1
  25.  
  26. /*-----------------------------------------------------------------------------
  27.  * Main Program
  28.  *---------------------------------------------------------------------------*/
  29. int main(void) {
  30.  
  31.     sei();
  32.  
  33.     IRDDR &= ~(1<<IRBIT);
  34.  
  35.     uint32_t timeStamp = 0;
  36.     uint32_t irTimeoutTimeStamp = 0;
  37.  
  38.     Can_Message_t txMsg;
  39.     Can_Message_t rxMsg;
  40.     txMsg.Id = (CLASS_SNS << CLASS_MASK_BITS)|(SNS_IR_RECEIVE << TYPE_MASK_BITS)|(NODE_ID);
  41.  
  42.     uint8_t ir_protocol, ir_address, ir_command;
  43.     uint8_t state = STATE_IDLE;
  44.  
  45.     /* main loop */
  46.     while (1) {
  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;
  54.                 bios->can_send(&txMsg);
  55.                 irTimeoutTimeStamp = bios->timebase_get();
  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
  60.             if (bios->timebase_get() - irTimeoutTimeStamp >= 105) {     //getLastProtoTimeout()
  61.                 state = STATE_IDLE;
  62.                 txMsg.Data.bytes[0] = 0x0f;
  63.                 bios->can_send(&txMsg);
  64.             }
  65.             if (checkIrIdle() == IR_OK) {       //funktion som borde finnas i irreceiver.c
  66.                 irTimeoutTimeStamp = bios->timebase_get();
  67.             }
  68.         }
  69.     }
  70.  
  71.     return 0;
  72. }
  73.