소스 검색

add getting temperature from stm32

balbekova 1 년 전
부모
커밋
9f6e87f315
4개의 변경된 파일13개의 추가작업 그리고 4개의 파일을 삭제
  1. 9 1
      modules/MegaTec/megatec.c
  2. 1 1
      modules/MegaTec/megatec.h
  3. 1 1
      modules/stm32_temperature/stm32_temperature.c
  4. 2 1
      user/init_task.c

+ 9 - 1
modules/MegaTec/megatec.c

@@ -129,6 +129,7 @@ void init_UPS_value(void)
     UPS.Status = 0;
     UPS.Mode = 0;
     UPS.Alarm = 0;
+    UPS.temp_stm32 = 0;
     UPS.warn_status = 0;
     UPS.Test_Status = 0;
     UPS.fault_type = 0;
@@ -1005,6 +1006,7 @@ void ups_temperature_response(char *data)
 {
     char value[20];
     uint8_t len = 0;
+    float temp = 0;
 
     if (data[0] != '(') {
         return;
@@ -1018,7 +1020,13 @@ void ups_temperature_response(char *data)
     len = get_ups_param(data, " ", value);
     data += (len + 1);
     if (len > 0) {
-        UPS.Temp = atof(value);
+        temp = atof(value);
+        if (temp == 0 && UPS.temp_stm32 < 0) {
+            UPS.Temp = UPS.temp_stm32;
+        } else {
+            UPS.Temp = temp;
+        }
+         
     }
 }
 

+ 1 - 1
modules/MegaTec/megatec.h

@@ -93,7 +93,7 @@ typedef struct{
 	char vertion[22];
 	char serial[15];
 	uint8_t fault_type;
-	uint16_t temp_stm32;
+	float temp_stm32;
 	uint8_t cnt_err_ups;
 	ups_state_connection_t Present;
 	bool Flag_Present;

+ 1 - 1
modules/stm32_temperature/stm32_temperature.c

@@ -91,7 +91,7 @@ void stm32_temperature_meas(void *params)
 
         adc_temperature += 25.0; // Add the 25°C
        UPS.temp_stm32 = adc_temperature - TEMPERATURE_SHIFT;
-       printf("stm32_temperature %d\r\n", UPS.temp_stm32);
+       printf("stm32_temperature %0.1f\r\n", UPS.temp_stm32);
         vTaskDelay(5000);
     }
 }

+ 2 - 1
user/init_task.c

@@ -48,6 +48,7 @@
 #ifdef AM2301_SENSOR_ENABLE
 #include "AM2301.h"
 #endif
+#include "stm32_temperature.h"
 #include "sntp_api.h"
 #include "settings_api.h"
 #include "main.h"
@@ -156,7 +157,7 @@ DHT_Task_Init();
 /* Random number generator */
     RNG_Init();
 // -----------------------------------------------------------------------------
-
+stm32_temperature_init();
 // -----------------------------------------------------------------------------
 #ifdef NET_ENABLE
     ETH_BSP_Config();