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