Skip to content

Commit

Permalink
Complete re-write of application code for low power.
Browse files Browse the repository at this point in the history
  • Loading branch information
beegee-tokyo committed Feb 21, 2024
1 parent 94af03c commit 5f1c6d5
Show file tree
Hide file tree
Showing 43 changed files with 2,099 additions and 35,646 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
.vscode/launch.json
.vscode/ipch
Generated
Debug-Build
32,913 changes: 0 additions & 32,913 deletions Flash-Files/WisBlock_Comfort_V1.0.0_23.08.16_14.38_full.hex

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 RAKwireless
Copyright (c) 2024 RAKwireless

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ This firmware is using the [WisBlock API V2](https://github.com/beegee-tokyo/Wis
### _REMARK 2_
For the displays, the RAK14000 EPD module with a 4.2" display is used.

### _REMARK 2_
RAK12039 is only supported by the hardware version with permanent 5-24V power supply. The battery version does not include the RAK12039 due to its high power consumption.

----

# Content
Expand Down Expand Up @@ -73,7 +76,6 @@ For the displays, the RAK14000 EPD module with a 4.2" display is used.
- [Adafruit Unified Sensor](https://registry.platformio.org/libraries/adafruit/Adafruit%20Unified%20Sensor) ⤴️
- [ClosedCube OPT3001](https://github.com/beegee-tokyo/ClosedCube_OPT3001_Arduino) ⤴️
- [Melopero RV3028](https://registry.platformio.org/libraries/melopero/Melopero%20RV3028) ⤴️
- [nRF52_OLED](https://registry.platformio.org/libraries/beegee-tokyo/nRF52_OLED) ⤴️
- [RAK12019_LTR390_UV_Light](https://registry.platformio.org/libraries/beegee-tokyo/RAK12019_LTR390_UV_Light) ⤴️
- [RAKwireless VEML Light Sensor](https://registry.platformio.org/libraries/rakwireless/RAKwireless%20VEML%20Light%20Sensor) ⤴️
- [Sensirion Core](https://registry.platformio.org/libraries/sensirion/Sensirion%20Core) ⤴️
Expand Down
22 changes: 0 additions & 22 deletions create_uf2.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,6 @@ def create_uf2(source, target, env):
print(target + " is ready to flash to target device")
print("#########################################################")

# # Create bootloader UF2
# # source_hex = target[0].get_abspath()
# # source_hex = target[0].get_string(False)
# source_hex2 = '.\\Debug-Build\\wiscore_rak4631_board_bootloader-0.4.3.hex'
# print("#########################################################")
# print("Create Bootloader UF2 from "+source_hex2)
# print("#########################################################")
# # print("Source: " + source_hex)
# # target = source_hex.replace(".hex", "")
# target2 = ".\\Debug-Build\\wiscore_rak4631_board_bootloader-0.4.3.uf2"
# print("Bootloader Target: " + target2)

# with open(source_hex2, mode='rb') as f2:
# inpbuf2 = f2.read()

# outbuf2 = convert_from_hex_to_uf2(inpbuf2.decode("utf-8"))

# write_file(target2, outbuf2)
# print("#########################################################")
# print(target2 + " bootloader is ready to flash to target device")
# print("#########################################################")


# Add callback after .hex file was created
env.AddPostAction("$BUILD_DIR/${PROGNAME}.hex", create_uf2)
Expand Down
11 changes: 10 additions & 1 deletion src/modules/RAK14000_epd.h → include/RAK14000_epd.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ extern char *months_txt[];
// Forward declaration
void text_rak14000(int16_t x, int16_t y, char *text, uint16_t text_color, uint32_t text_size);
void scientific_rak14000(void);
void rak14000_start_screen(bool startup);
void status_ui_rak14000(void);
void voc_rak14000(void);
void co2_rak14000(bool has_pm);
void pm_rak14000(void);
Expand All @@ -74,6 +76,13 @@ void humid_rak14000(bool has_pm, bool has_baro);
void baro_rak14000(bool has_pm);
void icon_rak14000(void);
void draw_bar_rak14000(uint8_t level, uint16_t x, uint16_t y);
void light_rak14000(bool has_pm);
void set_voc_rak14000(uint16_t voc_value);
void set_temp_rak14000(float temp_value);
void set_humid_rak14000(float humid_value);
void set_co2_rak14000(float co2_value);
void set_baro_rak14000(float baro_value);
void set_pm_rak14000(uint16_t pm10_env, uint16_t pm25_env, uint16_t pm100_env);

extern unsigned char good_air[];
extern uint16_t good_air_width;
Expand Down Expand Up @@ -162,7 +171,7 @@ extern GFXfont RAK_EPD_20pt;
#define EPD_CS SS
#define EPD_DC WB_IO1
#define SRAM_CS -1 // not use
#define EPD_RESET -1 // not use
#define EPD_RESET - 1 // not use
#define EPD_BUSY WB_IO4

#define RGB_BLUE 0,0,255
Expand Down
39 changes: 0 additions & 39 deletions include/README

This file was deleted.

61 changes: 61 additions & 0 deletions include/cayenne_lpp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* @file cayenne_lpp.h
* @author Bernd Giesecke ([email protected])
* @brief Defines for RAK Cayenne LPP packet format
* @version 0.1
* @date 2024-02-08
*
* @copyright Copyright (c) 2024
*
*/
#ifndef _CAYENNE_LPP_H_
#define _CAYENNE_LPP_H_
#include <Arduino.h>

// Cayenne LPP Channel numbers per sensor value
#define LPP_CHANNEL_BATT 1 // Base Board
#define LPP_CHANNEL_HUMID 2 // RAK1901
#define LPP_CHANNEL_TEMP 3 // RAK1901
#define LPP_CHANNEL_PRESS 4 // RAK1902
#define LPP_CHANNEL_LIGHT 5 // RAK1903
#define LPP_CHANNEL_HUMID_2 6 // RAK1906
#define LPP_CHANNEL_TEMP_2 7 // RAK1906
#define LPP_CHANNEL_PRESS_2 8 // RAK1906
#define LPP_CHANNEL_GAS_2 9 // RAK1906
#define LPP_CHANNEL_GPS 10 // RAK1910/RAK12500
#define LPP_CHANNEL_SOIL_TEMP 11 // RAK12035
#define LPP_CHANNEL_SOIL_HUMID 12 // RAK12035
#define LPP_CHANNEL_SOIL_HUMID_RAW 13 // RAK12035
#define LPP_CHANNEL_SOIL_VALID 14 // RAK12035
#define LPP_CHANNEL_LIGHT2 15 // RAK12010
#define LPP_CHANNEL_VOC 16 // RAK12047
#define LPP_CHANNEL_GAS 17 // RAK12004
#define LPP_CHANNEL_GAS_PERC 18 // RAK12004
#define LPP_CHANNEL_CO2 19 // RAK12008
#define LPP_CHANNEL_CO2_PERC 20 // RAK12008
#define LPP_CHANNEL_ALC 21 // RAK12009
#define LPP_CHANNEL_ALC_PERC 22 // RAK12009
#define LPP_CHANNEL_TOF 23 // RAK12014
#define LPP_CHANNEL_TOF_VALID 24 // RAK12014
#define LPP_CHANNEL_GYRO 25 // RAK12025
#define LPP_CHANNEL_GESTURE 26 // RAK14008
#define LPP_CHANNEL_UVI 27 // RAK12019
#define LPP_CHANNEL_UVS 28 // RAK12019
#define LPP_CHANNEL_CURRENT_CURRENT 29 // RAK16000
#define LPP_CHANNEL_CURRENT_VOLTAGE 30 // RAK16000
#define LPP_CHANNEL_CURRENT_POWER 31 // RAK16000
#define LPP_CHANNEL_TOUCH_1 32 // RAK14002
#define LPP_CHANNEL_TOUCH_2 33 // RAK14002
#define LPP_CHANNEL_TOUCH_3 34 // RAK14002
#define LPP_CHANNEL_CO2_2 35 // RAK12037
#define LPP_CHANNEL_CO2_Temp_2 36 // RAK12037
#define LPP_CHANNEL_CO2_HUMID_2 37 // RAK12037
#define LPP_CHANNEL_TEMP_3 38 // RAK12003
#define LPP_CHANNEL_TEMP_4 39 // RAK12003
#define LPP_CHANNEL_PM_1_0 40 // RAK12039
#define LPP_CHANNEL_PM_2_5 41 // RAK12039
#define LPP_CHANNEL_PM_10_0 42 // RAK12039

extern WisCayenne g_solution_data;

#endif
40 changes: 40 additions & 0 deletions include/debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* @file debug.h
* @author Bernd Giesecke ([email protected])
* @brief Defines for Debug output
* @version 0.1
* @date 2024-02-08
*
* @copyright Copyright (c) 2024
*
*/
#ifndef _DEBUG_H_
#define _DEBUG_H_

#include <Arduino.h>

// Debug output set to 0 to disable app debug output
#ifndef MY_DEBUG
#define MY_DEBUG 0
#endif

#if MY_DEBUG > 0
#define MYLOG(tag, ...) \
do \
{ \
if (tag) \
PRINTF("[%s] ", tag); \
PRINTF(__VA_ARGS__); \
PRINTF("\n"); \
Serial.flush(); \
if (g_ble_uart_is_connected) \
{ \
g_ble_uart.printf(__VA_ARGS__); \
g_ble_uart.printf("\n"); \
} \
} while (0)
#else
#define MYLOG(...)
#endif

#endif // _DEBUG_H_
110 changes: 110 additions & 0 deletions include/main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* @file main.h
* @author Bernd Giesecke ([email protected])
* @brief Defines and includes
* @version 0.1
* @date 2024-02-13
*
* @copyright Copyright (c) 2024
*
*/
#ifndef _MAIN_H_
#define _MAIN_H_
#include <Arduino.h>
#include <WisBlock-API-V2.h>
#include <wisblock_cayenne.h>
#include "cayenne_lpp.h"
#include "modules.h"
#include <nrfx_power.h>
#include "debug.h"
#include "RAK14000_epd.h"

// RAK19024 Base Board
#define PIR_INT 25 // Interrupt pin for PIR
#define BUTTON_INT 24 // Input pin for Button
#define VOC_POWER 20 // VOC power enable pin
#define PIR_POWER 2 // PIR power enable pin
#define CO2_PM_POWER 28 // CO2 and PM power enable pin
#define EPD_POWER 34 // EPD power enable pin
#define SET_PIN WB_IO6 // PM sensor enable pin

/** Wakeup triggers for application events */
#define MOTION 0b1000000000000000
#define N_MOTION 0b0111111111111111
#define SEND_NOW 0b0100000000000000
#define N_SEND_NOW 0b1011111111111111
#define VOC_REQ 0b0010000000000000
#define N_VOC_REQ 0b1101111111111111
#define ROOM_EMPTY 0b0001000000000000
#define N_ROOM_EMPTY 0b1110111111111111
#define LED_REQ 0b0000100000000000
#define N_LED_REQ 0b1111011111111111
#define DISP_UPDATE 0b0000010000000000
#define N_DISP_UPDATE 0b1111101111111111
#define DISP_JOIN 0b0000001000000000
#define N_DISP_JOIN 0b1111110111111111
#define RST_REQ 0b0000000100000000
#define N_RST_REQ 0b1111111011111111
#define APP_EVENT 0b1111111110000001

// Structures and Unions
/** RTC date/time structure */
struct date_time_s
{
uint16_t year;
uint8_t month;
uint8_t weekday;
uint8_t date;
uint8_t hour;
uint8_t minute;
uint8_t second;
};

/** Define the version of your SW */
#ifndef SW_VERSION_1
#define SW_VERSION_1 1 // major version increase on API change / not backwards compatible
#define SW_VERSION_2 0 // minor version increase on API change / backward compatible
#define SW_VERSION_3 0 // patch version increase on bugfix, no affect on API
#endif

// Forward declarations
void send_delayed(TimerHandle_t unused);
void init_user_at(void);
void read_batt_settings(void);
void save_batt_settings(bool check_batt_enables);
void read_ui_settings(void);
void save_ui_settings(uint8_t ui_selected);

// Global Variables
extern WisCayenne g_solution_data;
extern date_time_s g_date_time;
extern SoftwareTimer g_sensor_timer;
extern SoftwareTimer voc_read_timer;
extern SoftwareTimer g_rgb_timer;
extern SoftwareTimer g_epd_off_timer;
extern bool has_rak1901;
extern bool has_rak1902;
extern bool has_rak1903;
extern bool has_rak1906;
extern bool has_rak12002;
extern bool has_rak12010;
extern bool has_rak12019;
extern bool has_rak12037;
extern bool has_rak12039;
extern bool has_rak12047;
extern bool g_has_rgb;
extern bool g_voc_valid;
extern float g_last_temp;
extern float g_last_humid;
extern float g_last_pressure;
extern float g_last_light_lux;
extern uint8_t g_ui_selected;
extern uint8_t g_ui_last;
extern uint8_t g_air_status;
extern bool g_status_changed;
extern bool g_occupied;
extern bool g_is_using_battery;
extern bool g_rgb_on;
extern time_t g_app_start_time;

#endif
Loading

0 comments on commit 5f1c6d5

Please sign in to comment.