Rev 256 | Rev 334 | Go to most recent revision | Details | Compare with Previous | 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; |
||
| 37 | uint8_t temperatureData[8], //servoPosition[4], relayStatus[4], dimmerStatus[4], |
||
| 38 | temperatureLength=8;//, servoLength=0, relayLength=0; |
||
| 39 | uint32_t rot_timeStamp; |
||
| 256 | eqlazer | 40 | |
| 332 | eqlazer | 41 | ISR( PCINT2_vect ){ |
| 256 | eqlazer | 42 | |
| 332 | eqlazer | 43 | rot_timeStamp = bios->timebase_get(); |
| 44 | rot = TRUE; |
||
| 45 | /* stäng av interrupt på pinnarna */ |
||
| 46 | PCICR &= ~(1<<PCIE2); |
||
| 47 | } |
||
| 179 | eqlazer | 48 | |
| 332 | eqlazer | 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 */ |
||
| 179 | eqlazer | 69 | |
| 332 | eqlazer | 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 | |||
| 179 | eqlazer | 83 | /*----------------------------------------------------------------------------- |
| 84 | * Main Program |
||
| 85 | *---------------------------------------------------------------------------*/ |
||
| 86 | int main(void) { |
||
| 87 | |||
| 88 | char buffer[ BUFFER_SIZE ]; |
||
| 332 | eqlazer | 89 | // uint8_t a=0, b=0; |
| 90 | /* uint8_t m, temperatureData[8], servoPosition[4], relayStatus[4], dimmerStatus[4], |
||
| 91 | temperatureLength, servoLength, relayLength; |
||
| 92 | */ |
||
| 196 | eqlazer | 93 | /* |
| 332 | eqlazer | 94 | * Initialize rotaryencoders and buttons |
| 196 | eqlazer | 95 | */ |
| 332 | eqlazer | 96 | /* Set as input and enable pull-up */ |
| 196 | eqlazer | 97 | DDRD &= ~( (1<<DDD6)|(1<<DDD7) ); |
| 332 | eqlazer | 98 | // PORTD |= (1<<PD6)|(1<<PD7); |
| 196 | eqlazer | 99 | /* Enable IO-pin interrupt */ |
| 332 | eqlazer | 100 | // PCICR |= (1<<PCIE2); |
| 196 | eqlazer | 101 | /* Unmask PD6 and PD7 */ |
| 102 | PCMSK2 |= (1<<PCINT22)|(1<<PCINT23); |
||
| 179 | eqlazer | 103 | |
| 196 | eqlazer | 104 | sei(); |
| 332 | eqlazer | 105 | bios->can_callback = &can_receive; |
| 256 | eqlazer | 106 | |
| 332 | eqlazer | 107 | lcd_init( LCD_DISP_ON ); |
| 108 | lcd_clrscr(); |
||
| 109 | // lcd_puts("CAN LCD\n"); |
||
| 179 | eqlazer | 110 | |
| 111 | lcd_clrscr(); |
||
| 256 | eqlazer | 112 | printLCDview( MAIN_VIEW ); |
| 179 | eqlazer | 113 | |
| 114 | /* main loop */ |
||
| 332 | eqlazer | 115 | while(1){ |
| 116 | /* check if any messages have been received */ |
||
| 117 | if(msg_received){ |
||
| 256 | eqlazer | 118 | /* Print views skeleton and if existing its data */ |
| 119 | printLCDview( currentView ); |
||
| 120 | if(currentView == TEMPSENS_VIEW){ |
||
| 121 | printLCDviewData( TEMPSENS_VIEW, temperatureData, temperatureLength); |
||
| 332 | eqlazer | 122 | // }else if(currentView == SERVO_VIEW){ |
| 123 | // printLCDviewData( SERVO_VIEW, servoPosition, servoLength); |
||
| 256 | eqlazer | 124 | } |
| 332 | eqlazer | 125 | msg_received = FALSE; |
| 256 | eqlazer | 126 | } |
| 179 | eqlazer | 127 | |
| 332 | eqlazer | 128 | // TODO använd rotary encoders för att växla view |
| 256 | eqlazer | 129 | // också med fjärrkontroll |
| 332 | eqlazer | 130 | /* if((bios->timebase_get() - rot_timeStamp >= BOUNCE_TIME) && rot == TRUE){ |
| 131 | PCICR |= (1<<PCIE2); |
||
| 132 | rot = FALSE; |
||
| 133 | }*/ |
||
| 134 | } |
||
| 179 | eqlazer | 135 | |
| 136 | |||
| 137 | } |