From: Martin Mares Date: Sat, 21 Jul 2018 15:06:40 +0000 (+0200) Subject: BMP read after each USB update X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=5c6f049b7cc32f992ba8b5b8fdff681485fe0598;p=home-hw.git BMP read after each USB update --- diff --git a/usb/Inc/app.h b/usb/Inc/app.h index d0061dd..05a96f2 100644 --- a/usb/Inc/app.h +++ b/usb/Inc/app.h @@ -16,6 +16,7 @@ void tx_packet_send(void); // bmp085.c +extern byte bmp_request; extern int adjusted_temp; extern int adjusted_press; extern u32 bmp_counter; diff --git a/usb/Src/bmp085.c b/usb/Src/bmp085.c index c5712c9..45039b7 100644 --- a/usb/Src/bmp085.c +++ b/usb/Src/bmp085.c @@ -161,6 +161,7 @@ enum bmp_state { BMP_PRESSURE, }; +byte bmp_request; static byte bmp_state = BMP_IDLE; static u16 raw_temp; static u32 raw_press; @@ -173,6 +174,9 @@ void bmp_step(void) switch (bmp_state) { case BMP_IDLE: + if (!bmp_request) + return; + bmp_request = 0; bmp_debug("BMP: Start measure\n"); bmp_start_measure(0x2e); bmp_state++; diff --git a/usb/Src/main.c b/usb/Src/main.c index e8d8abb..e934fa9 100644 --- a/usb/Src/main.c +++ b/usb/Src/main.c @@ -123,7 +123,7 @@ int main(void) MX_USB_PCD_Init(); MX_TIM4_Init(); /* USER CODE BEGIN 2 */ - //display_init(); + display_init(); usb_start(&usb); bmp_init(); @@ -131,12 +131,10 @@ int main(void) LL_TIM_EnableIT_UPDATE(TIM4); LL_TIM_GenerateEvent_UPDATE(TIM4); -#if 0 { byte buf[5] = { 0xff, 0xff, 10, 0xff, 0xff }; display_buffer(buf); } -#endif /* USER CODE END 2 */ @@ -146,14 +144,14 @@ int main(void) { if (rx_packet_state == 1 && !tx_packet_state) { - static byte led_state; - if (led_state) - LL_GPIO_SetOutputPin(LED_GPIO_Port, LED_Pin); - else - LL_GPIO_ResetOutputPin(LED_GPIO_Port, LED_Pin); - led_state ^= 1; - - // display_buffer(rx_packet); + static byte led_state; + if (led_state) + LL_GPIO_SetOutputPin(LED_GPIO_Port, LED_Pin); + else + LL_GPIO_ResetOutputPin(LED_GPIO_Port, LED_Pin); + led_state ^= 1; + + display_buffer(rx_packet); tx_packet_state = 1; put_u32_be(tx_packet, adjusted_temp); put_u32_be(tx_packet + 4, adjusted_press); @@ -161,6 +159,7 @@ int main(void) usb_ep_send(&usb, 0x82, tx_packet, 12); rx_packet_state = 0; usb_ep_receive(&usb, 0x01, rx_packet, 64); + bmp_request = 1; } bmp_step();