32#include <SensirionI2CSht4x.h>
33#include <Adafruit_DPS310.h>
48#define DEVICE_MANUFACTURER "Flying Silicon"
50#define DEVICE_NAME "FS-SP4"
52#define DEVICE_SERIAL "23-001"
55#define ACTIVE_WITH_USB 0
70#define AUTO_OFF_MS 3600000
76#define PATCH_LEDR digitalWrite(LEDR, HIGH)
83#define IntervalMSG 125
85#define IntervalSDP IntervalMSG
87#define IntervalDPS IntervalMSG
89#define IntervalSHT 1000
91#define IntervalPWR 1000
93#define IntervalPOL IntervalMSG
96#define LoopPassiveMs 125
103#define IdleIntervalLED 1250
105#define IdleLightLED 625
108#define IntervalLED 2500
136static SensirionI2CSht4x
sht;
139static Adafruit_DPS310
dps;
223 pinMode(
LEDB, OUTPUT);
224 digitalWrite(
LEDB, HIGH);
226 pinMode(
LEDG, OUTPUT);
227 digitalWrite(
LEDG, HIGH);
229 pinMode(
LEDR, OUTPUT);
230 digitalWrite(
LEDR, HIGH);
238 const int ret =
sdp.readSample();
240 LOGL(
"No data from SDP")
261 if (!
dps.temperatureAvailable())
263 if (!
dps.pressureAvailable())
266 sensors_event_t temp_event, pressure_event;
267 dps.getEvents(&temp_event, &pressure_event);
282 sht.measureHighPrecision(t, h);
300static void flashBlueLED(
int active,
unsigned int intervalMs,
unsigned int lightMs) {
308 digitalWrite(
LEDB, LOW);
318 digitalWrite(
LEDB, HIGH);
586 analogReadResolution(12);
616 Serial.begin(115200);
626 while (
sdp.init() != 0) {
635 while (!
dps.begin_I2C()) {
643 dps.configurePressure(DPS310_64HZ, DPS310_8SAMPLES);
644 dps.configureTemperature(DPS310_64HZ, DPS310_8SAMPLES);
void init(const char *deviceName)
void sendMetaMsg(const String &mna, const String &mmo, const String &msn)
void sendShortMsg(const SensorData &data)
void sendLongMsg(const SensorData &data)
int getReceived(String &cmd)
void clrReceived()
Clear anything received so far.
#define LOG(s)
Debug log inactive.
#define DEBUG
Enable/disable debugging.
#define LOGL(s)
Debug log inactive.
Support for nrf52 deep sleep / low power modes.
void enterDeepSleep(void)
int setLowPowerMode(void)
#define AUTO_OFF_MS
Delay before auto power off (without BLE connection)
static void loopConnected(void)
#define LoopPassiveMs
Loop interval ms when disabled.
static void suspend(void)
static void flashBlueLED(int active, unsigned int intervalMs, unsigned int lightMs)
#define ACTIVE_WITH_USB
Run or stay passive (and charge) when USB is connected.
#define IntervalSDP
SDP read interval ms.
static void disable(void)
static unsigned long lastSHTMs
Last read SHT ambient temperature/humidity.
static Adafruit_DPS310 dps
Infineon DPS310 for barometric pressure.
static void configure(void)
static void readSHT(void)
static void readSDP(void)
#define IntervalPOL
Time ms before BLE receive repeats.
#define IntervalSHT
SHT read interval ms.
#define IntervalMSG
Message send interval ms (critical)
static SensirionI2CSht4x sht
Sensirion SHT for temperature / humidity.
static PtvBleInterface::SensorData sensorData
Sensor data to work with.
static unsigned long lastMSGMs
Last time message sent.
static PtvBleInterface Remote
Singleton connection to be used (all BLE stuff is singleton)
#define FLASH_ALWAYS
Flash blue LED (when BLE connected) also when running on battery.
static int isEnabled
Operating mode 0/1.
#define DEVICE_NAME
Device name meta data (also sent in BLE advertising, truncated to 31)
#define DEVICE_SERIAL
Serial number meta data.
static void readDPS(void)
#define IdleLightLED
Time LED is on.
static void processCmd(const String &cmd)
#define PATCH_LEDR
Patch the red LED which is going on when BLE device is bonded.
static unsigned long lastActiveMs
static unsigned long lastLEDMs
Last LED state change.
#define LoopIdleMs
Loop interval when not connected.
#define LightLED
Time LED is on.
#define NopDelayMs
Delay ms when no message needs to be sent.
#define IntervalDPS
DPS read interval ms.
static void loopIdle(void)
static int isConnected
Connection state 0/1.
static void resetStatus(void)
static void resetTimers(void)
#define SEND_LONG
Use the long PTVSOAR message format also for data.
#define IdleIntervalLED
LED flashing interval when BLE is active but disconnected.
#define DEVICE_MANUFACTURER
Manufacturer meta data.
static unsigned long timeMs
Current loop time ms.
#define IntervalLED
LED flashing interval when BLE is active and connected.
static void clearLEDs(void)
static unsigned int sentMeta
Meta data repetition counter.
static unsigned long lastPWRMs
Last read of battery/voltage status.
static unsigned long lastDPSMs
Last read DPS atmospheric pressure.
static void loopPassive(void)
#define IntervalPWR
Power state update interval ms.
static int isBlueLedOn
LED blinking state 0/1.
static void managePower()
static SDP3XSensor sdp
Sensirion SDP31 for Pitot.
static unsigned long lastPOLMs
Last BLE receive poll.
static unsigned long lastSDPMs
Last read SDP differential pressure.
static const int Melody[]
Startup melody.
#define META_REPEAT
Number of meta headers to send on (re)connect.
void playDisconnect(void)
void playMelody(const int melody[])
void playBattery(float batPct)
Pin definitions for Seeed XIAO nRF52840 2.9.2 with Adafruit bluefruit library.
Extension of BleInterface providing the PTV / PTVSOAR protocol formats.
Manage power supply status of the device.
Varios methods to produce the buzzer sounds.
int isCharging
Charging state.
float batPct
Battery charge %.
float batVolt
Battery Voltage.
float diffPa
SDP31 differential pressure Pa.
float humPct
SHT humidity %.
float tempC
SHT temperature °C.
float absHpa
DPS310 barometric pressure hPa.