Merge pull request #907 from cyberman54/development
Add CI & fix build errors & migrate RGB LED library
This commit is contained in:
commit
c2f2660473
65
.github/workflows/build.yml
vendored
65
.github/workflows/build.yml
vendored
@ -4,24 +4,59 @@ on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- master
|
||||
- build-workflow
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
os: [ubuntu-latest]
|
||||
# os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
path: ~/.cache/pip
|
||||
platformio-path: ~/.platformio
|
||||
- os: macos-latest
|
||||
path: ~/Library/Caches/pip
|
||||
platformio-path: ~/Library/Caches/platformio
|
||||
- os: windows-latest
|
||||
path: ~\AppData\Local\pip\Cache
|
||||
platformio-path: ~\AppData\Local\platformio\Cache
|
||||
- os: ubuntu-latest
|
||||
path: ~/.cache/pip
|
||||
platformio-path: ~/.platformio
|
||||
# - os: macos-latest
|
||||
# path: ~/Library/Caches/pip
|
||||
# platformio-path: ~/Library/Caches/platformio
|
||||
# - os: windows-latest
|
||||
# path: ~\AppData\Local\pip\Cache
|
||||
# platformio-path: ~\AppData\Local\platformio\Cache
|
||||
board:
|
||||
[
|
||||
ebox.h,
|
||||
eboxtube.h,
|
||||
ecopower.h,
|
||||
heltec.h,
|
||||
heltecv2.h,
|
||||
heltecv21.h,
|
||||
ttgov1.h,
|
||||
ttgov2.h,
|
||||
ttgov21old.h,
|
||||
ttgov21new.h,
|
||||
ttgofox.h,
|
||||
ttgobeam.h,
|
||||
ttgobeam10.h,
|
||||
ttgotdisplay.h,
|
||||
ttgotwristband.h,
|
||||
fipy.h,
|
||||
lopy.h,
|
||||
lopy4.h,
|
||||
lolin32litelora.h,
|
||||
lolin32lora.h,
|
||||
lolin32lite.h,
|
||||
wemos32oled.h,
|
||||
wemos32matrix.h,
|
||||
octopus32.h,
|
||||
tinypico.h,
|
||||
tinypicomatrix.h,
|
||||
m5core.h,
|
||||
m5fire.h,
|
||||
olimexpoeiso.h,
|
||||
]
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
@ -52,5 +87,9 @@ jobs:
|
||||
cp src/loraconf_sample.h src/loraconf.h
|
||||
cp src/ota_sample.conf src/ota.conf
|
||||
cp src/paxcounter_orig.conf src/paxcounter.conf
|
||||
- name: Run PlatformIO
|
||||
run: pio run
|
||||
- name: Clean
|
||||
run: pio run -t clean -e ci
|
||||
- name: Run PlatformIO CI for ${{ matrix.board }}
|
||||
env:
|
||||
CI_HALFILE: ${{ matrix.board }}
|
||||
run: pio run -e ci
|
||||
|
19
build.py
19
build.py
@ -27,7 +27,16 @@ haldir = os.path.join (srcdir, "hal")
|
||||
|
||||
# check if hal file is present in source directory
|
||||
halconfig = config.get("board", "halfile")
|
||||
|
||||
# check if hal file is set by ENV CI_HALFILE
|
||||
if os.getenv("CI_HALFILE"):
|
||||
# if set, use ENV CI_HALFILE
|
||||
print("CI_HALFILE ENV FOUND")
|
||||
# override halconfig
|
||||
halconfig = os.getenv("CI_HALFILE")
|
||||
|
||||
halconfigfile = os.path.join (haldir, halconfig)
|
||||
|
||||
if os.path.isfile(halconfigfile) and os.access(halconfigfile, os.R_OK):
|
||||
print("Parsing hardware configuration from " + halconfigfile)
|
||||
else:
|
||||
@ -98,10 +107,10 @@ env.Replace(PAXEXPRESS_API_TOKEN=apitoken)
|
||||
|
||||
# get runtime credentials and put them to compiler directive
|
||||
env.Append(BUILD_FLAGS=[
|
||||
u'-DWIFI_SSID=\\"' + mykeys["OTA_WIFI_SSID"] + '\\"',
|
||||
u'-DWIFI_PASS=\\"' + mykeys["OTA_WIFI_PASS"] + '\\"',
|
||||
u'-DPAXEXPRESS_USER=\\"' + mykeys["PAXEXPRESS_USER"] + '\\"',
|
||||
u'-DPAXEXPRESS_REPO=\\"' + mykeys["PAXEXPRESS_REPO"] + '\\"',
|
||||
u'-DWIFI_SSID=\\"' + mykeys["OTA_WIFI_SSID"] + '\\"',
|
||||
u'-DWIFI_PASS=\\"' + mykeys["OTA_WIFI_PASS"] + '\\"',
|
||||
u'-DPAXEXPRESS_USER=\\"' + mykeys["PAXEXPRESS_USER"] + '\\"',
|
||||
u'-DPAXEXPRESS_REPO=\\"' + mykeys["PAXEXPRESS_REPO"] + '\\"',
|
||||
u'-DPAXEXPRESS_PACKAGE=\\"' + package + '\\"',
|
||||
u'-DARDUINO_LMIC_PROJECT_CONFIG_H=' + lmicconfig,
|
||||
u'-I \"' + srcdir + '\"'
|
||||
@ -127,7 +136,7 @@ def publish_paxexpress(source, target, env):
|
||||
}
|
||||
|
||||
r = None
|
||||
|
||||
|
||||
try:
|
||||
r = requests.put(url,
|
||||
data=open(firmware_path, "rb"),
|
||||
|
@ -5,7 +5,9 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
// Time functions
|
||||
#ifdef HAS_RTC
|
||||
#include <RtcDateTime.h>
|
||||
#endif
|
||||
#include <Ticker.h>
|
||||
|
||||
// std::set for unified array functions
|
||||
|
@ -1,9 +1,12 @@
|
||||
#ifndef _LED_H
|
||||
#define _LED_H
|
||||
|
||||
#ifdef RGB_LED_COUNT
|
||||
#include <SmartLeds.h>
|
||||
#ifdef HAS_RGB_LED
|
||||
#define FASTLED_INTERNAL
|
||||
#include <FastLED.h>
|
||||
#include "libpax_helpers.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAS_LORA
|
||||
#include "lorawan.h"
|
||||
#endif
|
||||
@ -12,39 +15,26 @@
|
||||
#define RGB_LED_COUNT 1
|
||||
#endif
|
||||
|
||||
// value for HSL color
|
||||
// see http://www.workwithcolor.com/blue-color-hue-range-01.htm
|
||||
#define COLOR_RED 0
|
||||
#define COLOR_ORANGE 30
|
||||
#define COLOR_ORANGE_YELLOW 45
|
||||
#define COLOR_YELLOW 60
|
||||
#define COLOR_YELLOW_GREEN 90
|
||||
#define COLOR_GREEN 120
|
||||
#define COLOR_GREEN_CYAN 165
|
||||
#define COLOR_CYAN 180
|
||||
#define COLOR_CYAN_BLUE 210
|
||||
#define COLOR_BLUE 240
|
||||
#define COLOR_BLUE_MAGENTA 275
|
||||
#define COLOR_MAGENTA 300
|
||||
#define COLOR_PINK 350
|
||||
#define COLOR_WHITE 360
|
||||
#define COLOR_NONE 999
|
||||
|
||||
struct RGBColor {
|
||||
uint8_t R;
|
||||
uint8_t G;
|
||||
uint8_t B;
|
||||
};
|
||||
|
||||
enum led_states { LED_OFF, LED_ON };
|
||||
|
||||
enum colors {
|
||||
COLOR_WHITE = 0xFFFFFF,
|
||||
COLOR_NONE = 0x000000,
|
||||
COLOR_CYAN = 0x00FFFF,
|
||||
COLOR_BLUE = 0x0000FF,
|
||||
COLOR_GREEN = 0x008000,
|
||||
COLOR_YELLOW = 0xFFFF00,
|
||||
COLOR_ORANGE = 0xFFA500,
|
||||
COLOR_RED = 0xFF0000,
|
||||
COLOR_PINK = 0xFFC0CB
|
||||
};
|
||||
|
||||
extern TaskHandle_t ledLoopTask;
|
||||
|
||||
// Exported Functions
|
||||
void rgb_set_color(uint16_t hue);
|
||||
void blink_LED(uint16_t set_color, uint16_t set_blinkduration);
|
||||
void rgb_led_init(void);
|
||||
void rgb_set_color(uint32_t color);
|
||||
void ledLoop(void *parameter);
|
||||
void switch_LED(uint8_t state);
|
||||
void switch_LED1(uint8_t state);
|
||||
void switch_LED(led_states state);
|
||||
void switch_LED1(led_states state);
|
||||
|
||||
#endif
|
@ -6,6 +6,8 @@
|
||||
#include "LEDMatrix.h"
|
||||
#include "ledmatrixfonts.h"
|
||||
#include "ledmatrixdisplay.h"
|
||||
#include "configmanager.h"
|
||||
#include <libpax_api.h>
|
||||
|
||||
extern uint8_t MatrixDisplayIsOn;
|
||||
extern LEDMatrix matrix;
|
||||
|
@ -33,6 +33,10 @@
|
||||
#elif HAS_SDCARD == 2 // MMC interface
|
||||
#include "driver/sdmmc_host.h"
|
||||
|
||||
#ifndef SDCARD_SLOTCONFIG
|
||||
#define SDCARD_SLOTCONFIG SDMMC_SLOT_CONFIG_DEFAULT()
|
||||
#endif
|
||||
|
||||
#ifndef SDCARD_SLOTWIDTH
|
||||
#define SDCARD_SLOTWIDTH 1
|
||||
#endif
|
||||
|
@ -67,7 +67,7 @@ lib_deps_display =
|
||||
lib_deps_ledmatrix =
|
||||
seeed-studio/Ultrathin_LED_Matrix @ ^1.0.0
|
||||
lib_deps_rgbled =
|
||||
https://github.com/RoboticsBrno/SmartLeds.git
|
||||
fastled/FastLED @ ^3.5.0
|
||||
lib_deps_gps =
|
||||
mikalhart/TinyGPSPlus @ ^1.0.3
|
||||
lib_deps_sensors =
|
||||
@ -82,7 +82,7 @@ lib_deps_basic =
|
||||
https://github.com/SukkoPera/Arduino-Rokkit-Hash.git
|
||||
bblanchon/ArduinoJson @ ^6
|
||||
makuna/RTC @ ^2.3.5
|
||||
spacehuhn/SimpleButton
|
||||
spacehuhn/SimpleButton
|
||||
lewisxhe/XPowersLib @ ^0.1.4
|
||||
256dpi/MQTT @ ^2.5.0
|
||||
lib_deps_all =
|
||||
@ -94,7 +94,6 @@ lib_deps_all =
|
||||
${common.lib_deps_sensors}
|
||||
${common.lib_deps_ledmatrix}
|
||||
build_flags_basic =
|
||||
-include "src/hal/${board.halfile}"
|
||||
-include "src/paxcounter.conf"
|
||||
'-DCORE_DEBUG_LEVEL=${common.debug_level}'
|
||||
'-DLOG_LOCAL_LEVEL=${common.debug_level}'
|
||||
@ -115,7 +114,9 @@ upload_speed = ${common.upload_speed}
|
||||
;upload_port = COM12
|
||||
platform = ${common.platform_espressif32}
|
||||
lib_deps = ${common.lib_deps_all}
|
||||
build_flags = ${common.build_flags_all}
|
||||
build_flags =
|
||||
-include "src/hal/${board.halfile}"
|
||||
${common.build_flags_all}
|
||||
upload_protocol = ${common.upload_protocol}
|
||||
extra_scripts = ${common.extra_scripts}
|
||||
monitor_speed = ${common.monitor_speed}
|
||||
@ -131,3 +132,9 @@ upload_protocol = esptool
|
||||
upload_protocol = esptool
|
||||
platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream
|
||||
platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git
|
||||
|
||||
[env:ci]
|
||||
build_flags =
|
||||
-include "src/hal/${sysenv.CI_HALFILE}" ; set by CI
|
||||
${common.build_flags_all}
|
||||
upload_protocol = esptool
|
@ -15,7 +15,7 @@
|
||||
|
||||
#define HAS_LED (22) // Green LED on board
|
||||
#define RGB_LED_COUNT 1 // we have 1 LED
|
||||
#define HAS_RGB_LED SmartLed rgb_led(LED_WS2812, RGB_LED_COUNT, GPIO_NUM_2) // WS2812B RGB LED on board
|
||||
#define HAS_RGB_LED FastLED.addLeds<WS2812, GPIO_NUM_2, GRB>(leds, RGB_LED_COUNT);
|
||||
#define HAS_BUTTON (0) // button "FLASH" on board
|
||||
#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature
|
||||
|
||||
|
@ -13,7 +13,8 @@
|
||||
|
||||
#define CFG_sx1272_radio 1
|
||||
#define HAS_LED NOT_A_PIN // FiPy has no on board LED, so we use RGB LED
|
||||
#define HAS_RGB_LED SmartLed rgb_led(LED_WS2812, 1, GPIO_NUM_0) // WS2812B RGB LED on GPIO0
|
||||
#define RGB_LED_COUNT 1 // we have 1 LED
|
||||
#define HAS_RGB_LED FastLED.addLeds<WS2812, GPIO_NUM_0, GRB>(leds, RGB_LED_COUNT);
|
||||
#define BOARD_HAS_PSRAM // use extra 4MB extern RAM
|
||||
|
||||
// Pins for LORA chip SPI interface, reset line and interrupt lines
|
||||
|
@ -72,7 +72,8 @@
|
||||
|
||||
#define HAS_LED (21) // on board LED
|
||||
#define HAS_BUTTON (39) // on board button
|
||||
#define HAS_RGB_LED SmartLed rgb_led(LED_WS2812, 1, GPIO_NUM_0) // WS2812B RGB LED on GPIO0
|
||||
#define RGB_LED_COUNT 1 // we have 1 LED
|
||||
#define HAS_RGB_LED FastLED.addLeds<WS2812, GPIO_NUM_0, GRB>(leds, RGB_LED_COUNT);
|
||||
|
||||
// GPS settings
|
||||
#define HAS_GPS 1 // use on board GPS
|
||||
|
@ -17,7 +17,8 @@
|
||||
//#define MY_DISPLAY_FLIP 1 // uncomment this for rotated display
|
||||
#define HAS_LED 22 // ESP32 GPIO12 (pin22) On Board LED (set to NOT_A_PIN to disable)
|
||||
#define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW
|
||||
#define HAS_RGB_LED SmartLed rgb_led(LED_WS2812, 1, GPIO_NUM_13) // ESP32 GPIO13 (pin13) On Board Shield WS2812B RGB LED
|
||||
#define RGB_LED_COUNT 1 // we have 1 LED
|
||||
#define HAS_RGB_LED FastLED.addLeds<WS2812, GPIO_NUM_0, GRB>(leds, RGB_LED_COUNT);
|
||||
#define HAS_BUTTON 15 // ESP32 GPIO15 (pin15) Button is on the LoraNode32 shield
|
||||
#define BUTTON_PULLUP 1 // Button need pullup instead of default pulldown
|
||||
|
||||
|
@ -18,7 +18,8 @@
|
||||
#define HAS_LED NOT_A_PIN // Led os on same pin as Lora SS pin, to avoid problems, we don't use it
|
||||
#define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW
|
||||
// Anyway shield is on over the LoLin32 board, so we won't be able to see this LED
|
||||
#define HAS_RGB_LED SmartLed rgb_led(LED_WS2812, 1, GPIO_NUM_13) // ESP32 GPIO13 (pin13) On Board Shield WS2812B RGB LED
|
||||
#define RGB_LED_COUNT 1 // we have 1 LED
|
||||
#define HAS_RGB_LED FastLED.addLeds<WS2812, GPIO_NUM_13, GRB>(leds, RGB_LED_COUNT);
|
||||
#define HAS_BUTTON 15 // ESP32 GPIO15 (pin15) Button is on the LoraNode32 shield
|
||||
#define BUTTON_PULLUP 1 // Button need pullup instead of default pulldown
|
||||
|
||||
|
@ -12,7 +12,8 @@
|
||||
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
|
||||
#define CFG_sx1272_radio 1
|
||||
#define HAS_LED NOT_A_PIN // LoPy4 has no on board mono LED, we use on board RGB LED
|
||||
#define HAS_RGB_LED SmartLed rgb_led(LED_WS2812, 1, GPIO_NUM_0) // WS2812B RGB LED on GPIO0 (P2)
|
||||
#define RGB_LED_COUNT 1 // we have 1 LED
|
||||
#define HAS_RGB_LED FastLED.addLeds<WS2812, GPIO_NUM_0, GRB>(leds, RGB_LED_COUNT);
|
||||
|
||||
// Note: Pins for LORA chip SPI interface come from board file pins_arduino.h
|
||||
|
||||
|
@ -21,7 +21,8 @@
|
||||
#define CFG_sx1276_radio 1
|
||||
#define HAS_LED NOT_A_PIN // LoPy4 has no on board mono LED, we use on board RGB LED
|
||||
#define RGB_LED_COUNT 1 // we have 1 LEDs
|
||||
#define HAS_RGB_LED SmartLed rgb_led(LED_WS2812, RGB_LED_COUNT, GPIO_NUM_0) // WS2812B RGB LED on GPIO0 (P2)
|
||||
#define RGB_LED_COUNT 1 // we have 1 LED
|
||||
#define HAS_RGB_LED FastLED.addLeds<WS2812, GPIO_NUM_0, GRB>(leds, RGB_LED_COUNT);
|
||||
#define BOARD_HAS_PSRAM // use extra 4MB extern RAM
|
||||
|
||||
// Note: Pins for LORA chip SPI interface come from board file pins_arduino.h
|
||||
|
@ -38,10 +38,10 @@
|
||||
#define PMU_CHG_CUTOFF 0 // battery charge cutoff
|
||||
// possible values: *0:4.2V, 1:4.3V, 2:4.35V, 3:4.4V
|
||||
|
||||
// GPS settings
|
||||
#define HAS_GPS 1 // use on board GPS
|
||||
#define GPS_SERIAL 9600, SERIAL_8N1, RXD2, TXD2 // UBlox NEO 6M RX, TX
|
||||
#define GPS_INT
|
||||
// Optional GPS Module settings
|
||||
//#define HAS_GPS 1 // use GPS
|
||||
//#define GPS_SERIAL 9600, SERIAL_8N1, GPIO_NUM_17, GPIO_NUM_16 // UBlox NEO M8N RX,TX
|
||||
//#define GPS_INT GPIO_NUM_36 // 30ns accurary timepulse, to be external wired on pcb: shorten R12!
|
||||
|
||||
// Display Settings
|
||||
#define HAS_DISPLAY 2 // TFT-LCD
|
||||
|
@ -33,7 +33,8 @@
|
||||
#define HAS_LED NOT_A_PIN // no on board LED (?)
|
||||
#define RGB_LED_COUNT 10
|
||||
|
||||
#define HAS_RGB_LED SmartLed rgb_led(LED_SK6812, RGB_LED_COUNT, GPIO_NUM_15) // LED_SK6812 RGB LED on GPIO15
|
||||
#define RGB_LED_COUNT 1 // we have 1 LED
|
||||
#define HAS_RGB_LED FastLED.addLeds<SK6812, GPIO_NUM_15, GRB>(leds, RGB_LED_COUNT);
|
||||
#define HAS_BUTTON (39) // on board button A
|
||||
|
||||
// power management settings
|
||||
@ -43,10 +44,10 @@
|
||||
#define PMU_CHG_CUTOFF 0 // battery charge cutoff
|
||||
// possible values: *0:4.2V, 1:4.3V, 2:4.35V, 3:4.4V
|
||||
|
||||
// GPS settings
|
||||
#define HAS_GPS 0 // use on board GPS
|
||||
#define GPS_SERIAL 9600, SERIAL_8N1, RXD2, TXD2 // UBlox NEO 6M RX, TX
|
||||
// #define GPS_INT GPIO_NUM_35 // 30ns accurary timepulse, to be external wired on pcb: shorten R12!
|
||||
// Optional GPS Module settings
|
||||
//#define HAS_GPS 1 // use GPS
|
||||
//#define GPS_SERIAL 9600, SERIAL_8N1, GPIO_NUM_5, GPIO_NUM_13 // to be external wired on pcb: open R1 & R4, and shorten R2 & R5
|
||||
//#define GPS_INT GPIO_NUM_36 // 30ns accurary timepulse, to be external wired on pcb: shorten R12!
|
||||
|
||||
// Display Settings
|
||||
#define HAS_DISPLAY 2 // TFT-LCD
|
||||
|
@ -22,7 +22,8 @@
|
||||
|
||||
#define HAS_LED 13 // ESP32 GPIO12 (pin22) On Board LED
|
||||
//#define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW
|
||||
//#define HAS_RGB_LED SmartLed rgb_led(LED_WS2812, 1, GPIO_NUM_13) // ESP32 GPIO13 (pin13) On Board Shield WS2812B RGB LED
|
||||
//#define RGB_LED_COUNT 1 // we have 1 LED
|
||||
//#define HAS_RGB_LED FastLED.addLeds<WS2812, GPIO_NUM_13, GRB>(leds, RGB_LED_COUNT);
|
||||
//#define HAS_BUTTON 15 // ESP32 GPIO15 (pin15) Button is on the LoraNode32 shield
|
||||
//#define BUTTON_PULLUP 1 // Button need pullup instead of default pulldown
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
// Hardware related definitions for crowdsupply tinypico board
|
||||
|
||||
#define HAS_LED NOT_A_PIN // Green LED on board
|
||||
#define HAS_RGB_LED Apa102 rgb_led(1, GPIO_NUM_12, GPIO_NUM_2) // APA102 RGB LED on board
|
||||
#define HAS_RGB_LED FastLED.addLeds<APA102, GPIO_NUM_2, GPIO_NUM_12, BGR>(leds, RGB_LED_COUNT)
|
||||
|
||||
//#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature
|
||||
#define BAT_MEASURE_ADC ADC1_GPIO35_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7
|
||||
|
@ -12,7 +12,7 @@
|
||||
// for operating a 96x16 shift register LED matrix display
|
||||
|
||||
#define HAS_LED NOT_A_PIN // Green LED on board
|
||||
#define HAS_RGB_LED Apa102 rgb_led(1, GPIO_NUM_12, GPIO_NUM_2) // APA102 RGB LED on board
|
||||
#define HAS_RGB_LED FastLED.addLeds<APA102, GPIO_NUM_2, GPIO_NUM_12, BGR>(leds, RGB_LED_COUNT)
|
||||
|
||||
//#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature
|
||||
#define BAT_MEASURE_ADC ADC1_GPIO35_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7
|
||||
|
112
src/led.cpp
112
src/led.cpp
@ -2,94 +2,36 @@
|
||||
#include "globals.h"
|
||||
#include "led.h"
|
||||
|
||||
led_states LEDState = LED_OFF; // LED state global for state machine
|
||||
static led_states LEDState = LED_OFF; // LED state global for state machine
|
||||
led_states previousLEDState =
|
||||
LED_ON; // This will force LED to be off at boot since State is OFF
|
||||
|
||||
TaskHandle_t ledLoopTask;
|
||||
|
||||
uint16_t LEDColor = COLOR_NONE, LEDBlinkDuration = 0; // state machine variables
|
||||
unsigned long LEDBlinkStarted = 0; // When (in millis() led blink started)
|
||||
uint32_t LEDColor = COLOR_NONE, LEDBlinkDuration = 0; // state machine variables
|
||||
static unsigned long LEDBlinkStarted =
|
||||
0; // When (in millis() led blink started)
|
||||
|
||||
#ifdef HAS_RGB_LED
|
||||
|
||||
// RGB Led instance
|
||||
HAS_RGB_LED;
|
||||
|
||||
float rgb_CalcColor(float p, float q, float t) {
|
||||
if (t < 0.0f)
|
||||
t += 1.0f;
|
||||
if (t > 1.0f)
|
||||
t -= 1.0f;
|
||||
|
||||
if (t < 1.0f / 6.0f)
|
||||
return p + (q - p) * 6.0f * t;
|
||||
|
||||
if (t < 0.5f)
|
||||
return q;
|
||||
|
||||
if (t < 2.0f / 3.0f)
|
||||
return p + ((q - p) * (2.0f / 3.0f - t) * 6.0f);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Hue, Saturation, Lightness color members
|
||||
// HslColor using H, S, L values (0.0 - 1.0)
|
||||
// L should be limited to between (0.0 - 0.5)
|
||||
// ------------------------------------------------------------------------
|
||||
RGBColor rgb_hsl2rgb(float h, float s, float l) {
|
||||
RGBColor RGB_color;
|
||||
float r;
|
||||
float g;
|
||||
float b;
|
||||
|
||||
if (s == 0.0f || l == 0.0f) {
|
||||
r = g = b = l; // achromatic or black
|
||||
} else {
|
||||
float q = l < 0.5f ? l * (1.0f + s) : l + s - (l * s);
|
||||
float p = 2.0f * l - q;
|
||||
r = rgb_CalcColor(p, q, h + 1.0f / 3.0f);
|
||||
g = rgb_CalcColor(p, q, h);
|
||||
b = rgb_CalcColor(p, q, h - 1.0f / 3.0f);
|
||||
}
|
||||
|
||||
RGB_color.R = (uint8_t)(r * 255.0f);
|
||||
RGB_color.G = (uint8_t)(g * 255.0f);
|
||||
RGB_color.B = (uint8_t)(b * 255.0f);
|
||||
|
||||
return RGB_color;
|
||||
}
|
||||
|
||||
void rgb_set_color(uint16_t hue) {
|
||||
if (hue == COLOR_NONE) {
|
||||
// set Off
|
||||
for (int i = 0; i < RGB_LED_COUNT; i++)
|
||||
rgb_led[i] = Rgb(0, 0, 0);
|
||||
} else {
|
||||
// see http://www.workwithcolor.com/blue-color-hue-range-01.htm
|
||||
// H (is color from 0..360) should be between 0.0 and 1.0
|
||||
// S is saturation keep it to 1
|
||||
// L is brightness should be between 0.0 and 0.5
|
||||
// cfg.rgblum is between 0 and 100 (percent)
|
||||
RGBColor target = rgb_hsl2rgb(hue / 360.0f, 1.0f, 0.005f * cfg.rgblum);
|
||||
// uint32_t color = target.R<<16 | target.G<<8 | target.B;
|
||||
for (int i = 0; i < RGB_LED_COUNT; i++)
|
||||
rgb_led[i] = Rgb(target.R, target.G, target.B);
|
||||
}
|
||||
// Show
|
||||
rgb_led.show();
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// No RGB LED empty functions
|
||||
void rgb_set_color(uint16_t hue) {}
|
||||
|
||||
CRGB leds[RGB_LED_COUNT];
|
||||
#endif
|
||||
|
||||
void switch_LED(uint8_t state) {
|
||||
void rgb_set_color(uint32_t color) {
|
||||
#ifdef HAS_RGB_LED
|
||||
for (int i = 0; i < RGB_LED_COUNT; i++)
|
||||
leds[i] = CRGB(color);
|
||||
FastLED.show();
|
||||
#endif
|
||||
}
|
||||
|
||||
void rgb_led_init(void) {
|
||||
#ifdef HAS_RGB_LED
|
||||
HAS_RGB_LED;
|
||||
rgb_set_color(COLOR_NONE);
|
||||
#endif
|
||||
}
|
||||
|
||||
void switch_LED(led_states state) {
|
||||
#if (HAS_LED != NOT_A_PIN)
|
||||
if (state == LED_ON) {
|
||||
// switch LED on
|
||||
@ -109,7 +51,7 @@ void switch_LED(uint8_t state) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void switch_LED1(uint8_t state) {
|
||||
void switch_LED1(led_states state) {
|
||||
#ifdef HAS_TWO_LED
|
||||
if (state == LED_ON) {
|
||||
// switch LED on
|
||||
@ -129,14 +71,6 @@ void switch_LED1(uint8_t state) {
|
||||
#endif // HAS_TWO_LED
|
||||
}
|
||||
|
||||
void blink_LED(uint16_t set_color, uint16_t set_blinkduration) {
|
||||
#if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED)
|
||||
LEDColor = set_color; // set color for RGB LED
|
||||
LEDBlinkDuration = set_blinkduration; // duration
|
||||
LEDBlinkStarted = millis(); // Time Start here
|
||||
LEDState = LED_ON; // Let main set LED on
|
||||
#endif
|
||||
}
|
||||
|
||||
#if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED)
|
||||
|
||||
@ -215,4 +149,4 @@ void ledLoop(void *parameter) {
|
||||
} // while(1)
|
||||
}; // ledloop()
|
||||
|
||||
#endif // #if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED)
|
||||
#endif // #if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED)
|
12
src/main.cpp
12
src/main.cpp
@ -201,26 +201,26 @@ void setup() {
|
||||
#endif
|
||||
|
||||
// initialize leds
|
||||
#ifdef HAS_RGB_LED
|
||||
rgb_led_init();
|
||||
strcat_P(features, " RGB");
|
||||
#endif
|
||||
|
||||
#if (HAS_LED != NOT_A_PIN)
|
||||
pinMode(HAS_LED, OUTPUT);
|
||||
strcat_P(features, " LED");
|
||||
|
||||
#ifdef LED_POWER_SW
|
||||
pinMode(LED_POWER_SW, OUTPUT);
|
||||
digitalWrite(LED_POWER_SW, LED_POWER_ON);
|
||||
#endif
|
||||
|
||||
#ifdef HAS_TWO_LED
|
||||
pinMode(HAS_TWO_LED, OUTPUT);
|
||||
strcat_P(features, " LED2");
|
||||
#endif
|
||||
|
||||
// use LED for power display if we have additional RGB LED, else for status
|
||||
// use simple LED for power display if we have additional RGB LED, else for status
|
||||
#ifdef HAS_RGB_LED
|
||||
switch_LED(LED_ON);
|
||||
strcat_P(features, " RGB");
|
||||
#endif
|
||||
|
||||
#endif // HAS_LED
|
||||
|
||||
#if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED)
|
||||
|
@ -97,7 +97,7 @@
|
||||
#define RCMDPORT 2 // remote commands
|
||||
#define STATUSPORT 2 // remote command results
|
||||
#define CONFIGPORT 3 // config query results
|
||||
#define GPSPORT 4 // gps - NOTE: set to 1 to send combined GPS+COUNTERPORT payload
|
||||
#define GPSPORT 4 // gps - NOTE: set to 1 to send combined GPS+COUNTERPORT payload
|
||||
#define BUTTONPORT 5 // button pressed signal
|
||||
#define RESERVEDPORT 6 // reserved (unused)
|
||||
#define BMEPORT 7 // BME680 sensor
|
||||
@ -126,4 +126,4 @@
|
||||
#define MQTT_PASSWD "public"
|
||||
#define MQTT_RETRYSEC 20 // retry reconnect every 20 seconds
|
||||
#define MQTT_KEEPALIVE 10 // keep alive interval in seconds
|
||||
//#define MQTT_CLIENTNAME "my_paxcounter" // generated by default
|
||||
//#define MQTT_CLIENTNAME "my_paxcounter" // generated by default
|
@ -132,7 +132,7 @@ bool sdcard_init(bool create) {
|
||||
// has these signals.
|
||||
// Default config for SDMMC_HOST_DEFAULT (4-bit bus width, slot 1)
|
||||
// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/sdmmc_host.html
|
||||
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
|
||||
sdmmc_slot_config_t slot_config = SDCARD_SLOTCONFIG;
|
||||
|
||||
// Set 1-line or 4-line SD mode (default is 1-line)
|
||||
slot_config.width = SDCARD_SLOTWIDTH;
|
||||
|
@ -18,7 +18,8 @@ static float pm10 = 0.0, pm25 = 0.0;
|
||||
|
||||
// init
|
||||
bool sds011_init() {
|
||||
sds.begin(9600, SERIAL_8N1, SDS_RX, SDS_TX);
|
||||
Serial2.begin(9600, SERIAL_8N1, SDS_RX, SDS_TX);
|
||||
sds.begin();
|
||||
sds011_wakeup();
|
||||
ESP_LOGI(TAG, "SDS011: %s", sds.queryFirmwareVersion().toString().c_str());
|
||||
sds.setQueryReportingMode();
|
||||
|
Loading…
Reference in New Issue
Block a user