Flying Silicon Sensor
|
Sketch main module. More...
#include <Arduino.h>
#include <Wire.h>
#include <sdpsensor.h>
#include <SensirionI2CSht4x.h>
#include <Adafruit_DPS310.h>
#include "pindefs.h"
#include "sounds.h"
#include "debug.h"
#include "ptvBleInterface.h"
#include "deepSleep.h"
#include "pwrSupply.h"
Go to the source code of this file.
Macros | |
#define | DEVICE_MANUFACTURER "Flying Silicon" |
Manufacturer meta data. | |
#define | DEVICE_NAME "FS-SP4" |
Device name meta data (also sent in BLE advertising, truncated to 31) | |
#define | DEVICE_SERIAL "23-001" |
Serial number meta data. | |
#define | ACTIVE_WITH_USB 0 |
Run or stay passive (and charge) when USB is connected. | |
#define | FLASH_ALWAYS 1 |
Flash blue LED (when BLE connected) also when running on battery. | |
#define | SEND_LONG 0 |
Use the long PTVSOAR message format also for data. | |
#define | DEEP_SLEEP 1 |
Enter deep sleep when battery drained (else suspend loop) | |
#define | AUTO_OFF_MS 3600000 |
Delay before auto power off (without BLE connection) | |
#define | META_REPEAT 16 |
Number of meta headers to send on (re)connect. | |
#define | PATCH_LEDR digitalWrite(LEDR, HIGH) |
Patch the red LED which is going on when BLE device is bonded. | |
#define | IntervalMSG 125 |
Message send interval ms (critical) | |
#define | IntervalSDP IntervalMSG |
SDP read interval ms. | |
#define | IntervalDPS IntervalMSG |
DPS read interval ms. | |
#define | IntervalSHT 1000 |
SHT read interval ms. | |
#define | IntervalPWR 1000 |
Power state update interval ms. | |
#define | IntervalPOL IntervalMSG |
Time ms before BLE receive repeats. | |
#define | LoopPassiveMs 125 |
Loop interval ms when disabled. | |
#define | LoopIdleMs 125 |
Loop interval when not connected. | |
#define | NopDelayMs 10 |
Delay ms when no message needs to be sent. | |
#define | IdleIntervalLED 1250 |
LED flashing interval when BLE is active but disconnected. | |
#define | IdleLightLED 625 |
Time LED is on. | |
#define | IntervalLED 2500 |
LED flashing interval when BLE is active and connected. | |
#define | LightLED 125 |
Time LED is on. | |
Functions | |
static void | resetStatus (void) |
static void | resetTimers (void) |
static void | clearLEDs (void) |
static void | readSDP (void) |
static void | readDPS (void) |
static void | readSHT (void) |
static void | flashBlueLED (int active, unsigned int intervalMs, unsigned int lightMs) |
static void | managePower () |
static void | processCmd (const String &cmd) |
static void | enable (void) |
static void | disable (void) |
static void | suspend (void) |
static void | loopIdle (void) |
static void | loopConnected (void) |
static void | loopPassive (void) |
void | appLoop (void) |
static void | configure (void) |
void | appSetup (void) |
Variables | |
static const int | Melody [] |
Startup melody. | |
static PtvBleInterface | Remote |
Singleton connection to be used (all BLE stuff is singleton) | |
static SDP3XSensor | sdp |
Sensirion SDP31 for Pitot. | |
static SensirionI2CSht4x | sht |
Sensirion SHT for temperature / humidity. | |
static Adafruit_DPS310 | dps |
Infineon DPS310 for barometric pressure. | |
static PtvBleInterface::SensorData | sensorData |
Sensor data to work with. | |
static int | isBlueLedOn = 0 |
LED blinking state 0/1. | |
static int | isEnabled = 0 |
Operating mode 0/1. | |
static int | isConnected = 0 |
Connection state 0/1. | |
static unsigned int | sentMeta = 0 |
Meta data repetition counter. | |
static unsigned long | timeMs = 0 |
Current loop time ms. | |
static unsigned long | lastActiveMs |
static unsigned long | lastSHTMs |
Last read SHT ambient temperature/humidity. | |
static unsigned long | lastSDPMs |
Last read SDP differential pressure. | |
static unsigned long | lastDPSMs |
Last read DPS atmospheric pressure. | |
static unsigned long | lastMSGMs |
Last time message sent. | |
static unsigned long | lastPOLMs |
Last BLE receive poll. | |
static unsigned long | lastLEDMs |
Last LED state change. | |
static unsigned long | lastPWRMs |
Last read of battery/voltage status. | |
Sketch main module.
Arduino code for Flying Silicon Airspeed/Vario Probe and TotalVario Android app.
For more information refer to: https://flyingsilicon.blogspot.com/
https://totalvario.blogspot.com/
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License http://www.gnu.org/licenses/ for more details.
Definition in file fsSensor.cpp.
#define ACTIVE_WITH_USB 0 |
Run or stay passive (and charge) when USB is connected.
Definition at line 55 of file fsSensor.cpp.
#define AUTO_OFF_MS 3600000 |
Delay before auto power off (without BLE connection)
Definition at line 70 of file fsSensor.cpp.
#define DEEP_SLEEP 1 |
Enter deep sleep when battery drained (else suspend loop)
Definition at line 64 of file fsSensor.cpp.
#define DEVICE_MANUFACTURER "Flying Silicon" |
Manufacturer meta data.
Definition at line 48 of file fsSensor.cpp.
#define DEVICE_NAME "FS-SP4" |
Device name meta data (also sent in BLE advertising, truncated to 31)
Definition at line 50 of file fsSensor.cpp.
#define DEVICE_SERIAL "23-001" |
Serial number meta data.
Definition at line 52 of file fsSensor.cpp.
#define FLASH_ALWAYS 1 |
Flash blue LED (when BLE connected) also when running on battery.
Definition at line 58 of file fsSensor.cpp.
#define IdleIntervalLED 1250 |
LED flashing interval when BLE is active but disconnected.
Definition at line 103 of file fsSensor.cpp.
#define IdleLightLED 625 |
Time LED is on.
Definition at line 105 of file fsSensor.cpp.
#define IntervalDPS IntervalMSG |
DPS read interval ms.
Definition at line 87 of file fsSensor.cpp.
#define IntervalLED 2500 |
LED flashing interval when BLE is active and connected.
Definition at line 108 of file fsSensor.cpp.
#define IntervalMSG 125 |
Message send interval ms (critical)
Definition at line 83 of file fsSensor.cpp.
#define IntervalPOL IntervalMSG |
Time ms before BLE receive repeats.
Definition at line 93 of file fsSensor.cpp.
#define IntervalPWR 1000 |
Power state update interval ms.
Definition at line 91 of file fsSensor.cpp.
#define IntervalSDP IntervalMSG |
SDP read interval ms.
Definition at line 85 of file fsSensor.cpp.
#define IntervalSHT 1000 |
SHT read interval ms.
Definition at line 89 of file fsSensor.cpp.
#define LightLED 125 |
Time LED is on.
Definition at line 110 of file fsSensor.cpp.
#define LoopIdleMs 125 |
Loop interval when not connected.
Definition at line 98 of file fsSensor.cpp.
#define LoopPassiveMs 125 |
Loop interval ms when disabled.
Definition at line 96 of file fsSensor.cpp.
#define META_REPEAT 16 |
Number of meta headers to send on (re)connect.
Definition at line 73 of file fsSensor.cpp.
#define NopDelayMs 10 |
Delay ms when no message needs to be sent.
Definition at line 100 of file fsSensor.cpp.
#define PATCH_LEDR digitalWrite(LEDR, HIGH) |
Patch the red LED which is going on when BLE device is bonded.
Definition at line 76 of file fsSensor.cpp.
#define SEND_LONG 0 |
Use the long PTVSOAR message format also for data.
Definition at line 61 of file fsSensor.cpp.
void appLoop | ( | void | ) |
Application loop
Definition at line 501 of file fsSensor.cpp.
References ACTIVE_WITH_USB, AUTO_OFF_MS, DEBUG, disable(), enable(), IntervalPWR, PwrSupply::isBatDrained(), PwrSupply::isBatPowered(), BleInterface::isConnected(), isConnected, isEnabled, lastActiveMs, lastPWRMs, LOGL, loopConnected(), loopIdle(), loopPassive(), managePower(), Sounds::playConnect(), Sounds::playDisconnect(), Sounds::playSwitchOff(), Remote, sentMeta, suspend(), and timeMs.
Referenced by loop().
void appSetup | ( | void | ) |
Initial application setup
Definition at line 610 of file fsSensor.cpp.
References ACTIVE_WITH_USB, configure(), DEBUG, DEVICE_NAME, disable(), dps, enable(), BleInterface::init(), PwrSupply::isBatDrained(), PwrSupply::isBatPowered(), LOGL, managePower(), Remote, resetStatus(), resetTimers(), sdp, sht, and suspend().
Referenced by setup().
|
static |
Switch RGB LEDs off
Definition at line 221 of file fsSensor.cpp.
References LEDB, LEDG, and LEDR.
Referenced by configure(), and suspend().
|
static |
Configure pins etc
Definition at line 577 of file fsSensor.cpp.
References ANALOG_REFV, clearLEDs(), PIN_BATTV, PIN_BATTV_ENABLE, PIN_BUZZER, PIN_CHG, PIN_HICHG, and PIN_USB.
Referenced by appSetup().
|
static |
Called when device becomes deactivated
Definition at line 382 of file fsSensor.cpp.
References isEnabled, LOGL, Sounds::playSwitchOff(), Remote, and BleInterface::shutdown().
Referenced by appLoop(), and appSetup().
|
static |
Called when device becomes activated
Definition at line 355 of file fsSensor.cpp.
References PtvBleInterface::SensorData::batPct, PtvBleInterface::clrReceived(), isEnabled, PwrSupply::isUsbConnected(), LOGL, Melody, Sounds::playBattery(), Sounds::playCharging(), Sounds::playMelody(), Remote, resetTimers(), sensorData, and BleInterface::startAdv().
Referenced by appLoop(), and appSetup().
|
static |
Flash the blue LED with the specified timing
active | enable (1) or disable (0) blinking |
intervalMs | duration of a blink period in ms |
lightMs | time in ms that the LED is on |
Definition at line 300 of file fsSensor.cpp.
References isBlueLedOn, lastLEDMs, LEDB, and timeMs.
Referenced by loopConnected(), and loopIdle().
|
static |
Periodically called when device is active and a BLE central is connected
Definition at line 435 of file fsSensor.cpp.
References DEVICE_MANUFACTURER, DEVICE_NAME, DEVICE_SERIAL, FLASH_ALWAYS, flashBlueLED(), PtvBleInterface::getReceived(), IntervalDPS, IntervalLED, IntervalMSG, IntervalPOL, IntervalSDP, IntervalSHT, PwrSupply::isUsbConnected(), lastDPSMs, lastMSGMs, lastPOLMs, lastSDPMs, lastSHTMs, LightLED, META_REPEAT, NopDelayMs, PATCH_LEDR, processCmd(), readDPS(), readSDP(), readSHT(), Remote, SEND_LONG, PtvBleInterface::sendLongMsg(), PtvBleInterface::sendMetaMsg(), PtvBleInterface::sendShortMsg(), sensorData, sentMeta, and timeMs.
Referenced by appLoop().
|
static |
Periodically called when device is active and no BLE central is connected
Definition at line 423 of file fsSensor.cpp.
References flashBlueLED(), IdleIntervalLED, IdleLightLED, LoopIdleMs, and PATCH_LEDR.
Referenced by appLoop().
|
static |
Periodically called when device is inactive
Definition at line 488 of file fsSensor.cpp.
References PtvBleInterface::SensorData::isCharging, LEDB, LoopPassiveMs, PATCH_LEDR, and sensorData.
Referenced by appLoop().
|
static |
Manage power supply status and related stuff
Definition at line 327 of file fsSensor.cpp.
References PtvBleInterface::SensorData::batPct, PtvBleInterface::SensorData::batVolt, PwrSupply::getBatPct(), PwrSupply::getBatVolt(), PwrSupply::isBatPowered(), PtvBleInterface::SensorData::isCharging, PwrSupply::isCharging(), PwrSupply::isUsbConnected(), PIN_BUZZER, sensorData, Sounds::setBuzzer(), and PwrSupply::updateState().
Referenced by appLoop(), and appSetup().
|
static |
Process a control command received from remote
cmd | String holding the command |
Definition at line 347 of file fsSensor.cpp.
References LOGL.
Referenced by loopConnected().
|
static |
Periodically read atmospheric pressure from DPS sensor
Definition at line 257 of file fsSensor.cpp.
References PtvBleInterface::SensorData::absHpa, dps, LOG, LOGL, and sensorData.
Referenced by loopConnected().
|
static |
Periodically read differential pressure from SDP31 sensor
Definition at line 236 of file fsSensor.cpp.
References PtvBleInterface::SensorData::absHpa, PtvBleInterface::SensorData::diffPa, LOG, LOGL, sdp, and sensorData.
Referenced by loopConnected().
|
static |
Periodically read temperature and humidity from SHT sensor
Definition at line 279 of file fsSensor.cpp.
References PtvBleInterface::SensorData::humPct, LOG, LOGL, sensorData, sht, and PtvBleInterface::SensorData::tempC.
Referenced by loopConnected().
|
static |
Initialise all global status variables
Definition at line 177 of file fsSensor.cpp.
References PtvBleInterface::SensorData::absHpa, PtvBleInterface::SensorData::batPct, PtvBleInterface::SensorData::batVolt, PtvBleInterface::SensorData::diffPa, PtvBleInterface::SensorData::humPct, isBlueLedOn, isConnected, isEnabled, PwrSupply::reset(), sensorData, sentMeta, and PtvBleInterface::SensorData::tempC.
Referenced by appSetup().
|
static |
Initialise the function timers
Definition at line 200 of file fsSensor.cpp.
References IntervalDPS, IntervalMSG, IntervalPOL, IntervalPWR, IntervalSDP, IntervalSHT, lastActiveMs, lastDPSMs, lastLEDMs, lastMSGMs, lastPOLMs, lastPWRMs, lastSDPMs, lastSHTMs, and timeMs.
Referenced by appSetup(), and enable().
|
static |
Shut down BLE and suspend loop until next restart
Definition at line 395 of file fsSensor.cpp.
References clearLEDs(), enterDeepSleep(), LOGL, Sounds::playSwitchOff(), Remote, setLowPowerMode(), and BleInterface::shutdown().
Referenced by appLoop(), and appSetup().
|
static |
Infineon DPS310 for barometric pressure.
Definition at line 139 of file fsSensor.cpp.
Referenced by appSetup(), and readDPS().
|
static |
LED blinking state 0/1.
Definition at line 150 of file fsSensor.cpp.
Referenced by flashBlueLED(), and resetStatus().
|
static |
Connection state 0/1.
Definition at line 154 of file fsSensor.cpp.
Referenced by appLoop(), and resetStatus().
|
static |
Operating mode 0/1.
Definition at line 152 of file fsSensor.cpp.
Referenced by appLoop(), disable(), enable(), and resetStatus().
|
static |
Definition at line 163 of file fsSensor.cpp.
Referenced by appLoop(), and resetTimers().
|
static |
Last read DPS atmospheric pressure.
Definition at line 167 of file fsSensor.cpp.
Referenced by loopConnected(), and resetTimers().
|
static |
Last LED state change.
Definition at line 170 of file fsSensor.cpp.
Referenced by flashBlueLED(), and resetTimers().
|
static |
Last time message sent.
Definition at line 168 of file fsSensor.cpp.
Referenced by loopConnected(), and resetTimers().
|
static |
Last BLE receive poll.
Definition at line 169 of file fsSensor.cpp.
Referenced by loopConnected(), and resetTimers().
|
static |
Last read of battery/voltage status.
Definition at line 171 of file fsSensor.cpp.
Referenced by appLoop(), and resetTimers().
|
static |
Last read SDP differential pressure.
Definition at line 166 of file fsSensor.cpp.
Referenced by loopConnected(), and resetTimers().
|
static |
Last read SHT ambient temperature/humidity.
Definition at line 165 of file fsSensor.cpp.
Referenced by loopConnected(), and resetTimers().
|
static |
|
static |
Singleton connection to be used (all BLE stuff is singleton)
Definition at line 130 of file fsSensor.cpp.
Referenced by appLoop(), appSetup(), disable(), enable(), loopConnected(), and suspend().
|
static |
Sensirion SDP31 for Pitot.
Definition at line 133 of file fsSensor.cpp.
Referenced by appSetup(), and readSDP().
|
static |
Sensor data to work with.
Definition at line 142 of file fsSensor.cpp.
Referenced by enable(), loopConnected(), loopPassive(), managePower(), readDPS(), readSDP(), readSHT(), and resetStatus().
|
static |
Meta data repetition counter.
Definition at line 157 of file fsSensor.cpp.
Referenced by appLoop(), loopConnected(), and resetStatus().
|
static |
Sensirion SHT for temperature / humidity.
Definition at line 136 of file fsSensor.cpp.
Referenced by appSetup(), and readSHT().
|
static |
Current loop time ms.
Last time when connected via BLE
Definition at line 160 of file fsSensor.cpp.
Referenced by appLoop(), flashBlueLED(), loopConnected(), and resetTimers().