Skip to content

Commit

Permalink
Merge pull request jakkra#152 from jakkra/jakkra_air_quality_on_watch…
Browse files Browse the repository at this point in the history
…face

digital watchface: Show IAQ and CO2 as arc values instead of pressure.
  • Loading branch information
Kampi authored Nov 26, 2023
2 parents 8fc270c + a941346 commit ced8bfe
Show file tree
Hide file tree
Showing 6 changed files with 400 additions and 45 deletions.
27 changes: 8 additions & 19 deletions app/src/applications/watchface/watchface_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "events/activity_event.h"
#include "events/ble_data_event.h"
#include "sensors/zsw_imu.h"
#include "sensors/zsw_environment_sensor.h"
#include "sensors/zsw_pressure_sensor.h"
#include "managers/zsw_battery_manager.h"
#include "managers/zsw_notification_manager.h"
Expand Down Expand Up @@ -118,8 +119,6 @@ static uint8_t current_watchface;

static watchface_app_evt_listener watchface_evt_cb;

static const struct device *const bme688 = DEVICE_DT_GET_OR_NULL(DT_NODELABEL(bme688));

static int watchface_app_init(void)
{
k_work_init_delayable(&general_work_item.work, general_work);
Expand Down Expand Up @@ -214,29 +213,19 @@ static void general_work(struct k_work *item)
case UPDATE_SLOW_VALUES: {
float pressure = 0.0;
float temperature = 0.0;
int humidity = 0.0;
struct sensor_value sensor_val;
float humidity = 0.0;
float iaq = 0.0;
float co2 = 0.0;
struct tm *time = zsw_clock_get_time();

if (device_is_ready(bme688)) {
if (sensor_sample_fetch(bme688) != 0) {
return;
}

sensor_channel_get(bme688, SENSOR_CHAN_AMBIENT_TEMP, &sensor_val);
temperature = sensor_value_to_float(&sensor_val);

sensor_channel_get(bme688, SENSOR_CHAN_HUMIDITY, &sensor_val);
humidity = sensor_value_to_float(&sensor_val);

sensor_channel_get(bme688, SENSOR_CHAN_PRESS, &sensor_val);
pressure = sensor_value_to_float(&sensor_val);
}
zsw_environment_sensor_get(&temperature, &humidity, &pressure);
zsw_environment_sensor_get_co2(&co2);
zsw_environment_sensor_get_iaq(&iaq);

watchfaces[current_watchface]->set_date(time->tm_wday, time->tm_mday);

zsw_pressure_sensor_get_pressure(&pressure);
watchfaces[current_watchface]->set_watch_env_sensors((int)temperature, (int)humidity, (int)pressure);
watchfaces[current_watchface]->set_watch_env_sensors((int)temperature, (int)humidity, (int)pressure, iaq, co2);

__ASSERT(0 <= k_work_schedule(&date_work.work, SLOW_UPDATE_INTERVAL), "FAIL date_work");
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/applications/watchface/watchface_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ typedef struct watchface_ui_api_t {
void (*set_num_notifcations)(int32_t value);
void (*set_weather)(int8_t temperature, int weather_code);
void (*set_date)(int day_of_week, int date);
void (*set_watch_env_sensors)(int temperature, int humidity, int pressure);
void (*set_watch_env_sensors)(int temperature, int humidity, int pressure, float iaq, float co2);
void (*ui_invalidate_cached)(void);
} watchface_ui_api_t;

Expand Down
Loading

0 comments on commit ced8bfe

Please sign in to comment.