Skip to content

Commit c50b042

Browse files
committed
Added static VL53L0XSensor::getInstance() and setMode() to change Sensor mode using menu.
1 parent 5821ec4 commit c50b042

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

src/graphics/draw/MenuHandler.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <cmath>
3030
#include <functional>
3131
#include <utility>
32+
#include "modules/Telemetry/Sensor/VL53L0XSensor.h"
3233

3334
extern uint16_t TFT_MESH;
3435

@@ -1014,8 +1015,10 @@ void menuHandler::sensorsMenu()
10141015
static int optionsEnumArray[2] = {Back, VL53L0X};
10151016
int options = 1;
10161017

1017-
optionsArray[options] = "VL53L0X";
1018-
optionsEnumArray[options++] = VL53L0X;
1018+
if(VL53L0XSensor::getInstance()) {
1019+
optionsArray[options] = "VL53L0X";
1020+
optionsEnumArray[options++] = VL53L0X;
1021+
}
10191022

10201023
BannerOverlayOptions bannerOptions;
10211024
bannerOptions.message = "Sensors";
@@ -1044,18 +1047,18 @@ void menuHandler::sensorsVL53L0XMenu()
10441047
bannerOptions.optionsArrayPtr = optionsArray;
10451048
bannerOptions.optionsCount = 5;
10461049
bannerOptions.bannerCallback = [](int selected) -> void {
1050+
VL53L0XSensor* vl = VL53L0XSensor::getInstance();
10471051
if (selected == Back) {
10481052
menuQueue = SensorsMenu;
10491053
} else if (selected == Default) {
1050-
// TODO: set Sensitivity
1054+
vl->setMode(Adafruit_VL53L0X::VL53L0X_SENSE_DEFAULT);
10511055
} else if (selected == LongRange) {
1052-
// TODO: set Sensitivity
1056+
vl->setMode(Adafruit_VL53L0X::VL53L0X_SENSE_LONG_RANGE);
10531057
} else if (selected == HighSpeed) {
1054-
// TODO: set Sensitivity
1058+
vl->setMode(Adafruit_VL53L0X::VL53L0X_SENSE_HIGH_SPEED);
10551059
} else if (selected == HighAccuracy) {
1056-
// TODO: set Sensitivity
1060+
vl->setMode(Adafruit_VL53L0X::VL53L0X_SENSE_HIGH_ACCURACY);
10571061
}
1058-
// TODO: call VL50L0x::saveState();
10591062
};
10601063
screen->showOverlayBanner(bannerOptions);
10611064
}

src/modules/Telemetry/Sensor/VL53L0XSensor.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@
1919
#include <pb_decode.h>
2020
#include <pb_encode.h>
2121

22+
static VL53L0XSensor* instance = 0;
23+
24+
VL53L0XSensor* VL53L0XSensor::getInstance()
25+
{
26+
return instance;
27+
}
28+
29+
void VL53L0XSensor::setMode(Adafruit_VL53L0X::VL53L0X_Sense_config_t mode)
30+
{
31+
if(this->mode != mode) {
32+
this->mode = mode;
33+
saveState();
34+
}
35+
36+
}
2237

2338
bool VL53L0XSensor::loadState()
2439
{
@@ -76,7 +91,7 @@ bool VL53L0XSensor::saveState()
7691
#endif
7792
}
7893

79-
VL53L0XSensor::VL53L0XSensor() : TelemetrySensor(meshtastic_TelemetrySensorType_VL53L0X, "VL53L0X") {}
94+
VL53L0XSensor::VL53L0XSensor() : TelemetrySensor(meshtastic_TelemetrySensorType_VL53L0X, "VL53L0X") {instance = this;}
8095

8196
bool VL53L0XSensor::initDevice(TwoWire *bus, ScanI2C::FoundDevice *dev)
8297
{

src/modules/Telemetry/Sensor/VL53L0XSensor.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ class VL53L0XSensor : public TelemetrySensor
1818

1919
Adafruit_VL53L0X::VL53L0X_Sense_config_t mode;
2020

21+
public:
22+
static VL53L0XSensor* getInstance();
23+
void setMode(Adafruit_VL53L0X::VL53L0X_Sense_config_t mode);
2124
bool loadState();
2225
bool saveState();
2326

24-
public:
2527
VL53L0XSensor();
2628
virtual bool getMetrics(meshtastic_Telemetry *measurement) override;
2729
virtual bool initDevice(TwoWire *bus, ScanI2C::FoundDevice *dev) override;

0 commit comments

Comments
 (0)