Subversion Repositories HomeAutomation

Rev

Rev 196 | 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. /* For eq's testing purpose */
  15. #define EQLAZER 0
  16.  
  17. /*-----------------------------------------------------------------------------
  18.  * Includes
  19.  *---------------------------------------------------------------------------*/
  20. /* system files */
  21. #include <avr/io.h>
  22. #include <avr/interrupt.h>
  23. #include <avr/wdt.h>
  24. #include <stdio.h>
  25. /* lib files */
  26. #include <can.h>
  27. #include <serial.h>
  28. #include <timebase.h>
  29. #include <lcd_HD44780.h>
  30.  
  31. /* defines */
  32. //#include <global_funcdefs> // TODO in future version use this (first fix the defs)
  33.  
  34. #ifdef EQLAZER
  35. #include <eqlazer_funcdefs.h> // for eq's personal defs
  36. #endif
  37.  
  38. #define BUFFER_SIZE 20
  39.  
  40. /*-----------------------------------------------------------------------------
  41.  * Main Program
  42.  *---------------------------------------------------------------------------*/
  43. int main(void) {
  44.  
  45.     char buffer[ BUFFER_SIZE ];
  46.     uint8_t subzero;
  47.  
  48.     Timebase_Init();
  49.     Serial_Init();
  50.     sei();
  51.     lcd_init( LCD_DISP_ON );
  52.  
  53.     printf("\n------------------------------------------------------------\n");
  54.     printf(  "   CAN LCD\n");
  55.     printf(  "------------------------------------------------------------\n");
  56.  
  57.     lcd_clrscr();
  58.     lcd_puts("CAN LCD test\n");
  59.  
  60.     printf("CanInit...");
  61.     lcd_puts("CanInit... ");
  62.     if (Can_Init() != CAN_OK) {
  63.         printf("FAILED!\n");
  64.         lcd_puts("FAILED!\n");
  65.     }
  66.     else {
  67.         printf("OK!\n");
  68.         lcd_puts("OK!\n");
  69.     }
  70.    
  71.     uint32_t timeStamp = 0;
  72.    
  73.     Can_Message_t txMsg;
  74.     Can_Message_t rxMsg;
  75.     txMsg.Id = 0;
  76.     txMsg.RemoteFlag = 0;
  77.     txMsg.ExtendedFlag = 1;
  78.  
  79.     lcd_clrscr();
  80.  
  81.     /* main loop */
  82.     while (1) {
  83.         /* service the CAN routines */
  84.         Can_Service();
  85.  
  86.         /* check if any messages have been received and print to uart */
  87.         while (Can_Receive(&rxMsg) == CAN_OK) {
  88.             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));
  89.             printf("data={ ");
  90.  
  91.             for (uint8_t i=0; i<rxMsg.DataLength; i++) {
  92.                 printf("%x ", rxMsg.Data.bytes[i]);
  93.             }
  94.             printf("}\n");
  95.  
  96. #ifdef EQLAZER /* More personalized code */
  97.             if( (rxMsg.Id & 0x1E000000)>>25 == FUNCT_SENSORS){
  98.  
  99. // TODO fixa rätt umatning av sensordata: negativa tal och decimaldelen.
  100. // Skriva om hela skiten
  101. //
  102.                 /* which temperature sensor? */
  103.                 if( (rxMsg.Id & 0x01FF8000)>>15 == FUNCC_SENSORS_TEMPERATURE_INSIDE ){
  104.                     /* Below 0 degrees celsius? */
  105.                     if(rxMsg.Data.bytes[0]&0x80){
  106.                         rxMsg.Data.bytes[0]= -rxMsg.Data.bytes[0];
  107.                         subzero = 1;
  108.                     }else{
  109.                         subzero = 0;
  110.                     }
  111.                         snprintf( buffer, BUFFER_SIZE, (subzero)?"-%d,%d%cC":"%d,%d%cC", rxMsg.Data.bytes[0], rxMsg.Data.bytes[1], 0xdf );
  112.                         lcd_gotoxy( LCD_LINE0_0 );
  113.                         lcd_puts( LCD_SENSOR_TEMPERATURE_INSIDE );
  114.                         lcd_gotoxy( LCD_LINE1_0 );
  115.                         lcd_puts( buffer );
  116.                 }else if( (rxMsg.Id & 0x01FF8000)>>15 == FUNCC_SENSORS_TEMPERATURE_OUTSIDE ){
  117.                     if(rxMsg.Data.bytes[0]&0x80){
  118.                         rxMsg.Data.bytes[0]= -rxMsg.Data.bytes[0];
  119.                         subzero = 1;
  120.                     }else{
  121.                         subzero = 0;
  122.                     }
  123.                         snprintf( buffer, BUFFER_SIZE, (subzero)?"-%d,%d%cC":"%d,%d%cC", rxMsg.Data.bytes[0], rxMsg.Data.bytes[1], 0xdf );
  124.                         lcd_gotoxy( LCD_LINE2_0 );
  125.                         lcd_puts( LCD_SENSOR_TEMPERATURE_OUTSIDE );
  126.                         lcd_gotoxy( LCD_LINE3_0 );
  127.                         lcd_puts( buffer );
  128.                 }else if( (rxMsg.Id & 0x01FF8000)>>15 == FUNCC_SENSORS_TEMPERATURE_FREEZER ){
  129.                     if(rxMsg.Data.bytes[0]&0x80){
  130.                         rxMsg.Data.bytes[0]= -rxMsg.Data.bytes[0];
  131.                         subzero = 1;
  132.                     }else{
  133.                         subzero = 0;
  134.                     }
  135.                         snprintf( buffer, BUFFER_SIZE, (subzero)?"-%d,%d%cC":"%d,%d%cC", rxMsg.Data.bytes[0], rxMsg.Data.bytes[1], 0xdf );
  136.                         lcd_gotoxy( LCD_LINE2_2 );
  137.                         lcd_puts( LCD_SENSOR_TEMPERATURE_FREEZER );
  138.                         lcd_gotoxy( LCD_LINE3_2 );
  139.                         lcd_puts( buffer );
  140.                 }else{
  141.                     lcd_clrscr();
  142.                     lcd_puts("Sensors: No config.");
  143.                 }
  144.             }
  145. #else /* Generally code */
  146.  
  147.         /* If temperature sensor data received print to LCD */
  148.         if( rxMsg.Id  == 0x300 ){
  149.  
  150.                 for( uint8_t i=0; i<(rxMsg.DataLength/2); i++ ){
  151.                         snprintf( buffer, BUFFER_SIZE, "Sensor %i: %d,%d%cC", i, rxMsg.Data.bytes[i*2], rxMsg.Data.bytes[i*2+1], 0xdf ); // TODO fixa korrekt utmatning av negativa tal och decimaldel
  152.                         lcd_gotoxy(0,1+i);
  153.                         lcd_puts( buffer );
  154.                 }
  155.             }
  156. #endif
  157.         }
  158.     }
  159.    
  160.     return 0;
  161. }
  162.