Subversion Repositories HomeAutomation

Rev

Rev 179 | Rev 256 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /**
  2.  * CAN LCD.
  3.  * For HD44780- and KS0073-based LCD displays
  4.  * This is the early version that only prints temperature sensor data.
  5.  *
  6.  * @date    2006-12-11
  7.  * @author  Erik Larsson
  8.  *
  9.  * TODO Fix more types of output: relay status, mail recieved etc.
  10.  * Make it configurable to use UART, because it's not necessary on the final PCB
  11.  *
  12.  */
  13.  
  14. #define DEBUG 1
  15.  
  16. /*-----------------------------------------------------------------------------
  17.  * Includes
  18.  *---------------------------------------------------------------------------*/
  19. /* system files */
  20. #include <avr/io.h>
  21. #include <avr/interrupt.h>
  22. #include <avr/wdt.h>
  23. #include <stdio.h>
  24. /* lib files */
  25. #include <can.h>
  26. #include <serial.h>
  27. #include <timebase.h>
  28. #include <lcd_HD44780.h>
  29. #include <clcd20x4.h>
  30. /* funcdefs */
  31. #include <global_funcdefs.h>
  32. #include <eqlazer_funcdefs.h>
  33.  
  34. /* defines */
  35. #define BUFFER_SIZE 20
  36.  
  37. uint8_t currentView = MAIN_VIEW;
  38. /*static const PROGMEM unsigned char symbolThermometer[] =
  39. {
  40.     0x04, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0E, 0x0E,
  41.     0x0E, 0x0E, 0x0E, 0x0A, 0x11, 0x11, 0x0A, 0x04
  42. };*/ // TODO behövs symbol för termometer?
  43.  
  44. // TODO ISR() för att använda optoencoders
  45. ISR( PCINT2_vect ){
  46.     // TODO do the magic stuff
  47.     // vriden medurs currentView++
  48.     // moturs currentView--
  49. } // TODO lägga denna koden i ett eget lib?
  50.  
  51. /*-----------------------------------------------------------------------------
  52.  * Main Program
  53.  *---------------------------------------------------------------------------*/
  54. int main(void) {
  55.  
  56.     char buffer[ BUFFER_SIZE ];
  57.     uint8_t subzero; // TODO städa upp
  58.     uint8_t m, temperatureData[8], relayStatus[4], dimmerStatus[4];
  59.  
  60.     /*
  61.      * Initialize optoencoders and buttons
  62.      */
  63.     /* Set as input and enable pull-up */ // TODO fixa rätt ingångar
  64.     DDRD &= ~( (1<<DDD6)|(1<<DDD7) );
  65.     PORTD |= (1<<PD6)|(1<<PD7);
  66.     /* Enable IO-pin interrupt */
  67.     PCICR |= (1<<PCIE1);
  68.     /* Unmask PD6 and PD7 */
  69.     PCMSK2 |= (1<<PCINT22)|(1<<PCINT23);
  70.  
  71.  
  72.     Timebase_Init();
  73. #if DEBUG
  74.     Serial_Init();
  75. #endif
  76.     sei();
  77.     lcd_init( LCD_DISP_ON );
  78. #if DEBUG
  79.     printf("\n------------------------------------------------------------\n");
  80.     printf(  "   CAN LCD\n");
  81.     printf(  "------------------------------------------------------------\n");
  82. #endif
  83.     lcd_clrscr();
  84.     lcd_puts("CAN LCD test\n");
  85. #if DEBUG
  86.     printf("CanInit...");
  87.     lcd_puts("CanInit... ");
  88.     if (Can_Init() != CAN_OK) {
  89.         printf("FAILED!\n");
  90.         lcd_puts("FAILED!\n");
  91.     }
  92.     else {
  93.         printf("OK!\n");
  94.         lcd_puts("OK!\n");
  95.     }
  96. #else
  97.     lcd_puts("CanInit... ");
  98.     if (Can_Init() != CAN_OK) {
  99.         lcd_puts("FAILED!\n");
  100.     }else{
  101.         lcd_puts("OK!\n");
  102.     }
  103. #endif
  104.     uint32_t timeStamp = 0;
  105.  
  106.     Can_Message_t txMsg;
  107.     Can_Message_t rxMsg;
  108.     txMsg.Id = 0;
  109.     txMsg.RemoteFlag = 0;
  110.     txMsg.ExtendedFlag = 1;
  111.  
  112.     lcd_clrscr();
  113.  
  114.     /* main loop */
  115.     while (1) {
  116.         /* service the CAN routines */
  117.         Can_Service();
  118.  
  119.         /* check if any messages have been received and print to uart */
  120.         while (Can_Receive(&rxMsg) == CAN_OK) {
  121. #if DEBUG
  122.             printf("MSG Received: ID=%lx, DLC=%u, EXT=%u, RTR=%u, ", rxMsg.Id, (uint16_t)(rxMsg.DataLength), (uint16_t)(rxMsg.ExtendedFlag), (uint16_t)(rxMsg.RemoteFlag));
  123.             printf("data={ ");
  124.  
  125.             for (uint8_t i=0; i<rxMsg.DataLength; i++) {
  126.                 printf("%x ", rxMsg.Data.bytes[i]);
  127.             }
  128.             printf("}\n");
  129. #endif
  130.             /* Get data from bus and store */
  131.             if( rxMsg.Id == 0x300 ){
  132.                 /* Temperature sensor data */
  133.                 for(m=0; m<rxMsg.DataLength; m++){
  134.                     temperatureData[m] = rxMsg.Data.bytes[m];
  135.                 }
  136.             }else if( rxMsg.Id == 0x1201 ){
  137.                 /* Relay status (ON/OFF) */
  138.                 relayStatus[1] = rxMsg.Data.bytes[2];
  139.             } /* TODO Add extra messages here */
  140.         }
  141.  
  142.         /* Print views */
  143.         // TODO använd optoencoders för att växla view
  144.         printLCDview( MAIN_VIEW );
  145.  
  146.     }
  147.  
  148.     return 0;
  149. }
  150.