Rev 17 | Rev 19 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 17 | Rev 18 | ||
|---|---|---|---|
| Line 52... | Line 52... | ||
| 52 | UART_HandleTypeDef huart1; |
52 | UART_HandleTypeDef huart1; |
| 53 | UART_HandleTypeDef huart2; |
53 | UART_HandleTypeDef huart2; |
| 54 | 54 | ||
| 55 | /* USER CODE BEGIN PV */ |
55 | /* USER CODE BEGIN PV */ |
| 56 | /* Private variables ---------------------------------------------------------*/ |
56 | /* Private variables ---------------------------------------------------------*/ |
| 57 | #define MAXRDG 10 |
57 | #define MAXRDG 32 |
| 58 | 58 | ||
| 59 | int OldObservation[2] = |
59 | int OldObservation[2] = |
| 60 | { -1, -1 }; // illegal initial value |
60 | { -1, -1 }; // illegal initial value |
| 61 | int OldObservationIndex[2] = |
61 | int OldObservationIndex[2] = |
| 62 | { -1, -1 }; // if more than one sensor this will be printed |
62 | { -1, -1 }; // if more than one sensor this will be printed |
| 63 | int16_t dial0[2] = |
63 | int16_t dial0[2] = |
| 64 | { 0, 0 }; |
64 | { 0, 0 }; |
| 65 | int16_t dial1[2] = |
65 | int16_t dial1[2] = |
| 66 | { -1, -1 }; |
66 | { -1, -1 }; |
| 67 | 67 | ||
| - | 68 | uint16_t dial_timer[2] = |
|
| - | 69 | { 0, 0 }; |
|
| - | 70 | ||
| - | 71 | static const int DialTimeout = 50; // about 20 seconds after twiddle, save the dial position. |
|
| - | 72 | ||
| 68 | /* Virtual address defined by the user: 0xFFFF value is prohibited */ |
73 | /* Virtual address defined by the user: 0xFFFF value is prohibited */ |
| 69 | uint16_t VirtAddVarTab[NumbOfVar] = {0x1111,0x2222 } ; |
74 | uint16_t VirtAddVarTab[NumbOfVar] = {0x1111,0x2222 } ; |
| 70 | 75 | ||
| 71 | union |
76 | union |
| 72 | { |
77 | { |
| Line 101... | Line 106... | ||
| 101 | // suppress is the ItemIndex we wish to suppress on this display |
106 | // suppress is the ItemIndex we wish to suppress on this display |
| 102 | int DisplayCurrent(int dial,int suppress) |
107 | int DisplayCurrent(int dial,int suppress) |
| 103 | { |
108 | { |
| 104 | char buff[10]; |
109 | char buff[10]; |
| 105 | int i; |
110 | int i; |
| - | 111 | int rc; |
|
| 106 | select_display(dial); // pick the display we are using |
112 | select_display(dial); // pick the display we are using |
| 107 | int ItemIndex = dial_pos[dial]/4; |
113 | int ItemIndex = dial_pos[dial]/4; |
| 108 | 114 | ||
| 109 | // wrap around count if dial too far to the right |
115 | // wrap around count if dial too far to the right |
| 110 | if (ItemIndex >= PLXItems) |
116 | if (ItemIndex >= PLXItems) |
| Line 157... | Line 163... | ||
| 157 | { |
163 | { |
| 158 | if (Observation != OldObservation[dial] |
164 | if (Observation != OldObservation[dial] |
| 159 | || ObservationIndex != OldObservationIndex[dial]) |
165 | || ObservationIndex != OldObservationIndex[dial]) |
| 160 | { |
166 | { |
| 161 | 167 | ||
| - | 168 | dial_timer[dial] = DialTimeout; |
|
| 162 | 169 | ||
| 163 | dial1[dial] = -1; |
170 | dial1[dial] = -1; |
| 164 | clearDisplay(); |
171 | clearDisplay(); |
| 165 | dial_draw_scale( |
172 | dial_draw_scale( |
| 166 | DisplayInfo[Observation].Low, |
173 | DisplayInfo[Observation].Low, |
| Line 185... | Line 192... | ||
| 185 | OldObservationIndex[dial] = ObservationIndex; |
192 | OldObservationIndex[dial] = ObservationIndex; |
| 186 | // |
193 | // |
| 187 | display(); |
194 | display(); |
| 188 | 195 | ||
| 189 | } |
196 | } |
| - | 197 | else |
|
| - | 198 | { |
|
| - | 199 | // check for timer timeout on consistent timer |
|
| - | 200 | if(dial_timer[dial]) |
|
| - | 201 | { |
|
| - | 202 | dial_timer[dial]--; |
|
| - | 203 | ||
| - | 204 | if(dial_timer[dial]==0 ) |
|
| - | 205 | { |
|
| - | 206 | uint16_t curr_val = dial_pos[dial]; |
|
| - | 207 | rc = EE_ReadVariable(VirtAddVarTab[dial],&curr_val); |
|
| - | 208 | if((rc !=0) || (curr_val != dial_pos[dial])) |
|
| - | 209 | { |
|
| - | 210 | EE_WriteVariable(VirtAddVarTab[dial],dial_pos[dial]); |
|
| - | 211 | } |
|
| - | 212 | } |
|
| - | 213 | } |
|
| - | 214 | ||
| - | 215 | } |
|
| 190 | 216 | ||
| 191 | double max_rdg; |
217 | double max_rdg; |
| 192 | double min_rdg; |
218 | double min_rdg; |
| 193 | double cur_rdg; |
219 | double cur_rdg; |
| 194 | int int_rdg; |
220 | int int_rdg; |
| Line 307... | Line 333... | ||
| 307 | init_usart_ctl(&uc1, huart1.Instance); |
333 | init_usart_ctl(&uc1, huart1.Instance); |
| 308 | init_usart_ctl(&uc2, huart2.Instance); |
334 | init_usart_ctl(&uc2, huart2.Instance); |
| 309 | 335 | ||
| 310 | EnableSerialRxInterrupt(&uc1); |
336 | EnableSerialRxInterrupt(&uc1); |
| 311 | EnableSerialRxInterrupt(&uc2); |
337 | EnableSerialRxInterrupt(&uc2); |
| - | 338 | /* Unlock the Flash to enable the flash control register access *************/ |
|
| - | 339 | HAL_FLASH_Unlock(); |
|
| 312 | 340 | ||
| 313 | EE_Init(); |
341 | EE_Init(); |
| 314 | 342 | ||
| - | 343 | ||
| - | 344 | ||
| 315 | int i; |
345 | int i; |
| - | 346 | uint16_t rc; |
|
| 316 | for(i=0;i<2;i++) |
347 | for(i=0;i<2;i++) |
| 317 | { |
348 | { |
| 318 | uint16_t val; |
349 | uint16_t val; |
| 319 | 350 | ||
| 320 | uint16_t rc = EE_ReadVariable(i, &val); |
351 | uint16_t rc = EE_ReadVariable(VirtAddVarTab[i], &val); |
| 321 | 352 | ||
| 322 | if (rc == 0) |
353 | if (rc == 0) |
| 323 | { |
354 | { |
| 324 | dial_pos[i] = val; |
355 | dial_pos[i] = val; |
| 325 | } |
356 | } |
| - | 357 | else |
|
| - | 358 | { |
|
| - | 359 | break; |
|
| - | 360 | } |
|
| 326 | } |
361 | } |
| 327 | 362 | ||
| - | 363 | ||
| - | 364 | ||
| 328 | ap_init(); // set up the approximate math library |
365 | ap_init(); // set up the approximate math library |
| 329 | 366 | ||
| 330 | int disp; |
367 | int disp; |
| 331 | 368 | ||
| 332 | ssd1306_begin(1, 0); |
369 | ssd1306_begin(1, 0); |