Go to most recent revision | Details | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 179 | eqlazer | 1 | /** |
| 335 | eqlazer | 2 | * CanCLCD. |
| 179 | eqlazer | 3 | * For HD44780- and KS0073-based LCD displays |
| 335 | eqlazer | 4 | * Prints sensor data and other interesting things. |
| 179 | eqlazer | 5 | * |
| 6 | * @date 2006-12-11 |
||
| 7 | * @author Erik Larsson |
||
| 8 | * |
||
| 9 | * TODO Fix more types of output: relay status, mail recieved etc. |
||
| 10 | * |
||
| 11 | */ |
||
| 12 | |||
| 13 | /*----------------------------------------------------------------------------- |
||
| 14 | * Includes |
||
| 15 | *---------------------------------------------------------------------------*/ |
||
| 16 | /* system files */ |
||
| 17 | #include <avr/io.h> |
||
| 18 | #include <avr/interrupt.h> |
||
| 19 | #include <stdio.h> |
||
| 20 | /* lib files */ |
||
| 332 | eqlazer | 21 | #include <bios.h> |
| 179 | eqlazer | 22 | #include <lcd_HD44780.h> |
| 196 | eqlazer | 23 | #include <clcd20x4.h> |
| 24 | /* funcdefs */ |
||
| 332 | eqlazer | 25 | //#include <global_funcdefs.h> |
| 196 | eqlazer | 26 | #include <eqlazer_funcdefs.h> |
| 179 | eqlazer | 27 | |
| 28 | /* defines */ |
||
| 196 | eqlazer | 29 | #define BUFFER_SIZE 20 |
| 332 | eqlazer | 30 | #define TRUE 1 |
| 31 | #define FALSE 0 |
||
| 179 | eqlazer | 32 | |
| 332 | eqlazer | 33 | Can_Message_t rxMsg; |
| 256 | eqlazer | 34 | |
| 335 | eqlazer | 35 | uint8_t currentView = MAIN_VIEW, |
| 36 | msg_received = FALSE; |
||
| 37 | |||
| 38 | uint8_t temperatureData[8], |
||
| 39 | servoPosition[4], |
||
| 40 | //relayStatus[4], |
||
| 41 | //dimmerStatus[4], |
||
| 42 | temperatureLength = 8, |
||
| 43 | servoLength = 0; |
||
| 44 | //, relayLength=0; //TODO mer generaliserat |
||
| 45 | |||
| 46 | uint8_t rot_lastdir = 0, |
||
| 47 | rot_laststate = 0; |
||
| 48 | |||
| 332 | eqlazer | 49 | ISR( PCINT2_vect ){ |
| 335 | eqlazer | 50 | uint8_t rot_data = 0; |
| 256 | eqlazer | 51 | |
| 335 | eqlazer | 52 | if(PIND&(1<<PD6)){ |
| 53 | rot_data |= 0x01; |
||
| 54 | } |
||
| 55 | if(PIND&(1<<PD7)){ |
||
| 56 | rot_data |= 0x02; |
||
| 57 | } |
||
| 58 | |||
| 59 | if( rot_data==3 && rot_laststate!=3 ){ |
||
| 60 | if( rot_lastdir&0x01 ){ |
||
| 61 | // Moving left |
||
| 62 | if(currentView>0){ |
||
| 63 | currentView--; |
||
| 64 | msg_received = TRUE; |
||
| 65 | } |
||
| 66 | }else{ |
||
| 67 | // Moving right |
||
| 68 | if(currentView<LAST_VIEW){ |
||
| 69 | currentView++; |
||
| 70 | msg_received = TRUE; |
||
| 71 | } |
||
| 72 | } |
||
| 73 | rot_laststate=3; |
||
| 74 | }else if( rot_data==0 && rot_laststate!=0 ){ |
||
| 75 | rot_laststate = 0; |
||
| 76 | }else if( rot_data==1 || rot_data==2 ){ |
||
| 77 | rot_lastdir = rot_data; |
||
| 78 | } |
||
| 332 | eqlazer | 79 | } |
| 179 | eqlazer | 80 | |
| 332 | eqlazer | 81 | void can_receive(Can_Message_t *msg){ |
| 334 | eqlazer | 82 | uint8_t temp, m; |
| 332 | eqlazer | 83 | /* Check for incoming messages from IR-receiver node */ |
| 84 | if( CLASS_SNS == ((msg->Id & CLASS_MASK) >> CLASS_MASK_BITS) ){ |
||
| 85 | /* FIXME detta är väldigt fult och borde fixas |
||
| 86 | * knapp 4 på fjärren bläddrar åt vänster |
||
| 87 | * knapp 6 åt höger |
||
| 88 | */ |
||
| 89 | if( SNS_IR_RECEIVE == (msg->Id & TYPE_MASK)>>TYPE_MASK_BITS){ |
||
| 90 | if(msg->Data.bytes[0] == 0 && msg->Data.bytes[1] == 0 && msg->Data.bytes[2] == 0){ |
||
| 91 | if(msg->Data.bytes[3] == 4 && currentView>0){ |
||
| 92 | currentView--; |
||
| 93 | msg_received = TRUE; |
||
| 94 | }else if(msg->Data.bytes[3] == 6 && currentView<LAST_VIEW){ |
||
| 95 | currentView++; |
||
| 96 | msg_received = TRUE; |
||
| 97 | } |
||
| 98 | } |
||
| 99 | } |
||
| 100 | /* Other sensor messages should be placed here */ |
||
| 179 | eqlazer | 101 | |
| 332 | eqlazer | 102 | /* DS18S20 sensors */ |
| 103 | if( SNS_TEMP_DS18S20 == (msg->Id & SNS_TYPE_MASK)>>SNS_TYPE_BITS ){ |
||
| 104 | temp = (msg->Id & SNS_ID_MASK)>>SNS_ID_BITS; |
||
| 334 | eqlazer | 105 | temperatureData[ (temp-1)*2 ] = msg->Data.bytes[0]; |
| 106 | temperatureData[ (temp-1)*2+1 ] = msg->Data.bytes[1]; |
||
| 332 | eqlazer | 107 | } |
| 334 | eqlazer | 108 | |
| 109 | /* Servo controllers */ |
||
| 110 | if( SNS_ACT_STATUS_SERVO == (msg->Id & TYPE_MASK)>>TYPE_MASK_BITS ){ // TODO annan struktur på statusmeddelanden från servo |
||
| 111 | temp = msg->DataLength - 3; |
||
| 112 | for(m=0;m<temp;m++){ |
||
| 113 | servoPosition[ m ] = msg->Data.bytes[m+3]; |
||
| 114 | } |
||
| 115 | servoLength = temp; |
||
| 116 | } |
||
| 117 | |||
| 332 | eqlazer | 118 | } |
| 119 | } |
||
| 120 | |||
| 121 | |||
| 179 | eqlazer | 122 | /*----------------------------------------------------------------------------- |
| 123 | * Main Program |
||
| 124 | *---------------------------------------------------------------------------*/ |
||
| 125 | int main(void) { |
||
| 126 | |||
| 127 | char buffer[ BUFFER_SIZE ]; |
||
| 335 | eqlazer | 128 | /* |
| 129 | * Initialize rotaryencoders and buttons |
||
| 130 | */ |
||
| 131 | /* Set as input */ |
||
| 132 | DDRD &= ~( (1<<DDD6)|(1<<DDD7) ); |
||
| 133 | /* Enable IO-pin interrupt */ |
||
| 134 | PCICR |= (1<<PCIE2); |
||
| 135 | /* Unmask PD6 and PD7 */ |
||
| 136 | PCMSK2 |= (1<<PCINT22)|(1<<PCINT23); |
||
| 179 | eqlazer | 137 | |
| 335 | eqlazer | 138 | sei(); |
| 332 | eqlazer | 139 | bios->can_callback = &can_receive; |
| 256 | eqlazer | 140 | |
| 332 | eqlazer | 141 | lcd_init( LCD_DISP_ON ); |
| 142 | lcd_clrscr(); |
||
| 179 | eqlazer | 143 | |
| 144 | lcd_clrscr(); |
||
| 256 | eqlazer | 145 | printLCDview( MAIN_VIEW ); |
| 179 | eqlazer | 146 | |
| 147 | /* main loop */ |
||
| 332 | eqlazer | 148 | while(1){ |
| 149 | /* check if any messages have been received */ |
||
| 150 | if(msg_received){ |
||
| 256 | eqlazer | 151 | /* Print views skeleton and if existing its data */ |
| 334 | eqlazer | 152 | printLCDview( currentView ); |
| 153 | if(currentView == TEMPSENS_VIEW){ |
||
| 154 | printLCDviewData( TEMPSENS_VIEW, temperatureData, temperatureLength); |
||
| 155 | }else if(currentView == SERVO_VIEW){ |
||
| 156 | printLCDviewData( SERVO_VIEW, servoPosition, servoLength); |
||
| 157 | } |
||
| 158 | msg_received = FALSE; |
||
| 159 | } |
||
| 332 | eqlazer | 160 | } |
| 179 | eqlazer | 161 | } |