Skip to content

Commit 463b75f

Browse files
committed
Added a simulated sensor source as a configuration option
1 parent 699b8a7 commit 463b75f

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

src/client_task.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ static void client_publish_message(MQTTClient* mqtt_client)
116116
MQTTMessage message;
117117
char json_message[256];
118118
uint32_t ts = time_utils_get_utc();
119-
uint32_t temp = th5_read_sensor(0);
120-
uint32_t speed = fan_click_get_tach();
119+
uint32_t temp = sensor_get_temperature();
120+
uint32_t speed = sensor_get_fan_speed();
121121
char topic[100];
122122

123123
if(config_get_client_pub_topic(topic, sizeof(topic)))

src/config.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,17 @@
4545
#define CONFIG_DEBUG
4646

4747
/* Define for WIFI Manager Debug */
48-
//#define CONFIG_WIFI_DEBUG
48+
#define CONFIG_WIFI_DEBUG
4949

5050
/* Define for Client Manager Debug */
5151
#define CONFIG_CLIENT_DEBUG
5252

5353
/* Define if the connection parameters are in code */
5454
#define CONFIG_USE_STATIC_CONFIG
5555

56+
/* Define if simulating the data */
57+
#define CONFIG_SENSOR_SIMULATOR
58+
5659

5760
/** \brief Check if the configuration has been loaded */
5861
bool config_ready(void);

src/sensor_task.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,35 @@ static void write_map_to_buffer(uint8_t *buffer, size_t buflen)
144144
}
145145
}
146146

147+
uint32_t sensor_get_temperature(void)
148+
{
149+
#ifdef CONFIG_SENSOR_SIMULATOR
150+
if (24000 > g_temp_buffer[0] || 30000 < g_temp_buffer[0])
151+
{
152+
g_temp_buffer[0] = 24000;
153+
}
154+
else
155+
{
156+
g_temp_buffer[0] += 1000;
157+
}
158+
return g_temp_buffer[0];
159+
#else
160+
return th5_read_sensor(0);
161+
#endif
162+
}
163+
164+
uint16_t sensor_get_fan_speed(void)
165+
{
166+
#ifdef CONFIG_SENSOR_SIMULATOR
167+
return get_speed_from_map(g_temp_buffer[0]);
168+
#else
169+
return fan_click_get_tach();
170+
#endif
171+
}
172+
147173
void sensor_task(void)
148174
{
175+
#ifndef CONFIG_SENSOR_SIMULATOR
149176
uint16_t temp;
150177
uint16_t speed;
151178

@@ -162,4 +189,5 @@ static void write_map_to_buffer(uint8_t *buffer, size_t buflen)
162189

163190
/* Set new target */
164191
fan_click_set_target_tach(speed);
192+
#endif
165193
}

src/sensor_task.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include "config.h"
3636

3737
void sensor_task(void);
38+
uint32_t sensor_get_temperature(void);
39+
uint16_t sensor_get_fan_speed(void);
3840

3941
#ifdef CONFIG_USE_JSON_LIB
4042
#include "parson.h"

0 commit comments

Comments
 (0)