Go to most recent revision | Details | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 179 | eqlazer | 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 */ |
||
| 332 | eqlazer | 22 | #include <bios.h> |
| 179 | eqlazer | 23 | #include <lcd_HD44780.h> |
| 196 | eqlazer | 24 | #include <clcd20x4.h> |
| 25 | /* funcdefs */ |
||
| 332 | eqlazer | 26 | //#include <global_funcdefs.h> |
| 196 | eqlazer | 27 | #include <eqlazer_funcdefs.h> |
| 179 | eqlazer | 28 | |
| 29 | /* defines */ |
||
| 196 | eqlazer | 30 | #define BUFFER_SIZE 20 |
| 332 | eqlazer | 31 | #define BOUNCE_TIME 10 |
| 32 | #define TRUE 1 |
||
| 33 | #define FALSE 0 |
||
| 179 | eqlazer | 34 | |
| 332 | eqlazer | 35 | uint8_t currentView = MAIN_VIEW, msg_received = FALSE, encoderPosition, rot = FALSE; |
| 36 | Can_Message_t rxMsg; |
||
| 334 | eqlazer | 37 | uint8_t temperatureData[8], servoPosition[4], //relayStatus[4], dimmerStatus[4], |
| 38 | temperatureLength = 8, servoLength = 0; //, relayLength=0; //TODO mer generaliserat |
||
| 332 | eqlazer | 39 | uint32_t rot_timeStamp; |
| 334 | eqlazer | 40 | char buf[10]; |
| 256 | eqlazer | 41 | |
| 332 | eqlazer | 42 | ISR( PCINT2_vect ){ |
| 256 | eqlazer | 43 | |
| 332 | eqlazer | 44 | rot_timeStamp = bios->timebase_get(); |
| 45 | rot = TRUE; |
||
| 46 | /* stäng av interrupt på pinnarna */ |
||
| 47 | PCICR &= ~(1<<PCIE2); |
||
| 48 | } |
||
| 179 | eqlazer | 49 | |
| 332 | eqlazer | 50 | void can_receive(Can_Message_t *msg){ |
| 334 | eqlazer | 51 | uint8_t temp, m; |
| 332 | eqlazer | 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 */ |
||
| 179 | eqlazer | 70 | |
| 332 | eqlazer | 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; |
||
| 334 | eqlazer | 74 | temperatureData[ (temp-1)*2 ] = msg->Data.bytes[0]; |
| 75 | temperatureData[ (temp-1)*2+1 ] = msg->Data.bytes[1]; |
||
| 332 | eqlazer | 76 | } |
| 334 | eqlazer | 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 | |||
| 332 | eqlazer | 87 | } |
| 88 | } |
||
| 89 | |||
| 90 | |||
| 179 | eqlazer | 91 | /*----------------------------------------------------------------------------- |
| 92 | * Main Program |
||
| 93 | *---------------------------------------------------------------------------*/ |
||
| 94 | int main(void) { |
||
| 95 | |||
| 96 | char buffer[ BUFFER_SIZE ]; |
||
| 196 | eqlazer | 97 | /* |
| 332 | eqlazer | 98 | * Initialize rotaryencoders and buttons |
| 196 | eqlazer | 99 | */ |
| 332 | eqlazer | 100 | /* Set as input and enable pull-up */ |
| 196 | eqlazer | 101 | DDRD &= ~( (1<<DDD6)|(1<<DDD7) ); |
| 332 | eqlazer | 102 | // PORTD |= (1<<PD6)|(1<<PD7); |
| 196 | eqlazer | 103 | /* Enable IO-pin interrupt */ |
| 332 | eqlazer | 104 | // PCICR |= (1<<PCIE2); |
| 196 | eqlazer | 105 | /* Unmask PD6 and PD7 */ |
| 106 | PCMSK2 |= (1<<PCINT22)|(1<<PCINT23); |
||
| 179 | eqlazer | 107 | |
| 196 | eqlazer | 108 | sei(); |
| 332 | eqlazer | 109 | bios->can_callback = &can_receive; |
| 256 | eqlazer | 110 | |
| 332 | eqlazer | 111 | lcd_init( LCD_DISP_ON ); |
| 112 | lcd_clrscr(); |
||
| 179 | eqlazer | 113 | |
| 114 | lcd_clrscr(); |
||
| 256 | eqlazer | 115 | printLCDview( MAIN_VIEW ); |
| 179 | eqlazer | 116 | |
| 117 | /* main loop */ |
||
| 332 | eqlazer | 118 | while(1){ |
| 119 | /* check if any messages have been received */ |
||
| 120 | if(msg_received){ |
||
| 256 | eqlazer | 121 | /* Print views skeleton and if existing its data */ |
| 334 | eqlazer | 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 | } |
||
| 179 | eqlazer | 130 | |
| 332 | eqlazer | 131 | // TODO använd rotary encoders för att växla view |
| 256 | eqlazer | 132 | // också med fjärrkontroll |
| 332 | eqlazer | 133 | /* if((bios->timebase_get() - rot_timeStamp >= BOUNCE_TIME) && rot == TRUE){ |
| 134 | PCICR |= (1<<PCIE2); |
||
| 135 | rot = FALSE; |
||
| 136 | }*/ |
||
| 137 | } |
||
| 179 | eqlazer | 138 | |
| 139 | |||
| 140 | } |