Rev 179 | Rev 256 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 179 | Rev 196 | ||
|---|---|---|---|
| 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 | /* For eq's testing purpose */ |
- | |
| 15 | #define |
14 | #define DEBUG 1 |
| 16 | 15 | ||
| 17 | /*----------------------------------------------------------------------------- |
16 | /*----------------------------------------------------------------------------- |
| 18 | * Includes |
17 | * Includes |
| 19 | *---------------------------------------------------------------------------*/ |
18 | *---------------------------------------------------------------------------*/ |
| 20 | /* system files */ |
19 | /* system files */ |
| Line 25... | Line 24... | ||
| 25 | /* lib files */ |
24 | /* lib files */ |
| 26 | #include <can.h> |
25 | #include <can.h> |
| 27 | #include <serial.h> |
26 | #include <serial.h> |
| 28 | #include <timebase.h> |
27 | #include <timebase.h> |
| 29 | #include <lcd_HD44780.h> |
28 | #include <lcd_HD44780.h> |
| - | 29 | #include <clcd20x4.h> |
|
| - | 30 | /* funcdefs */ |
|
| - | 31 | #include <global_funcdefs.h> |
|
| - | 32 | #include <eqlazer_funcdefs.h> |
|
| 30 | 33 | ||
| 31 | /* defines */ |
34 | /* defines */ |
| 32 | //#include <global_funcdefs> // TODO in future version use this (first fix the defs) |
- | |
| 33 | - | ||
| 34 | #ifdef EQLAZER |
- | |
| 35 | #include <eqlazer_funcdefs.h> // for eq's personal defs |
- | |
| 36 | #endif |
- | |
| 37 | - | ||
| 38 | #define BUFFER_SIZE 20 |
35 | #define BUFFER_SIZE 20 |
| 39 | 36 | ||
| - | 37 | 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 | // TODO ISR() för att använda optoencoders |
|
| - | 45 | ISR( PCINT2_vect ){ |
|
| - | 46 | // TODO do the magic stuff |
|
| - | 47 | // vriden medurs currentView++ |
|
| - | 48 | // moturs currentView-- |
|
| - | 49 | } // TODO lägga denna koden i ett eget lib? |
|
| - | 50 | ||
| 40 | /*----------------------------------------------------------------------------- |
51 | /*----------------------------------------------------------------------------- |
| 41 | * Main Program |
52 | * Main Program |
| 42 | *---------------------------------------------------------------------------*/ |
53 | *---------------------------------------------------------------------------*/ |
| 43 | int main(void) { |
54 | int main(void) { |
| 44 | 55 | ||
| 45 | char buffer[ BUFFER_SIZE ]; |
56 | char buffer[ BUFFER_SIZE ]; |
| 46 | uint8_t subzero; |
57 | uint8_t subzero; // TODO städa upp |
| - | 58 | uint8_t m, temperatureData[8], relayStatus[4], dimmerStatus[4]; |
|
| - | 59 | ||
| - | 60 | /* |
|
| - | 61 | * Initialize optoencoders and buttons |
|
| - | 62 | */ |
|
| - | 63 | /* Set as input and enable pull-up */ // TODO fixa rätt ingångar |
|
| - | 64 | DDRD &= ~( (1<<DDD6)|(1<<DDD7) ); |
|
| - | 65 | PORTD |= (1<<PD6)|(1<<PD7); |
|
| - | 66 | /* Enable IO-pin interrupt */ |
|
| - | 67 | PCICR |= (1<<PCIE1); |
|
| - | 68 | /* Unmask PD6 and PD7 */ |
|
| - | 69 | PCMSK2 |= (1<<PCINT22)|(1<<PCINT23); |
|
| - | 70 | ||
| 47 | 71 | ||
| 48 | Timebase_Init(); |
72 | Timebase_Init(); |
| - | 73 | #if DEBUG |
|
| 49 | Serial_Init(); |
74 | Serial_Init(); |
| - | 75 | #endif |
|
| 50 | sei(); |
76 | sei(); |
| 51 | lcd_init( LCD_DISP_ON ); |
77 | lcd_init( LCD_DISP_ON ); |
| 52 | 78 | #if DEBUG |
|
| 53 | printf("\n------------------------------------------------------------\n"); |
79 | printf("\n------------------------------------------------------------\n"); |
| 54 | printf( " CAN LCD\n"); |
80 | printf( " CAN LCD\n"); |
| 55 | printf( "------------------------------------------------------------\n"); |
81 | printf( "------------------------------------------------------------\n"); |
| 56 | 82 | #endif |
|
| 57 | lcd_clrscr(); |
83 | lcd_clrscr(); |
| 58 | lcd_puts("CAN LCD test\n"); |
84 | lcd_puts("CAN LCD test\n"); |
| 59 | 85 | #if DEBUG |
|
| 60 | printf("CanInit..."); |
86 | printf("CanInit..."); |
| 61 | lcd_puts("CanInit... "); |
87 | lcd_puts("CanInit... "); |
| 62 | if (Can_Init() != CAN_OK) { |
88 | if (Can_Init() != CAN_OK) { |
| 63 | printf("FAILED!\n"); |
89 | printf("FAILED!\n"); |
| 64 | lcd_puts("FAILED!\n"); |
90 | lcd_puts("FAILED!\n"); |
| 65 | } |
91 | } |
| 66 | else { |
92 | else { |
| 67 | printf("OK!\n"); |
93 | printf("OK!\n"); |
| 68 | lcd_puts("OK!\n"); |
94 | lcd_puts("OK!\n"); |
| 69 | } |
95 | } |
| - | 96 | #else |
|
| - | 97 | lcd_puts("CanInit... "); |
|
| - | 98 | if (Can_Init() != CAN_OK) { |
|
| - | 99 | lcd_puts("FAILED!\n"); |
|
| - | 100 | }else{ |
|
| - | 101 | lcd_puts("OK!\n"); |
|
| 70 | 102 | } |
|
| - | 103 | #endif |
|
| 71 | uint32_t timeStamp = 0; |
104 | uint32_t timeStamp = 0; |
| 72 | 105 | ||
| 73 | Can_Message_t txMsg; |
106 | Can_Message_t txMsg; |
| 74 | Can_Message_t rxMsg; |
107 | Can_Message_t rxMsg; |
| 75 | txMsg.Id = 0; |
108 | txMsg.Id = 0; |
| Line 83... | Line 116... | ||
| 83 | /* service the CAN routines */ |
116 | /* service the CAN routines */ |
| 84 | Can_Service(); |
117 | Can_Service(); |
| 85 | 118 | ||
| 86 | /* check if any messages have been received and print to uart */ |
119 | /* check if any messages have been received and print to uart */ |
| 87 | while (Can_Receive(&rxMsg) == CAN_OK) { |
120 | while (Can_Receive(&rxMsg) == CAN_OK) { |
| - | 121 | #if DEBUG |
|
| 88 | printf("MSG Received: ID=%lx, DLC=%u, EXT=%u, RTR=%u, ", rxMsg.Id, (uint16_t)(rxMsg.DataLength), (uint16_t)(rxMsg.ExtendedFlag), (uint16_t)(rxMsg.RemoteFlag)); |
122 | printf("MSG Received: ID=%lx, DLC=%u, EXT=%u, RTR=%u, ", rxMsg.Id, (uint16_t)(rxMsg.DataLength), (uint16_t)(rxMsg.ExtendedFlag), (uint16_t)(rxMsg.RemoteFlag)); |
| 89 | printf("data={ "); |
123 | printf("data={ "); |
| 90 | 124 | ||
| 91 | for (uint8_t i=0; i<rxMsg.DataLength; i++) { |
125 | for (uint8_t i=0; i<rxMsg.DataLength; i++) { |
| 92 | printf("%x ", rxMsg.Data.bytes[i]); |
126 | printf("%x ", rxMsg.Data.bytes[i]); |
| 93 | } |
127 | } |
| 94 | printf("}\n"); |
128 | printf("}\n"); |
| 95 | - | ||
| 96 | #ifdef EQLAZER /* More personalized code */ |
- | |
| 97 | if( (rxMsg.Id & 0x1E000000)>>25 == FUNCT_SENSORS){ |
- | |
| 98 | - | ||
| 99 | // TODO fixa rätt umatning av sensordata: negativa tal och decimaldelen. |
- | |
| 100 | // Skriva om hela skiten |
- | |
| 101 |
|
129 | #endif |
| 102 |
|
130 | /* Get data from bus and store */ |
| 103 | if( (rxMsg.Id & 0x01FF8000)>>15 == FUNCC_SENSORS_TEMPERATURE_INSIDE ){ |
- | |
| 104 | /* Below 0 degrees celsius? */ |
- | |
| 105 | if(rxMsg.Data.bytes[0]&0x80){ |
- | |
| 106 | rxMsg.Data.bytes[0]= -rxMsg.Data.bytes[0]; |
- | |
| 107 | subzero = 1; |
- | |
| 108 | }else{ |
- | |
| 109 | subzero = 0; |
- | |
| 110 | } |
- | |
| 111 | snprintf( buffer, BUFFER_SIZE, (subzero)?"-%d,%d%cC":"%d,%d%cC", rxMsg.Data.bytes[0], rxMsg.Data.bytes[1], 0xdf ); |
- | |
| 112 | lcd_gotoxy( LCD_LINE0_0 ); |
- | |
| 113 | lcd_puts( LCD_SENSOR_TEMPERATURE_INSIDE ); |
- | |
| 114 | lcd_gotoxy( LCD_LINE1_0 ); |
- | |
| 115 | lcd_puts( buffer ); |
- | |
| 116 | }else if( (rxMsg.Id & 0x01FF8000)>>15 == FUNCC_SENSORS_TEMPERATURE_OUTSIDE ){ |
- | |
| 117 | if(rxMsg.Data.bytes[0]&0x80){ |
- | |
| 118 | rxMsg.Data.bytes[0]= -rxMsg.Data.bytes[0]; |
- | |
| 119 | subzero = 1; |
- | |
| 120 | }else{ |
- | |
| 121 | subzero = 0; |
- | |
| 122 | } |
- | |
| 123 | snprintf( buffer, BUFFER_SIZE, (subzero)?"-%d,%d%cC":"%d,%d%cC", rxMsg.Data.bytes[0], rxMsg.Data.bytes[1], 0xdf ); |
- | |
| 124 | lcd_gotoxy( LCD_LINE2_0 ); |
- | |
| 125 | lcd_puts( LCD_SENSOR_TEMPERATURE_OUTSIDE ); |
- | |
| 126 | lcd_gotoxy( LCD_LINE3_0 ); |
- | |
| 127 | lcd_puts( buffer ); |
- | |
| 128 | }else if( (rxMsg.Id & 0x01FF8000)>>15 == FUNCC_SENSORS_TEMPERATURE_FREEZER ){ |
- | |
| 129 | if(rxMsg.Data.bytes[0]&0x80){ |
- | |
| 130 | rxMsg.Data.bytes[0]= -rxMsg.Data.bytes[0]; |
- | |
| 131 | subzero = 1; |
- | |
| 132 | }else{ |
- | |
| 133 | subzero = 0; |
- | |
| 134 | } |
- | |
| 135 | snprintf( buffer, BUFFER_SIZE, (subzero)?"-%d,%d%cC":"%d,%d%cC", rxMsg.Data.bytes[0], rxMsg.Data.bytes[1], 0xdf ); |
- | |
| 136 | lcd_gotoxy( LCD_LINE2_2 ); |
- | |
| 137 | lcd_puts( LCD_SENSOR_TEMPERATURE_FREEZER ); |
- | |
| 138 | lcd_gotoxy( LCD_LINE3_2 ); |
- | |
| 139 | lcd_puts( buffer ); |
- | |
| 140 | }else{ |
- | |
| 141 | lcd_clrscr(); |
- | |
| 142 | lcd_puts("Sensors: No config."); |
- | |
| 143 | } |
- | |
| 144 | } |
- | |
| 145 | #else /* Generally code */ |
- | |
| 146 | - | ||
| 147 | /* If temperature sensor data received print to LCD */ |
- | |
| 148 | if( rxMsg.Id == 0x300 ){ |
131 | if( rxMsg.Id == 0x300 ){ |
| - | 132 | /* Temperature sensor data */ |
|
| - | 133 | for(m=0; m<rxMsg.DataLength; m++){ |
|
| - | 134 | temperatureData[m] = rxMsg.Data.bytes[m]; |
|
| - | 135 | } |
|
| - | 136 | }else if( rxMsg.Id == 0x1201 ){ |
|
| - | 137 | /* Relay status (ON/OFF) */ |
|
| - | 138 | relayStatus[1] = rxMsg.Data.bytes[2]; |
|
| - | 139 | } /* TODO Add extra messages here */ |
|
| - | 140 | } |
|
| - | 141 | ||
| - | 142 | /* Print views */ |
|
| - | 143 | // TODO använd optoencoders för att växla view |
|
| - | 144 | printLCDview( MAIN_VIEW ); |
|
| 149 | 145 | ||
| 150 | for( uint8_t i=0; i<(rxMsg.DataLength/2); i++ ){ |
- | |
| 151 | snprintf( buffer, BUFFER_SIZE, "Sensor %i: %d,%d%cC", i, rxMsg.Data.bytes[i*2], rxMsg.Data.bytes[i*2+1], 0xdf ); // TODO fixa korrekt utmatning av negativa tal och decimaldel |
- | |
| 152 | lcd_gotoxy(0,1+i); |
- | |
| 153 | lcd_puts( buffer ); |
- | |
| 154 | } |
- | |
| 155 | } |
- | |
| 156 | #endif |
- | |
| 157 | } |
- | |
| 158 | } |
146 | } |
| 159 | 147 | ||
| 160 | return 0; |
148 | return 0; |
| 161 | } |
149 | } |