Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kegov committed Mar 13, 2023
2 parents 46acddd + 40fed7d commit f94b60a
Show file tree
Hide file tree
Showing 11 changed files with 916 additions and 21 deletions.
5 changes: 5 additions & 0 deletions examples/esp32DeepSleep/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The compensated temperature, compensated humidity, IAQ & Static IAQ are not supported in this example code
because bsec expects the time to be ticking but during deepsleep the time resets to 0.

To overcome this the sleep duration can be added to the millis and passed to bsec from the example code.
Changes in bsec.c is also needed for this to work.
26 changes: 10 additions & 16 deletions examples/esp32DeepSleep/esp32DeepSleep.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@ bsec_virtual_sensor_t sensor_list[] = {
BSEC_OUTPUT_RAW_PRESSURE,
BSEC_OUTPUT_RAW_HUMIDITY,
BSEC_OUTPUT_RAW_GAS,
BSEC_OUTPUT_IAQ,
BSEC_OUTPUT_STATIC_IAQ,
BSEC_OUTPUT_CO2_EQUIVALENT,
BSEC_OUTPUT_BREATH_VOC_EQUIVALENT,
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE,
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY,
};

int64_t GetTimestamp() {
Expand All @@ -46,18 +42,18 @@ int64_t GetTimestamp() {
}

bool CheckSensor() {
if (sensor.status < BSEC_OK) {
LOG("BSEC error, status %d!", sensor.status);
if (sensor.bsecStatus < BSEC_OK) {
LOG("BSEC error, status %d!", sensor.bsecStatus);
return false;;
} else if (sensor.status > BSEC_OK) {
LOG("BSEC warning, status %d!", sensor.status);
} else if (sensor.bsecStatus > BSEC_OK) {
LOG("BSEC warning, status %d!", sensor.bsecStatus);
}

if (sensor.bme680Status < BME680_OK) {
LOG("Sensor error, bme680_status %d!", sensor.bme680Status);
if (sensor.bme68xStatus < BME68X_OK) {
LOG("Sensor error, bme680_status %d!", sensor.bme68xStatus);
return false;
} else if (sensor.bme680Status > BME680_OK) {
LOG("Sensor warning, status %d!", sensor.bme680Status);
} else if (sensor.bme68xStatus > BME68X_OK) {
LOG("Sensor warning, status %d!", sensor.bme68xStatus);
}

return true;
Expand Down Expand Up @@ -114,12 +110,10 @@ void setup() {
}

void loop() {
if (sensor.run(GetTimestamp())) {
if (sensor.run()) {
LOG("Temperature raw %.2f compensated %.2f", sensor.rawTemperature, sensor.temperature);
LOG("Humidity raw %.2f compensated %.2f", sensor.rawHumidity, sensor.humidity);
LOG("Pressure %.2f kPa", sensor.pressure / 1000);
LOG("IAQ %.0f accuracy %d", sensor.iaq, sensor.iaqAccuracy);
LOG("Static IAQ %.0f accuracy %d", sensor.staticIaq, sensor.staticIaqAccuracy);
LOG("Gas resistance %.2f kOhm", sensor.gasResistance / 1000);

sensor_state_time = GetTimestamp();
Expand All @@ -128,7 +122,7 @@ void loop() {
LOG("Saved state to RTC memory at %lld", sensor_state_time);
CheckSensor();

uint64_t time_us = ((sensor.nextCall - GetTimestamp()) * 1000) - esp_timer_get_time();
uint64_t time_us = (sensor.nextCall * 1000) - esp_timer_get_time();
LOG("Deep sleep for %llu ms. BSEC next call at %llu ms.", time_us / 1000, sensor.nextCall);
esp_sleep_enable_timer_wakeup(time_us);
esp_deep_sleep_start();
Expand Down
95 changes: 95 additions & 0 deletions examples/octopus_demo/OLED_featherwing_display.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/** Global Library includes */

/** Local Library includes */

#include "OLED_featherwing_display.h"

/** Global variables */
ImageList image_list[NUMBER_OF_IMAGES];

// Create an SSD1306 display object
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire);

/** Function definitions */

/********************************************************************************/
void initialize_display()
{
// Decode logos from uint32_t x 32 (32x32) to uint8_t x 128
decodeLogo(image_list[0].image, logo_bosch);
decodeLogo(image_list[1].image, logo_temp);
decodeLogo(image_list[2].image, logo_pres);
decodeLogo(image_list[3].image, logo_hum);
decodeLogo(image_list[4].image, logo_gas);
// Initialize the OLED display
display.begin(SSD1306_SWITCHCAPVCC, DISPLAY_I2C_ADDR); // initialize with the I2C addr 0x3C (for the 128x32)
display.clearDisplay();
display.display();
}

/********************************************************************************/
void display_print_string(String text, uint8_t x_axis, uint8_t y_axis, uint8_t text_size)
{
display.clearDisplay();
display.setTextSize(text_size);
display.setTextColor(WHITE);
display.setCursor(x_axis, y_axis);
display.println(text);
display.display();
}
/********************************************************************************/

void display_print_multi_string(String line1, uint8_t x_axis1, uint8_t y_axis1, uint8_t text_size1, String line2_0,
String line2,
uint8_t x_axis2, uint8_t y_axis2, uint8_t text_size2)
{
display.clearDisplay();
display.setTextSize(text_size1);
display.setTextColor(WHITE);
display.setCursor(x_axis1, y_axis1);
display.println(line1);

display.setTextSize(text_size2);
display.setTextColor(WHITE);
display.setCursor(x_axis2, y_axis2);
display.println(line2);

display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(110, 16);
display.println(" A");
display.setCursor(110, 24);
display.println(line2_0);

display.display();
}

/********************************************************************************/
void display_bosch_logo(String fwVersion)
{
display.clearDisplay();
display.drawBitmap(0, 0, image_list[0].image, 32, 32, WHITE);
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(40, 10);
display.println("BOSCH");
display.setTextSize(1);
display.setCursor(40, 00);
display.println(fwVersion);
display.display();
}

void display_print_img_string(String label, String value, uint8_t bmp, uint8_t label_size, uint8_t value_size)
{
display.clearDisplay();
display.drawBitmap(0, 0, image_list[bmp].image, 32, 32, WHITE);
display.setTextSize(label_size);
display.setTextColor(WHITE);
display.setCursor(40, 0);
display.println(label);
display.setTextSize(value_size);
display.setCursor(40, 20);
display.println(value);
display.display();
}

69 changes: 69 additions & 0 deletions examples/octopus_demo/OLED_featherwing_display.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/** Global Library includes */

#ifndef __OLED_FEATHERWING_DISPLAY_H_
#define __OLED_FEATHERWING_DISPLAY_H_

#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>

/** Local Library includes */

#include "logos.h"

/** Defines and consts */
#define NUMBER_OF_IMAGES 5u
#define DISPLAY_I2C_ADDR 0x3c

/** Structs and enums */

struct ImageList
{
uint8_t image[128];
};

extern ImageList image_list[NUMBER_OF_IMAGES];

/** Function declarations */

/**
* @brief Function used to initialize local objects for images with
* global consts from logos.h file
*/
void initialize_display();

/**
* @brief Function used to clear display and print the input string
* @param text [input] Input string that needs to be printed on display.
*/
void display_print_string(String text, uint8_t x_axis, uint8_t y_axis, uint8_t text_size);

/**
* @brief Function used to clear display and print the input string
* @param text [input] Input string that needs to be printed on display.
*/
void display_print_multi_string(String line1, uint8_t x_axis1, uint8_t y_axis1, uint8_t text_size1,
String line2_0,
String line2, uint8_t x_axis2, uint8_t y_axis2, uint8_t text_size2);

/**
* @brief Function used to display BOSCH logo on OLED display.
* @param fwVersion [input] Firmware version that needs to be printed on OLED Display
*/
void display_bosch_logo(String fwVersion);

/**
* @brief Function used to clear display and print input label and string based on bmp Index.
* @param label [input] Title which needs to be printed on display
* @param value [input] Value which needs to be printed on display
* @param bmp [input] Index number corresponding to bmp files
* @param label_size [input] Size of label string to be printed on OLED display
* @param value_size [input] Size of value string to be printed on OLED display
*/
void display_print_img_string(String label, String value, uint8_t bmp, uint8_t label_size, uint8_t value_size);

/** Global variables */

extern Adafruit_SSD1306 display;

#endif
6 changes: 6 additions & 0 deletions examples/octopus_demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Install Adafruit SSD1306, Adafruit GFX Library & Adafruit BusIO from the Arduino Library Manager

Versions used for testing
Adafruit SSD1306 version 2.3.1
Adafruit GFX Library version 1.9.0
Adafruit BusIO version 1.3.3
23 changes: 23 additions & 0 deletions examples/octopus_demo/logos.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "logos.h"

void decodeLogo(uint8_t *bitmap, const uint32_t *logo)
{
uint8_t i, j;

for (i = 0; i < 128; i++)
bitmap[i] = 0;

for (i = 0; i < 4; i++) {
for (j = 0; j < 32; j++)
{
bitmap[(4 * j) + i] = (((logo[i * 8] & 1 << j) >> j) << 7) |
(((logo[(i * 8) + 1] & 1 << j) >> j) << 6) |
(((logo[(i * 8) + 2] & 1 << j) >> j) << 5) |
(((logo[(i * 8) + 3] & 1 << j) >> j) << 4) |
(((logo[(i * 8) + 4] & 1 << j) >> j) << 3) |
(((logo[(i * 8) + 5] & 1 << j) >> j) << 2) |
(((logo[(i * 8) + 6] & 1 << j) >> j) << 1) |
(((logo[(i * 8) + 7] & 1 << j) >> j));
}
}
}
61 changes: 61 additions & 0 deletions examples/octopus_demo/logos.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#ifndef __LOGOS_H_
#define __LOGOS_H_

#include <Arduino.h>

void decodeLogo(uint8_t *bitmap, const uint32_t *logo);

const uint8_t lockBmp[32] = {
B00000000, B00000000,
B00000000, B00000000,
B00000011, B11000000,
B00001100, B00110000,
B00011000, B00011000,
B00011000, B00011000,
B00011000, B00011000,
B00011000, B00011000,
B00111111, B11111100,
B00111110, B01111100,
B00111100, B00111100,
B00111100, B00111100,
B00111110, B01111100,
B00111110, B01111100,
B00111111, B11111100,
B00011111, B11111000 };

const uint32_t logo_bosch[32] = { 0x00000000, 0x000FF000, 0x003FFC00,
0x00F00F00, 0x03C003C0, 0x071FF8E0, 0x067FFE60, 0x0CE00730, 0x19C00398,
0x3B8001DC, 0x33FFFFCC, 0x33FFFFCC, 0x60381C06, 0x60381C06, 0x60381C06,
0x60381C06, 0x60381C06, 0x60381C06, 0x60381C06, 0x60381C06, 0x33FFFFCC,
0x33FFFFCC, 0x3B8001DC, 0x19C00398, 0x0CE00730, 0x067FFE60, 0x071FF8E0,
0x03C003C0, 0x00F00F00, 0x003FFC00, 0x000FF000, 0x00000000 };

const uint32_t logo_temp[32] = { 0x00000000, 0x00000000, 0x00001000, 0x00001000,
0x00011080, 0x00011080, 0x000113E0, 0x00011080, 0x00011080, 0x00001000,
0x03C01000, 0x07E01000, 0x1C3FFFFC, 0x193FFFFE, 0x3B80100E, 0x3904522E,
0x1C3FFFFE, 0x1FFFFFFC, 0x08301000, 0x10101000, 0x20081000, 0x40441000,
0x40441000, 0x47C41000, 0x40441000, 0x40441000, 0x20081000, 0x10101000,
0x08201000, 0x07C00000, 0x00000000 };

const uint32_t logo_hum[32] = { 0x00000000, 0x00000000, 0x01FF0000, 0x03FFC000,
0x0701F000, 0x0E007800, 0x1C7C1C00, 0x38E00E00, 0x71800700, 0x73000380,
0x730001C0, 0x720000E0, 0x72000070, 0x72001FF0, 0x710071E0, 0x38006670,
0x1FF0CC18, 0x0C09980C, 0x10059006, 0x23E3900C, 0x21A1C818, 0x42E16070,
0x400131C0, 0x43E11F00, 0x40810000, 0x20810000, 0x23E20000, 0x10040000,
0x0C080000, 0x03F00000, 0x00000000, 0x00000000 };

const uint32_t logo_pres[32] = { 0x00000000, 0x00000400, 0x00000400, 0x1F1FC400,
0x31BFE404, 0x64FFF008, 0x6E607C10, 0x64303F80, 0x30181C40, 0x180C0C20,
0x0E060C20, 0x07030C20, 0x03C18C2E, 0x03E0DC20, 0x03B87840, 0x038C3F80,
0x03871C00, 0x0381CE40, 0x07C07320, 0x08201990, 0x10101EC0, 0x20081BE0,
0x400418F0, 0x4FE47838, 0x4124F000, 0x4124C000, 0x40C7C000, 0x200F8000,
0x101F0000, 0x08200000, 0x07C00000, 0x00000000 };

const uint32_t logo_gas[32] = { 0x00000000, 0x038000F8, 0x0440018C, 0x08200306,
0x08200202, 0x08600202, 0x04900202, 0x0389F706, 0x0047F98C, 0x002F10F8,
0x001E2080, 0x00382100, 0x00381380, 0x00380F80, 0x003E0380, 0x00390380,
0x00108380, 0x00208700, 0x07E11E80, 0x0833FC40, 0x101DF238, 0x23880124,
0x444400C2, 0x48240082, 0x49240082, 0x4F240044, 0x41040038, 0x20080000,
0x10100000, 0x08200000, 0x07C00000, 0x00000000 };

#endif
Loading

0 comments on commit f94b60a

Please sign in to comment.