Rev 334 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 334 | Rev 335 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | /** |
1 | /** |
| 2 | * |
2 | * CanCLCD. |
| 3 | * For HD44780- and KS0073-based LCD displays |
3 | * For HD44780- and KS0073-based LCD displays |
| 4 | * |
4 | * Prints sensor data and other interesting things. |
| 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 |
- | |
| 11 | * |
10 | * |
| 12 | */ |
11 | */ |
| 13 | 12 | ||
| 14 | /*----------------------------------------------------------------------------- |
13 | /*----------------------------------------------------------------------------- |
| 15 | * Includes |
14 | * Includes |
| Line 26... | Line 25... | ||
| 26 | //#include <global_funcdefs.h> |
25 | //#include <global_funcdefs.h> |
| 27 | #include <eqlazer_funcdefs.h> |
26 | #include <eqlazer_funcdefs.h> |
| 28 | 27 | ||
| 29 | /* defines */ |
28 | /* defines */ |
| 30 | #define BUFFER_SIZE 20 |
29 | #define BUFFER_SIZE 20 |
| 31 | #define BOUNCE_TIME 10 |
- | |
| 32 | #define TRUE 1 |
30 | #define TRUE 1 |
| 33 | #define FALSE 0 |
31 | #define FALSE 0 |
| 34 | 32 | ||
| 35 | uint8_t currentView = MAIN_VIEW, msg_received = FALSE, encoderPosition, rot = FALSE; |
- | |
| 36 | Can_Message_t rxMsg; |
33 | Can_Message_t rxMsg; |
| - | 34 | ||
| - | 35 | uint8_t currentView = MAIN_VIEW, |
|
| - | 36 | msg_received = FALSE; |
|
| - | 37 | ||
| 37 | uint8_t temperatureData[8] |
38 | uint8_t temperatureData[8], |
| - | 39 | servoPosition[4], |
|
| - | 40 | //relayStatus[4], |
|
| - | 41 | //dimmerStatus[4], |
|
| - | 42 | temperatureLength = 8, |
|
| - | 43 | servoLength = 0; |
|
| 38 |
|
44 | //, relayLength=0; //TODO mer generaliserat |
| - | 45 | ||
| 39 |
|
46 | uint8_t rot_lastdir = 0, |
| 40 |
|
47 | rot_laststate = 0; |
| 41 | 48 | ||
| 42 | ISR( PCINT2_vect ){ |
49 | ISR( PCINT2_vect ){ |
| - | 50 | uint8_t rot_data = 0; |
|
| 43 | 51 | ||
| - | 52 | if(PIND&(1<<PD6)){ |
|
| - | 53 | rot_data |= 0x01; |
|
| - | 54 | } |
|
| - | 55 | if(PIND&(1<<PD7)){ |
|
| - | 56 | rot_data |= 0x02; |
|
| - | 57 | } |
|
| - | 58 | ||
| 44 |
|
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++; |
|
| 45 |
|
70 | msg_received = TRUE; |
| - | 71 | } |
|
| - | 72 | } |
|
| - | 73 | rot_laststate=3; |
|
| - | 74 | }else if( rot_data==0 && rot_laststate!=0 ){ |
|
| - | 75 | rot_laststate = 0; |
|
| 46 |
|
76 | }else if( rot_data==1 || rot_data==2 ){ |
| 47 |
|
77 | rot_lastdir = rot_data; |
| - | 78 | } |
|
| 48 | } |
79 | } |
| 49 | 80 | ||
| 50 | void can_receive(Can_Message_t *msg){ |
81 | void can_receive(Can_Message_t *msg){ |
| 51 | uint8_t temp, m; |
82 | uint8_t temp, m; |
| 52 | /* Check for incoming messages from IR-receiver node */ |
83 | /* Check for incoming messages from IR-receiver node */ |
| Line 92... | Line 123... | ||
| 92 | * Main Program |
123 | * Main Program |
| 93 | *---------------------------------------------------------------------------*/ |
124 | *---------------------------------------------------------------------------*/ |
| 94 | int main(void) { |
125 | int main(void) { |
| 95 | 126 | ||
| 96 | char buffer[ BUFFER_SIZE ]; |
127 | char buffer[ BUFFER_SIZE ]; |
| 97 | /* |
128 | /* |
| 98 | * Initialize rotaryencoders and buttons |
129 | * Initialize rotaryencoders and buttons |
| 99 | */ |
130 | */ |
| 100 | /* Set as input |
131 | /* Set as input */ |
| 101 | DDRD &= ~( (1<<DDD6)|(1<<DDD7) ); |
132 | DDRD &= ~( (1<<DDD6)|(1<<DDD7) ); |
| 102 | // PORTD |= (1<<PD6)|(1<<PD7); |
- | |
| 103 | /* Enable IO-pin interrupt */ |
133 | /* Enable IO-pin interrupt */ |
| 104 |
|
134 | PCICR |= (1<<PCIE2); |
| 105 | /* Unmask PD6 and PD7 */ |
135 | /* Unmask PD6 and PD7 */ |
| 106 | PCMSK2 |= (1<<PCINT22)|(1<<PCINT23); |
136 | PCMSK2 |= (1<<PCINT22)|(1<<PCINT23); |
| 107 | 137 | ||
| 108 | sei(); |
138 | sei(); |
| 109 | bios->can_callback = &can_receive; |
139 | bios->can_callback = &can_receive; |
| 110 | 140 | ||
| 111 | lcd_init( LCD_DISP_ON ); |
141 | lcd_init( LCD_DISP_ON ); |
| 112 | lcd_clrscr(); |
142 | lcd_clrscr(); |
| 113 | 143 | ||
| Line 125... | Line 155... | ||
| 125 | }else if(currentView == SERVO_VIEW){ |
155 | }else if(currentView == SERVO_VIEW){ |
| 126 | printLCDviewData( SERVO_VIEW, servoPosition, servoLength); |
156 | printLCDviewData( SERVO_VIEW, servoPosition, servoLength); |
| 127 | } |
157 | } |
| 128 | msg_received = FALSE; |
158 | msg_received = FALSE; |
| 129 | } |
159 | } |
| 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 | } |
160 | } |
| 138 | - | ||
| 139 | - | ||
| 140 | } |
161 | } |