Skip to content

Commit

Permalink
change units to usv/h
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkok committed Jun 25, 2022
1 parent c1d4729 commit e4357ec
Show file tree
Hide file tree
Showing 7 changed files with 398 additions and 227 deletions.
2 changes: 1 addition & 1 deletion FW/main/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static void *display_thread(void * arg)
{
sleep(1);
display_print(&display_ram[0][27], 0, 0, "Current data");
sprintf(buffer, "GC Cnts: %6.0d", rx_store.current.gc_count);
sprintf(buffer, "Geiger: %2.3f usv/h", rx_store.current.gc_usv);
display_print(&display_ram[1][4], 0, 0, buffer);
sprintf(buffer, "Temp.: %3.2f C", rx_store.current.temperature);
display_print(&display_ram[2][4], 0, 0, buffer);
Expand Down
53 changes: 37 additions & 16 deletions FW/main/geiger.c
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
#include "geiger.h"

#define GC_LOG_CNT 60

extern QueueHandle_t data_queue;

static const char *TAG = "GEIGER";
static unsigned short int gc_event = 0;
static unsigned int gc_event = 0;
float gc_hourly[GC_LOG_CNT];
short int hourly_index = 0;
static unsigned short int gc_event_ind = 0;

void gc_int_handler(void *arg)
{
data_msg_s * gc_msg;

gc_msg = malloc(sizeof(data_msg_s));
if (gc_msg)
{
gc_event++;
gc_msg->msg_src = GC_SRC;
gc_msg->gc_count = gc_event;
if (xQueueSend( data_queue, (void *) &gc_msg, (TickType_t)0) != pdTRUE)
{
free(gc_msg);
}
}
gc_event++;
gc_event_ind = 1;
}

static void *geiger_thread(void * arg)
{
struct timeval tv_old, tv_new;
unsigned char clear_event = 0;
data_msg_s * gc_msg;

for (int i = 0 ; i < GC_LOG_CNT ; i++)
{
gc_hourly[i] = 0.0;
}

gettimeofday(&tv_old, NULL);

ESP_LOGI(TAG, "Thread started!");
while (true)
{
usleep(10000);
if (gc_event)
if (gc_event_ind)
{
gpio_set_level(BUZ_GPIO,0);
gpio_set_level(LED_GPIO,0);
gc_event--;
gc_event_ind = 0;
clear_event = 1;
}
else if (clear_event != 0)
Expand All @@ -43,6 +46,24 @@ static void *geiger_thread(void * arg)
gpio_set_level(LED_GPIO,1);
clear_event = 0;
}
gettimeofday(&tv_new, NULL);
if (tv_new.tv_sec >= (tv_old.tv_sec + 60))
{
gc_hourly[hourly_index] = gc_event * 0.00812037f; // Convertion factor for J305 tube
gc_msg = malloc(sizeof(data_msg_s));
if (gc_msg)
{
gc_msg->msg_src = GC_SRC;
gc_msg->gc_usv = gc_hourly[hourly_index];
if (xQueueSend( data_queue, (void *) &gc_msg, (TickType_t)0) != pdTRUE)
{
free(gc_msg);
}
}
tv_old = tv_new;
hourly_index = (hourly_index + 1) % GC_LOG_CNT;
gc_event = 0;
}
}
ESP_LOGE(TAG, "Thread ended!");

Expand Down
5 changes: 3 additions & 2 deletions FW/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ void app_main(void)
ESP_LOGI(TAG, "Initialization finished!");
rx_store.current.temperature = 0.0f;
rx_store.current.humidity = 0.0f;

rx_store.current.gc_usv = 0.0f;

// All done, idle looP
while (true)
{
Expand All @@ -80,7 +81,7 @@ void app_main(void)
switch (data_msg_rx->msg_src)
{
case (GC_SRC):
rx_store.current.gc_count += data_msg_rx->gc_count;
rx_store.current.gc_usv = data_msg_rx->gc_usv;
break;
case (DHT_SRC):
rx_store.current.temperature = data_msg_rx->dht_info.temperature;
Expand Down
4 changes: 2 additions & 2 deletions FW/main/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ typedef struct rx_data_t
unsigned short pm10;
float temperature;
float humidity;
unsigned short gc_count;
float gc_usv;
}rx_data_s;

typedef struct rx_store_t
Expand All @@ -57,7 +57,7 @@ typedef struct data_msg_t
{
msg_src_e msg_src;
union {
unsigned short gc_count;
float gc_usv;
pm_info_s pm_info;
dht_info_s dht_info;
};
Expand Down
4 changes: 2 additions & 2 deletions FW/main/mqtt_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ int msg_id;
char buffer[256];


snprintf(buffer, sizeof(buffer), "{\"counter\":\"%d\","
snprintf(buffer, sizeof(buffer), "{\"counter\":\"%f\","
"\"temperature\":\"%3.2f\","
"\"humidity\":\"%3.2f\","
"\"pm1\":\"%d\","
"\"pm2_5\":\"%d\","
"\"pm10\":\"%d\"}",
rx_store.current.gc_count,
rx_store.current.gc_usv,
rx_store.current.temperature,
rx_store.current.humidity,
rx_store.current.pm1,
Expand Down
6 changes: 3 additions & 3 deletions FW/main/web_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,13 @@ static esp_err_t status_get_handler(httpd_req_t *req)

/* Send response with custom headers and body set as the
* string passed in user context*/
snprintf(status, sizeof(status), "GC: %d<br>"
snprintf(status, sizeof(status), "GC: %f<br>"
"Temperature: %f<br>"
"Humidity: %f<br>"
"PM1: %d<br>"
"PM2.5: %d<br>"
"PM10: %d<br>",
rx_store.current.gc_count,
"PM10: %d<br>",
rx_store.current.gc_usv,
rx_store.current.temperature,
rx_store.current.humidity,
rx_store.current.pm1,
Expand Down
Loading

0 comments on commit e4357ec

Please sign in to comment.