diff --git a/Core/Inc/sts_weight_scale.h b/Core/Inc/sts_weight_scale.h index 1b475d0..2223e8b 100644 --- a/Core/Inc/sts_weight_scale.h +++ b/Core/Inc/sts_weight_scale.h @@ -25,7 +25,28 @@ #include "main.h" #include "sys_app.h" -int sts_weight_scale(void); + + +typedef struct +{ + uint32_t weight_scale_value; + float pressure; /*!< in mbar */ + float temperature; /*!< in degC */ + float humidity; /*!< in % */ + int32_t latitude; /*!< latitude converted to binary */ + int32_t longitude; /*!< longitude converted to binary */ + int16_t altitudeGps; /*!< in m */ + int16_t altitudeBar; /*!< in m * 10 */ + /**more may be added*/ + /* USER CODE BEGIN sensor_t */ + + /* USER CODE END sensor_t */ +} sts_sensor_t; + + + +void sts_weight_scale_init(void); +void sts_weight_scale(sts_sensor_t *sensor_data); void HX711_Init(void); void Init_HX711pin(void); uint32_t HX711_Read(void); @@ -39,5 +60,4 @@ void delay_us(uint32_t nus); - #endif /* YUNHORN_STS_WEIGHT_SCALE_H_ */ diff --git a/Core/Src/main.c b/Core/Src/main.c index a56a001..74892d2 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -91,7 +91,7 @@ int main(void) APP_LOG(TS_OFF, VLEVEL_M, "\r\n ----- Start ----- \r\n"); - sts_weight_scale(); + //sts_weight_scale(); /* USER CODE END 2 */ diff --git a/Core/Src/sts_weight_scale.c b/Core/Src/sts_weight_scale.c index bfd89a8..59fe4a9 100644 --- a/Core/Src/sts_weight_scale.c +++ b/Core/Src/sts_weight_scale.c @@ -25,20 +25,23 @@ volatile uint32_t gross_weight; int32_t net_weight; uint8_t Flag_Error; volatile uint32_t last_net_weight=0; -int sts_weight_scale(void) -{ +volatile sts_sensor_t sts_sensor_data; +void sts_weight_scale_init(void) +{ HX711_Init(); Get_GrossWeight(); - HAL_Delay(500); - Get_GrossWeight(); - +} - while(1) +void sts_weight_scale(sts_sensor_t *sts_sensor_data) +{ + + //while(1) { Get_NetWeight(); APP_LOG(TS_OFF, VLEVEL_M, "Net Weight = %d g \r\n", net_weight); + sts_sensor_data->weight_scale_value=net_weight; last_net_weight = net_weight; if (((last_net_weight - net_weight) > 100) && (net_weight > 100)) // re-calibrate @@ -46,9 +49,9 @@ int sts_weight_scale(void) Get_GrossWeight(); HAL_Delay(100); Get_GrossWeight(); - HAL_Delay(2000); + //HAL_Delay(2000); } - HAL_Delay(2000); + //HAL_Delay(2000); } } diff --git a/Core/Src/sys_app.c b/Core/Src/sys_app.c index 705ba80..fe4a2be 100644 --- a/Core/Src/sys_app.c +++ b/Core/Src/sys_app.c @@ -30,7 +30,9 @@ #include "utilities_def.h" #include "sys_debug.h" #include "sys_sensors.h" - +#ifdef STS_WS +#include "sts_weight_scale.h" +#endif /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -117,7 +119,9 @@ void SystemApp_Init(void) /*Initialize the Sensors */ EnvSensors_Init(); - +#ifdef STS_WS + sts_weight_scale_init(); +#endif /*Init low power manager*/ UTIL_LPM_Init(); /* Disable Stand-by mode */ diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 0eabe19..6a9f88f 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -36,7 +36,9 @@ #include "flash_if.h" /* USER CODE BEGIN Includes */ - +#ifdef STS_WS +#include "sts_weight_scale.h" +#endif /* USER CODE END Includes */ /* External variables ---------------------------------------------------------*/ @@ -555,6 +557,9 @@ static void SendTxData(void) LmHandlerErrorStatus_t status = LORAMAC_HANDLER_ERROR; uint8_t batteryLevel = GetBatteryLevel(); sensor_t sensor_data; +#ifdef STS_WS + sts_sensor_t sts_sensor_data; +#endif UTIL_TIMER_Time_t nextTxIn = 0; if (LmHandlerIsBusy() == false) @@ -572,7 +577,11 @@ static void SendTxData(void) #endif /* CAYENNE_LPP */ EnvSensors_Read(&sensor_data); +#ifdef STS_WS + sts_weight_scale(&sts_sensor_data); + APP_LOG(TS_ON, VLEVEL_M, "Weigt Scale : %d\r\n", sts_sensor_data.weight_scale_value); +#endif APP_LOG(TS_ON, VLEVEL_M, "VDDA: %d\r\n", batteryLevel); APP_LOG(TS_ON, VLEVEL_M, "temp: %d\r\n", (int16_t)(sensor_data.temperature)); @@ -628,6 +637,10 @@ static void SendTxData(void) AppData.Buffer[i++] = (uint8_t)((altitudeGps >> 8) & 0xFF); AppData.Buffer[i++] = (uint8_t)(altitudeGps & 0xFF); } +#ifdef STS_WS + AppData.Buffer[i++] = (uint8_t)(sts_sensor_data.weight_scale_value >> 8& 0xFF); + AppData.Buffer[i++] = (uint8_t)(sts_sensor_data.weight_scale_value & 0xFF); +#endif AppData.BufferSize = i; #endif /* CAYENNE_LPP */