Intoducing distance target mode

Signed-off-by: Tomasz Miklas <230130+tmiklas@users.noreply.github.com>
pull/1/head
Tomasz Miklas 2021-11-18 20:06:12 +00:00
rodzic 90d65e419d
commit ff421944c9
5 zmienionych plików z 84 dodań i 15 usunięć

Wyświetl plik

@ -24,8 +24,30 @@ Same as Fizzy I have not done any of the coding. My only idea with this fork is
Further modifications added by [tmiklas](https://github.com/tmiklas/tbeam-helium-mapper):
**2021-11-18** - Introducing **distance target** mode (a.k.a. TX window scaling)
Verison: `1.1-tm`
Most mappers usually operate in **time target** mode, where they send data to network every set interval (i.e. `SEND_INTERVAL`). There is however a different use case for fast moving mappers - like in a car at motorway speeds...
This feature allows you to switch mapping mode from time target to distace target and back. You can configure your desierd distance target in `configuration.h` and turn ON/OFF by pressing the `USR` button for over 1sec:
```
#define DISTANCE_TARGET 200.0 // MUST be decimal number; distance target in meters
```
![T-Beam buttons](img/t-beam-buttons.jpeg)
Once moving, you will be able to see it operating properly and reporting TX window:
![TX Window Scaling](img/TX-window-scaling.jpeg)
In simple terms, with distance target set to 200m (as default in this code), window scaling starts working once you travel at speed over 10m/s (36k/h or 22.3mph). There's also a lower limit - do not transmit more often than every 2sec... so with 200m target you are good up to 100m/s (360k/h or 223mph) - good luck :-P
**2021-11-14** - Added some new features
Verison: `1.0-tm`
> Send Now - transmit on deman by short-pressing 2nd button
Reacts to short-press of the central button and overrides any travel distance requirement (see 2 below).
@ -41,11 +63,13 @@ This is controlled by 2 variables in `configuration.h` file, `MIN_DIST` and `STA
Example:
```
#define SEND_INTERVAL (20 * 1000) // Sleep for these many millis
// -----------------------------------------------------------------------------
// LoRa send criteria
// -----------------------------------------------------------------------------
#define MIN_DIST 50.0 // MUST be decimal number; minimum distance in meters from the last sent location before we can send again. A hex is about 340m, divide by this value to get the pings per hex.
#define STATIONARY_TX_INTERVAL 60 // If stationary the LoRa frame will be sent once every N cycles... with 30sec cycle, interval of 60 means to transmit once every 30min
#define STATIONARY_TX_INTERVAL 60 // If stationary the LoRa frame will be sent once every N cycles... with 20sec cycle, interval of 60 means to transmit once every 20min
```

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 59 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 133 KiB

Wyświetl plik

@ -33,7 +33,7 @@ void ttn_register(void (*callback)(uint8_t message));
// -----------------------------------------------------------------------------
#define APP_NAME "Helium TTGO"
#define APP_VERSION "1.0-tm"
#define APP_VERSION "1.1-tm"
// -----------------------------------------------------------------------------
// Configuration
@ -80,6 +80,7 @@ void ttn_register(void (*callback)(uint8_t message));
// -----------------------------------------------------------------------------
#define MIN_DIST 50.0 // MUST be decimal number; minimum distance in meters from the last sent location before we can send again. A hex is about 340m, divide by this value to get the pings per hex.
#define STATIONARY_TX_INTERVAL 60 // If stationary the LoRa frame will be sent once every N cycles... with 30sec cycle, interval of 60 means to transmit once every 30min
#define DISTANCE_TARGET 200.0 // MUST be decimal number; distance target in meters
// -----------------------------------------------------------------------------

Wyświetl plik

@ -31,6 +31,7 @@
*/
#include <Arduino.h>
#include "configuration.h"
#include "rom/rtc.h"
#include <TinyGPS++.h>
@ -45,8 +46,12 @@ float last_send_lat = 0;
float last_send_lon = 0;
float min_dist_moved = MIN_DIST;
float dist_moved = UINT32_MAX;
unsigned int adjusted_SEND_INTERVAL = SEND_INTERVAL;
//
// do we want to auto-scale transmit window size?
bool autoScaleTX = false;
AXP20X_Class axp;
bool pmu_irq = false;
String baChStatus = "No charging";
@ -120,6 +125,22 @@ bool trySend() {
screen_print(buffer);
}
// TX window auto-scaling
// desired ping distance is 200m
if (autoScaleTX && !justSendNow) {
float newWindow = DISTANCE_TARGET / (dist_moved / adjusted_SEND_INTERVAL); // seconds
if (newWindow > SEND_INTERVAL) { // both are in millis!
// we're too slow... default back to old mode with ping every SEND_INTERVAL
newWindow = SEND_INTERVAL;
} else if (newWindow < 2000) {
// this is 100m/s movement or 360kph or 220mph :-o
newWindow = 2000;
}
snprintf(buffer, sizeof(buffer), "TX window: %4.1fsec\n", newWindow / 1000);
screen_print(buffer);
adjusted_SEND_INTERVAL = newWindow; // millis
}
// set back to normal mode
justSendNow = false;
@ -472,27 +493,50 @@ void loop() {
static bool wasPressed = false;
static uint32_t minPressMs; // what tick should we call this press long enough
if (!digitalRead(BUTTON_PIN)) {
if (!wasPressed) { // just started a new press
Serial.println("pressing");
// Serial.println("pressing");
wasPressed = true;
minPressMs = millis() + 3000;
minPressMs = millis();
}
} else if (wasPressed) {
// we just did a release
wasPressed = false;
if (millis() > minPressMs) {
if (millis() > minPressMs + 1000) {
// held long enough
#ifndef PREFS_DISCARD
screen_print("Discarding prefs disabled\n");
#endif
#ifdef PREFS_DISCARD
screen_print("Discarding prefs!\n");
ttn_erase_prefs();
delay(5000); // Give some time to read the screen
ESP.restart();
#endif
Serial.println("Long press!");
if (autoScaleTX) {
// turn off auto scaling to static trigger
autoScaleTX = false;
adjusted_SEND_INTERVAL = SEND_INTERVAL;
char buffer[40];
snprintf(buffer, sizeof(buffer), "TX scaling OFF\n");
screen_print(buffer);
// screen_print("TX Scaling OFF");
} else {
// enable auto-scaling
autoScaleTX = true;
char buffer[40];
snprintf(buffer, sizeof(buffer), "TX scaling ON\n");
screen_print(buffer);
// screen_print("TX Scaling ON");
}
// #ifndef PREFS_DISCARD
// screen_print("Discarding prefs disabled\n");
// #endif
// #ifdef PREFS_DISCARD
// screen_print("Discarding prefs!\n");
// ttn_erase_prefs();
// delay(5000); // Give some time to read the screen
// ESP.restart();
// #endif
} else {
// short press, send beacon
Serial.println("Short press :-P");
justSendNow = true;
trySend();
}
@ -501,7 +545,7 @@ void loop() {
// Send every SEND_INTERVAL millis
static uint32_t last = 0;
static bool first = true;
if (0 == last || millis() - last > SEND_INTERVAL) {
if (0 == last || millis() - last > adjusted_SEND_INTERVAL) {
if (trySend()) {
last = millis();
first = false;