|
25 | 25 |
|
26 | 26 | /* Private includes ----------------------------------------------------------*/ |
27 | 27 | /* USER CODE BEGIN Includes */ |
28 | | -#include "aht20.h" |
| 28 | +#include "bl.h" |
29 | 29 | #include "utils.h" |
30 | 30 | #include <stdio.h> |
31 | 31 | #include <string.h> |
@@ -64,18 +64,7 @@ static void MX_I2C1_Init(void); |
64 | 64 |
|
65 | 65 | /* Private user code ---------------------------------------------------------*/ |
66 | 66 | /* USER CODE BEGIN 0 */ |
67 | | -/* just a wrapper for HAL_UART_Transmit*/ |
68 | | -void UART_Send_String(const char* str) |
69 | | -{ |
70 | | - HAL_UART_Transmit(&huart2, (uint8_t*)str, strlen(str), HAL_MAX_DELAY); |
71 | | -} |
72 | 67 |
|
73 | | -/* transmits data to UART */ |
74 | | -void transmit_data(float humidity, float temperature_c, float temperature_f) { |
75 | | - char data_to_display[60] = "\0"; |
76 | | - sprintf(data_to_display, "Humidity: %.2f%%, Temperature: %.2fC, %.2fF\r\n", humidity, temperature_c, temperature_f); |
77 | | - HAL_UART_Transmit(&huart2, (uint8_t *)data_to_display, strlen(data_to_display), HAL_MAX_DELAY); |
78 | | -} |
79 | 68 | /* USER CODE END 0 */ |
80 | 69 |
|
81 | 70 | /** |
@@ -109,39 +98,20 @@ int main(void) |
109 | 98 | MX_USART2_UART_Init(); |
110 | 99 | MX_I2C1_Init(); |
111 | 100 | /* USER CODE BEGIN 2 */ |
112 | | - |
113 | | - /* |
114 | | - * Datasheet: AHT20 Product manuals |
115 | | - * 5.4 Sensor reading process, paragraph 1 |
116 | | - */ |
117 | | - aht20_status_t status = AHT20_STATUS_OK; |
118 | | - |
119 | | - /* getting info about sensor calibration */ |
120 | | - status = aht20_validate_calibration(&hi2c1); |
121 | | - if (status != AHT20_STATUS_OK) { |
122 | | - print_error(&huart2, status); |
| 101 | + if(BL_STATUS_OK != bl_run_sensor(&hi2c1, &huart2)) { |
123 | 102 | return 1; |
124 | 103 | } |
125 | | - |
126 | 104 | /* USER CODE END 2 */ |
127 | 105 |
|
128 | 106 | /* Infinite loop */ |
129 | 107 | /* USER CODE BEGIN WHILE */ |
130 | | - aht20_data_t sensor_data = {0}; |
131 | | - |
132 | 108 | while (1) |
133 | 109 | { |
134 | | - /* triggering measuring */ |
135 | | - status = aht20_measure(&hi2c1, sensor_data.measured_data, (uint16_t)sizeof(sensor_data.measured_data)); |
136 | | - if (status != AHT20_STATUS_OK) { |
137 | | - print_error(&huart2, status); |
138 | | - aht20_soft_reset(&hi2c1); |
139 | | - continue; |
| 110 | + if (BL_STATUS_OK != bl_process_sensor_data(&hi2c1, &huart2)) { |
| 111 | + return 2; |
140 | 112 | } |
141 | 113 |
|
142 | | - aht20_calculate_measurments(sensor_data.measured_data, &sensor_data.humidity, &sensor_data.temperature_c, &sensor_data.temperature_f); |
143 | | - transmit_data(sensor_data.humidity, sensor_data.temperature_c, sensor_data.temperature_f); |
144 | | - |
| 114 | + bl_uart_transmit_sensor_data(&huart2); |
145 | 115 | HAL_Delay(1000); |
146 | 116 | /* USER CODE END WHILE */ |
147 | 117 |
|
|
0 commit comments