Rev 196 | Rev 332 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 196 | Rev 256 | ||
|---|---|---|---|
| Line 9... | Line 9... | ||
| 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 | #define DEBUG |
14 | #define DEBUG 0 |
| 15 | 15 | ||
| 16 | /*----------------------------------------------------------------------------- |
16 | /*----------------------------------------------------------------------------- |
| 17 | * Includes |
17 | * Includes |
| 18 | *---------------------------------------------------------------------------*/ |
18 | *---------------------------------------------------------------------------*/ |
| 19 | /* system files */ |
19 | /* system files */ |
| Line 31... | Line 31... | ||
| 31 | #include <global_funcdefs.h> |
31 | #include <global_funcdefs.h> |
| 32 | #include <eqlazer_funcdefs.h> |
32 | #include <eqlazer_funcdefs.h> |
| 33 | 33 | ||
| 34 | /* defines */ |
34 | /* defines */ |
| 35 | #define BUFFER_SIZE 20 |
35 | #define BUFFER_SIZE 20 |
| - | 36 | ||
| - | 37 | #define LCD_CMD_GET 0x1600 |
|
| - | 38 | #define VIEW_LEFT 0x01 |
|
| - | 39 | #define VIEW_RIGHT 0x02 |
|
| - | 40 | #define VIEW_EDIT 0x03 |
|
| - | 41 | ||
| 36 | 42 | ||
| 37 | uint8_t currentView = MAIN_VIEW; |
43 | uint8_t currentView = MAIN_VIEW; |
| 38 | /*static const PROGMEM unsigned char symbolThermometer[] = |
- | |
| 39 | { |
- | |
| 40 | 0x04, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0E, 0x0E, |
- | |
| 41 | 0x0E, 0x0E, 0x0E, 0x0A, 0x11, 0x11, 0x0A, 0x04 |
- | |
| 42 | };*/ // TODO behövs symbol för termometer? |
- | |
| 43 | 44 | ||
| 44 | // TODO ISR() för att använda optoencoders |
45 | // TODO ISR() för att använda optoencoders |
| 45 | ISR( PCINT2_vect ){ |
46 | ISR( PCINT2_vect ){ |
| 46 | // TODO do the magic stuff |
47 | // TODO do the magic stuff |
| 47 | // vriden medurs currentView++ |
48 | // vriden medurs currentView++ |
| Line 52... | Line 53... | ||
| 52 | * Main Program |
53 | * Main Program |
| 53 | *---------------------------------------------------------------------------*/ |
54 | *---------------------------------------------------------------------------*/ |
| 54 | int main(void) { |
55 | int main(void) { |
| 55 | 56 | ||
| 56 | char buffer[ BUFFER_SIZE ]; |
57 | char buffer[ BUFFER_SIZE ]; |
| 57 | uint8_t |
58 | uint8_t m, temperatureData[8], servoPosition[4], relayStatus[4], dimmerStatus[4], |
| 58 |
|
59 | temperatureLength, servoLength; |
| 59 | 60 | ||
| 60 | /* |
61 | /* |
| 61 | * Initialize optoencoders and buttons |
62 | * Initialize optoencoders and buttons |
| 62 | */ |
63 | */ |
| 63 | /* Set as input and enable pull-up */ // TODO fixa rätt ingångar |
64 | /* Set as input and enable pull-up */ // TODO fixa rätt ingångar |
| Line 73... | Line 74... | ||
| 73 | #if DEBUG |
74 | #if DEBUG |
| 74 | Serial_Init(); |
75 | Serial_Init(); |
| 75 | #endif |
76 | #endif |
| 76 | sei(); |
77 | sei(); |
| 77 | lcd_init( LCD_DISP_ON ); |
78 | lcd_init( LCD_DISP_ON ); |
| 78 | #if DEBUG |
- | |
| 79 | printf("\n------------------------------------------------------------\n"); |
- | |
| 80 | printf( " CAN LCD\n"); |
- | |
| 81 | printf( "------------------------------------------------------------\n"); |
- | |
| 82 | #endif |
- | |
| 83 | lcd_clrscr(); |
79 | lcd_clrscr(); |
| 84 | lcd_puts("CAN LCD test\n"); |
80 | lcd_puts("CAN LCD test\n"); |
| 85 | #if DEBUG |
- | |
| 86 | printf("CanInit..."); |
- | |
| 87 | lcd_puts("CanInit... "); |
81 | lcd_puts("CanInit... "); |
| 88 | if (Can_Init() != CAN_OK) { |
- | |
| 89 | printf("FAILED!\n"); |
- | |
| 90 | lcd_puts("FAILED!\n"); |
- | |
| 91 | } |
- | |
| 92 | else { |
- | |
| 93 | printf("OK!\n"); |
- | |
| 94 | lcd_puts("OK!\n"); |
- | |
| 95 | } |
- | |
| 96 | #else |
- | |
| 97 | lcd_puts("CanInit... "); |
- | |
| 98 | if (Can_Init() != CAN_OK) { |
82 | if (Can_Init() != CAN_OK) { |
| 99 | lcd_puts("FAILED!\n"); |
83 | lcd_puts("FAILED!\n"); |
| 100 | }else{ |
84 | }else{ |
| 101 | lcd_puts("OK!\n"); |
85 | lcd_puts("OK!\n"); |
| 102 | } |
86 | } |
| 103 | #endif |
87 | |
| 104 | uint32_t timeStamp = 0; |
88 | uint32_t timeStamp = 0; |
| 105 | 89 | ||
| 106 | Can_Message_t txMsg; |
90 | Can_Message_t txMsg; |
| 107 | Can_Message_t rxMsg; |
91 | Can_Message_t rxMsg; |
| 108 | txMsg.Id = 0; |
92 | txMsg.Id = 0; |
| 109 | txMsg.RemoteFlag = 0; |
93 | txMsg.RemoteFlag = 0; |
| 110 | txMsg.ExtendedFlag = 1; |
94 | txMsg.ExtendedFlag = 1; |
| 111 | 95 | ||
| 112 | lcd_clrscr(); |
96 | lcd_clrscr(); |
| - | 97 | printLCDview( MAIN_VIEW ); |
|
| 113 | 98 | ||
| 114 | /* main loop */ |
99 | /* main loop */ |
| 115 | while (1) { |
100 | while (1) { |
| 116 | /* service the CAN routines */ |
101 | /* service the CAN routines */ |
| 117 | Can_Service(); |
102 | Can_Service(); |
| Line 126... | Line 111... | ||
| 126 | printf("%x ", rxMsg.Data.bytes[i]); |
111 | printf("%x ", rxMsg.Data.bytes[i]); |
| 127 | } |
112 | } |
| 128 | printf("}\n"); |
113 | printf("}\n"); |
| 129 | #endif |
114 | #endif |
| 130 | /* Get data from bus and store */ |
115 | /* Get data from bus and store */ |
| 131 | if( rxMsg.Id == |
116 | if( rxMsg.Id == 0x1502 ){ |
| 132 | /* Temperature sensor data */ |
117 | /* Temperature sensor data */ |
| 133 | for(m=0; m<rxMsg.DataLength; m++){ |
118 | for(m=0; m<rxMsg.DataLength; m++){ |
| 134 | temperatureData[m] = rxMsg.Data.bytes[m]; |
119 | temperatureData[m] = rxMsg.Data.bytes[m]; |
| - | 120 | temperatureLength = rxMsg.DataLength; |
|
| 135 | } |
121 | } |
| 136 | }else if( rxMsg.Id == 0x1201 ){ |
122 | }else if( rxMsg.Id == 0x1201 ){ |
| 137 | /* Relay status (ON/OFF) */ |
123 | /* Relay status (ON/OFF) */ |
| 138 | relayStatus[1] = rxMsg.Data.bytes[2]; |
124 | relayStatus[1] = rxMsg.Data.bytes[2]; |
| - | 125 | }else if( rxMsg.Id == 0x1301){ |
|
| 139 |
|
126 | /* Servo and blinds status */ |
| - | 127 | for( m=3; m<rxMsg.DataLength; m++ ){ |
|
| - | 128 | servoPosition[m-3] = rxMsg.Data.bytes[m]; |
|
| - | 129 | servoLength=rxMsg.DataLength-3; |
|
| 140 | } |
130 | } |
| - | 131 | } |
|
| - | 132 | /* TODO Add extra messages here */ |
|
| 141 | 133 | ||
| - | 134 | /* Incoming command to change view */ |
|
| - | 135 | if(rxMsg.Id == LCD_CMD_GET){ |
|
| - | 136 | if(rxMsg.Data.bytes[0]== VIEW_LEFT){ |
|
| - | 137 | if(currentView>MAIN_VIEW){ |
|
| - | 138 | currentView--; |
|
| 142 |
|
139 | } |
| - | 140 | }else if(rxMsg.Data.bytes[0]== VIEW_RIGHT){ |
|
| - | 141 | if(currentView<SERVO_VIEW){ /* TODO increase value if you add views */ |
|
| - | 142 | currentView++; |
|
| - | 143 | } |
|
| - | 144 | } |
|
| - | 145 | ||
| - | 146 | /* Print views skeleton and if existing its data */ |
|
| - | 147 | printLCDview( currentView ); |
|
| - | 148 | if(currentView == TEMPSENS_VIEW){ |
|
| - | 149 | printLCDviewData( TEMPSENS_VIEW, temperatureData, temperatureLength); |
|
| - | 150 | }else if(currentView == SERVO_VIEW){ |
|
| - | 151 | printLCDviewData( SERVO_VIEW, servoPosition, servoLength); |
|
| - | 152 | } |
|
| - | 153 | } |
|
| - | 154 | } |
|
| - | 155 | ||
| 143 | // TODO använd optoencoders för att växla view |
156 | // TODO använd optoencoders för att växla view |
| 144 |
|
157 | // också med fjärrkontroll |
| 145 | 158 | ||
| 146 | } |
159 | } |
| 147 | 160 | ||
| 148 | return 0; |
161 | |
| 149 | } |
162 | } |