Subversion Repositories HomeAutomation

Rev

Rev 332 | Rev 335 | 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; //TODO mer generaliserat
  39. uint32_t rot_timeStamp;
  40. char buf[10];
  41.  
  42. ISR( PCINT2_vect ){
  43.  
  44.     rot_timeStamp = bios->timebase_get();
  45.     rot = TRUE;
  46.     /* stäng av interrupt på pinnarna */
  47.     PCICR &= ~(1<<PCIE2);
  48. }
  49.  
  50. void can_receive(Can_Message_t *msg){
  51.     uint8_t temp, m;
  52.     /* Check for incoming messages from IR-receiver node */
  53.     if( CLASS_SNS == ((msg->Id & CLASS_MASK) >> CLASS_MASK_BITS) ){
  54.         /* FIXME detta är väldigt fult och borde fixas
  55.          * knapp 4 på fjärren bläddrar åt vänster
  56.          * knapp 6 åt höger
  57.          */
  58.         if( SNS_IR_RECEIVE == (msg->Id & TYPE_MASK)>>TYPE_MASK_BITS){
  59.             if(msg->Data.bytes[0] == 0 && msg->Data.bytes[1] == 0 && msg->Data.bytes[2] == 0){
  60.                 if(msg->Data.bytes[3] == 4 && currentView>0){
  61.                     currentView--;
  62.                     msg_received = TRUE;
  63.                 }else if(msg->Data.bytes[3] == 6 && currentView<LAST_VIEW){
  64.                     currentView++;
  65.                     msg_received = TRUE;
  66.                 }
  67.             }
  68.         }
  69.         /* Other sensor messages should be placed here */
  70.  
  71.         /* DS18S20 sensors */
  72.         if( SNS_TEMP_DS18S20 == (msg->Id & SNS_TYPE_MASK)>>SNS_TYPE_BITS ){
  73.             temp = (msg->Id & SNS_ID_MASK)>>SNS_ID_BITS;
  74.             temperatureData[ (temp-1)*2 ] = msg->Data.bytes[0];
  75.             temperatureData[ (temp-1)*2+1 ] = msg->Data.bytes[1];
  76.         }
  77.  
  78.         /* Servo controllers */
  79.         if( SNS_ACT_STATUS_SERVO == (msg->Id & TYPE_MASK)>>TYPE_MASK_BITS ){ // TODO annan struktur på statusmeddelanden från servo
  80.             temp = msg->DataLength - 3;
  81.             for(m=0;m<temp;m++){
  82.                 servoPosition[ m ] = msg->Data.bytes[m+3];
  83.             }
  84.             servoLength = temp;
  85.         }
  86.  
  87.     }
  88. }
  89.  
  90.  
  91. /*-----------------------------------------------------------------------------
  92.  * Main Program
  93.  *---------------------------------------------------------------------------*/
  94. int main(void) {
  95.  
  96.     char buffer[ BUFFER_SIZE ];
  97.     /*
  98.      * Initialize rotaryencoders and buttons
  99.      */
  100.     /* Set as input and enable pull-up */
  101.     DDRD &= ~( (1<<DDD6)|(1<<DDD7) );
  102. //    PORTD |= (1<<PD6)|(1<<PD7);
  103.     /* Enable IO-pin interrupt */
  104. //    PCICR |= (1<<PCIE2);
  105.     /* Unmask PD6 and PD7 */
  106.     PCMSK2 |= (1<<PCINT22)|(1<<PCINT23);
  107.  
  108.     sei();
  109.     bios->can_callback = &can_receive;
  110.  
  111.     lcd_init( LCD_DISP_ON );
  112.     lcd_clrscr();
  113.  
  114.     lcd_clrscr();
  115.     printLCDview( MAIN_VIEW );
  116.  
  117.     /* main loop */
  118.     while(1){
  119.         /* check if any messages have been received */
  120.         if(msg_received){
  121.                 /* Print views skeleton and if existing its data */
  122.             printLCDview( currentView );
  123.             if(currentView == TEMPSENS_VIEW){
  124.                 printLCDviewData( TEMPSENS_VIEW, temperatureData, temperatureLength);
  125.             }else if(currentView == SERVO_VIEW){
  126.                 printLCDviewData( SERVO_VIEW, servoPosition, servoLength);
  127.             }
  128.             msg_received = FALSE;
  129.         }
  130.  
  131.         // TODO använd rotary encoders för att växla view
  132.         // också med fjärrkontroll
  133. /*      if((bios->timebase_get() - rot_timeStamp >= BOUNCE_TIME) && rot == TRUE){
  134.             PCICR |= (1<<PCIE2);
  135.             rot = FALSE;
  136.         }*/
  137.     }
  138.  
  139.  
  140. }
  141.