Rev 52 | Rev 56 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 52 | Rev 53 | ||
---|---|---|---|
Line 110... | Line 110... | ||
110 | int itemIndex = dial_pos[dial] % PLXItems; |
110 | int itemIndex = dial_pos[dial] % PLXItems; |
111 | 111 | ||
112 | return cc_display (dial, itemIndex, suppress); |
112 | return cc_display (dial, itemIndex, suppress); |
113 | } |
113 | } |
114 | 114 | ||
- | 115 | void |
|
- | 116 | setBaud (usart_ctl *ctl, uint32_t baud) |
|
- | 117 | { |
|
- | 118 | ctl->handle->Init.BaudRate = baud; |
|
- | 119 | __disable_irq (); |
|
- | 120 | HAL_UART_Init (ctl->handle); |
|
- | 121 | __enable_irq (); |
|
- | 122 | } |
|
- | 123 | ||
- | 124 | void |
|
- | 125 | sendString (usart_ctl *ctl, char *string, int length) |
|
- | 126 | { |
|
- | 127 | int i; |
|
- | 128 | for (i = 0; i < length; i++) |
|
- | 129 | PutCharSerial (ctl, string[i]); |
|
- | 130 | ||
- | 131 | } |
|
- | 132 | ||
- | 133 | ||
- | 134 | // this code doesnt work so it leaves speed as 9600. |
|
- | 135 | void |
|
- | 136 | initModule (usart_ctl *ctl, uint32_t baudRate) |
|
- | 137 | { |
|
- | 138 | char initBuf[30]; |
|
- | 139 | // switch to command mode |
|
- | 140 | HAL_GPIO_WritePin (BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, GPIO_PIN_RESET); |
|
- | 141 | HAL_Delay (500); |
|
- | 142 | int initLen = small_sprintf (initBuf, "AT+UART=%d,1,2\n", baudRate); |
|
- | 143 | setBaud (ctl, 38400); |
|
- | 144 | sendString (ctl, initBuf, initLen); |
|
- | 145 | TxWaitEmpty (ctl); |
|
- | 146 | // switch back to normal comms at new baud rate |
|
- | 147 | ||
- | 148 | HAL_GPIO_WritePin (BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, GPIO_PIN_SET); |
|
- | 149 | setBaud (ctl, baudRate); |
|
- | 150 | HAL_Delay (100); |
|
- | 151 | ||
- | 152 | } |
|
- | 153 | ||
115 | /* USER CODE END PFP */ |
154 | /* USER CODE END PFP */ |
116 | 155 | ||
117 | /* Private user code ---------------------------------------------------------*/ |
156 | /* Private user code ---------------------------------------------------------*/ |
118 | /* USER CODE BEGIN 0 */ |
157 | /* USER CODE BEGIN 0 */ |
119 | 158 | ||
Line 180... | Line 219... | ||
180 | /* turn on USART3 IRQ */ |
219 | /* turn on USART3 IRQ */ |
181 | HAL_NVIC_SetPriority (USART3_IRQn, 4, 0); |
220 | HAL_NVIC_SetPriority (USART3_IRQn, 4, 0); |
182 | HAL_NVIC_EnableIRQ (USART3_IRQn); |
221 | HAL_NVIC_EnableIRQ (USART3_IRQn); |
183 | 222 | ||
184 | /* setup the USART control blocks */ |
223 | /* setup the USART control blocks */ |
185 | init_usart_ctl (&uc1, huart1.Instance); |
224 | init_usart_ctl (&uc1, &huart1); |
186 | init_usart_ctl (&uc2, huart2.Instance); |
225 | init_usart_ctl (&uc2, &huart2); |
187 | init_usart_ctl (&uc3, huart3.Instance); |
226 | init_usart_ctl (&uc3, &huart3); |
188 | 227 | ||
189 | EnableSerialRxInterrupt (&uc1); |
228 | EnableSerialRxInterrupt (&uc1); |
190 | EnableSerialRxInterrupt (&uc2); |
229 | EnableSerialRxInterrupt (&uc2); |
191 | EnableSerialRxInterrupt (&uc3); |
230 | EnableSerialRxInterrupt (&uc3); |
192 | 231 | ||
Line 195... | Line 234... | ||
195 | HAL_TIM_Encoder_Start (&htim9, TIM_CHANNEL_ALL); |
234 | HAL_TIM_Encoder_Start (&htim9, TIM_CHANNEL_ALL); |
196 | 235 | ||
197 | // Switch handler called on sysTick interrupt. |
236 | // Switch handler called on sysTick interrupt. |
198 | InitSwitches (); |
237 | InitSwitches (); |
199 | 238 | ||
- | 239 | initModule(&uc3,9600); |
|
- | 240 | ||
- | 241 | ||
200 | cc_init (); |
242 | cc_init (); |
201 | 243 | ||
202 | int i; |
244 | int i; |
203 | for (i = 0; i < 2; i++) |
245 | for (i = 0; i < 2; i++) |
204 | { |
246 | { |
Line 245... | Line 287... | ||
245 | 287 | ||
246 | int PLXPtr = 0; |
288 | int PLXPtr = 0; |
247 | 289 | ||
248 | while (1) |
290 | while (1) |
249 | { |
291 | { |
250 | // Handle the bluetooth pairing function by pressing both buttons. |
292 | // Handle the bluetooth pairing / reset function by pressing both buttons. |
251 | if ((push_pos[0] == 1) && (push_pos[1] == 1)) |
293 | if ((push_pos[0] == 1) && (push_pos[1] == 1)) |
252 | { |
294 | { |
253 | HAL_GPIO_WritePin (BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, |
295 | HAL_GPIO_WritePin (BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, |
254 | GPIO_PIN_RESET); |
296 | GPIO_PIN_RESET); |
255 | } |
297 | } |
Line 265... | Line 307... | ||
265 | { |
307 | { |
266 | timeout++; |
308 | timeout++; |
267 | if (timeout % 1000 == 0) |
309 | if (timeout % 1000 == 0) |
268 | { |
310 | { |
269 | const char msg[] = "Timeout\r\n"; |
311 | const char msg[] = "Timeout\r\n"; |
270 | char *p = msg; |
- | |
271 | while (*p) |
- | |
272 | { |
- | |
273 | PutCharSerial (&uc3, *p++); |
312 | sendString (&uc3, msg, sizeof(msg)); |
274 | } |
- | |
275 | 313 | ||
276 | } |
314 | } |
277 | 315 | ||
278 | if (timeout > 60000) |
316 | if (timeout > 60000) |
279 | { |
317 | { |
Line 309... | Line 347... | ||
309 | 347 | ||
310 | int DataVal; |
348 | int DataVal; |
311 | // process min/max |
349 | // process min/max |
312 | for (i = 0; i < PLXItems; i++) |
350 | for (i = 0; i < PLXItems; i++) |
313 | { |
351 | { |
314 | // Send item to BT |
- | |
315 | uint16_t addr = ConvPLX (Data.Sensor[i].AddrH, |
- | |
316 | Data.Sensor[i].AddrL); |
- | |
317 | uint8_t inst = Data.Sensor[i].Instance; |
- | |
318 | uint16_t reading = ConvPLX (Data.Sensor[i].ReadingH, |
- | |
319 | Data.Sensor[i].ReadingL); |
- | |
320 | 352 | ||
321 | if (log) |
353 | if (log) |
322 | { |
354 | { |
- | 355 | // Send item to BT |
|
- | 356 | uint16_t addr = ConvPLX (Data.Sensor[i].AddrH, |
|
- | 357 | Data.Sensor[i].AddrL); |
|
- | 358 | uint8_t inst = Data.Sensor[i].Instance; |
|
- | 359 | uint16_t reading = ConvPLX ( |
|
- | 360 | Data.Sensor[i].ReadingH, |
|
- | 361 | Data.Sensor[i].ReadingL); |
|
323 | char outbuff[100]; |
362 | char outbuff[100]; |
324 | 363 | ||
325 | int cnt = small_sprintf (outbuff, "$LOG%d,%d,%d", addr, |
364 | int cnt = small_sprintf (outbuff, "$LOG,%d,%d,%d", |
326 | inst, reading); |
365 | addr, inst, reading); |
327 | - | ||
328 | - | ||
329 | 366 | ||
- | 367 | //checksum |
|
330 | int ck; |
368 | int ck; |
331 | int sum = 0; |
369 | int sum = 0; |
332 | for (ck=1 ; ck < cnt ; ck++) |
370 | for (ck = 1; ck < cnt; ck++) |
333 | sum += outbuff[ck]; |
371 | sum += outbuff[ck]; |
334 | cnt += small_sprintf(outbuff+cnt,"*%02X\n",sum & 0xFF); |
372 | cnt += small_sprintf (outbuff + cnt, "*%02X\n", |
335 | for (ck = 0; ck <cnt; ck++) |
373 | sum & 0xFF); |
336 | PutCharSerial (&uc3, outbuff[ck]); |
374 | sendString (&uc3, outbuff, cnt); |
337 | 375 | ||
338 | } |
376 | } |
339 | DataVal = ConvPLX (Data.Sensor[i].ReadingH, |
377 | DataVal = ConvPLX (Data.Sensor[i].ReadingH, |
340 | Data.Sensor[i].ReadingL); |
378 | Data.Sensor[i].ReadingL); |
341 | if (DataVal > Max[i]) |
379 | if (DataVal > Max[i]) |