Subversion Repositories HomeAutomation

Rev

Rev 256 | Rev 334 | 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. /*-----------------------------------------------------------------------------
  15.  * Includes
  16.  *---------------------------------------------------------------------------*/
  17. /* system files */
  18. #include <avr/io.h>
  19. #include <avr/interrupt.h>
  20. #include <stdio.h>
  21. /* lib files */
  22. #include <bios.h>
  23. #include <lcd_HD44780.h>
  24. #include <clcd20x4.h>
  25. /* funcdefs */
  26. //#include <global_funcdefs.h>
  27. #include <eqlazer_funcdefs.h>
  28.  
  29. /* defines */
  30. #define BUFFER_SIZE 20
  31. #define BOUNCE_TIME 10
  32. #define TRUE 1
  33. #define FALSE 0
  34.  
  35. uint8_t currentView = MAIN_VIEW, msg_received = FALSE, encoderPosition, rot = FALSE;
  36. Can_Message_t rxMsg;
  37. uint8_t temperatureData[8], //servoPosition[4], relayStatus[4], dimmerStatus[4],
  38.             temperatureLength=8;//, servoLength=0, relayLength=0;
  39. uint32_t rot_timeStamp;
  40.  
  41. ISR( PCINT2_vect ){
  42.  
  43.     rot_timeStamp = bios->timebase_get();
  44.     rot = TRUE;
  45.     /* stäng av interrupt på pinnarna */
  46.     PCICR &= ~(1<<PCIE2);
  47. }
  48.  
  49. void can_receive(Can_Message_t *msg){
  50.     uint8_t temp;
  51.     /* Check for incoming messages from IR-receiver node */
  52.     if( CLASS_SNS == ((msg->Id & CLASS_MASK) >> CLASS_MASK_BITS) ){
  53.         /* FIXME detta är väldigt fult och borde fixas
  54.          * knapp 4 på fjärren bläddrar åt vänster
  55.          * knapp 6 åt höger
  56.          */
  57.         if( SNS_IR_RECEIVE == (msg->Id & TYPE_MASK)>>TYPE_MASK_BITS){
  58.             if(msg->Data.bytes[0] == 0 && msg->Data.bytes[1] == 0 && msg->Data.bytes[2] == 0){
  59.                 if(msg->Data.bytes[3] == 4 && currentView>0){
  60.                     currentView--;
  61.                     msg_received = TRUE;
  62.                 }else if(msg->Data.bytes[3] == 6 && currentView<LAST_VIEW){
  63.                     currentView++;
  64.                     msg_received = TRUE;
  65.                 }
  66.             }
  67.         }
  68.         /* Other sensor messages should be placed here */
  69.  
  70.         /* DS18S20 sensors */
  71.         if( SNS_TEMP_DS18S20 == (msg->Id & SNS_TYPE_MASK)>>SNS_TYPE_BITS ){
  72.             temp = (msg->Id & SNS_ID_MASK)>>SNS_ID_BITS;
  73.             temperatureData[ temp ] = msg->Data.bytes[0];
  74.             temperatureData[ temp+1 ] = msg->Data.bytes[1];
  75. //          if(temp == 1){
  76. //              lcd_puts("ute ");
  77. //          }
  78.         }
  79.     }
  80. }
  81.  
  82.  
  83. /*-----------------------------------------------------------------------------
  84.  * Main Program
  85.  *---------------------------------------------------------------------------*/
  86. int main(void) {
  87.  
  88.     char buffer[ BUFFER_SIZE ];
  89. //  uint8_t a=0, b=0;
  90. /*  uint8_t m, temperatureData[8], servoPosition[4], relayStatus[4], dimmerStatus[4],
  91.             temperatureLength, servoLength, relayLength;
  92. */
  93.     /*
  94.      * Initialize rotaryencoders and buttons
  95.      */
  96.     /* Set as input and enable pull-up */
  97.     DDRD &= ~( (1<<DDD6)|(1<<DDD7) );
  98. //    PORTD |= (1<<PD6)|(1<<PD7);
  99.     /* Enable IO-pin interrupt */
  100. //    PCICR |= (1<<PCIE2);
  101.     /* Unmask PD6 and PD7 */
  102.     PCMSK2 |= (1<<PCINT22)|(1<<PCINT23);
  103.  
  104.     sei();
  105.     bios->can_callback = &can_receive;
  106.  
  107.     lcd_init( LCD_DISP_ON );
  108.     lcd_clrscr();
  109. //    lcd_puts("CAN LCD\n");
  110.  
  111.     lcd_clrscr();
  112.     printLCDview( MAIN_VIEW );
  113.  
  114.     /* main loop */
  115.     while(1){
  116.         /* check if any messages have been received */
  117.         if(msg_received){
  118.                 /* Print views skeleton and if existing its data */
  119.                 printLCDview( currentView );
  120.                 if(currentView == TEMPSENS_VIEW){
  121.                     printLCDviewData( TEMPSENS_VIEW, temperatureData, temperatureLength);
  122.             //    }else if(currentView == SERVO_VIEW){
  123.             //        printLCDviewData( SERVO_VIEW, servoPosition, servoLength);
  124.                 }
  125.                 msg_received = FALSE;
  126.             }
  127.  
  128.         // TODO använd rotary encoders för att växla view
  129.         // också med fjärrkontroll
  130. /*      if((bios->timebase_get() - rot_timeStamp >= BOUNCE_TIME) && rot == TRUE){
  131.             PCICR |= (1<<PCIE2);
  132.             rot = FALSE;
  133.         }*/
  134.     }
  135.  
  136.  
  137. }
  138.