mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-08-08 06:32:35 -04:00
I2cDev_PPmod periodic sensor query (#2315)
* Add more data tx from esp * command enum rework. +1 for JT * filter 0 query interval * i2c timeouts and sanity check on ppmod
This commit is contained in:
parent
7a38b04192
commit
c90f0944b1
5 changed files with 181 additions and 10 deletions
|
@ -21,7 +21,6 @@
|
|||
|
||||
#include "i2cdev_ppmod.hpp"
|
||||
#include "portapack.hpp"
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace i2cdev {
|
||||
|
@ -30,11 +29,95 @@ bool I2cDev_PPmod::init(uint8_t addr_) {
|
|||
if (addr_ != I2CDEV_PPMOD_ADDR_1) return false;
|
||||
addr = addr_;
|
||||
model = I2CDECMDL_PPMOD;
|
||||
query_interval = 10;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void I2cDev_PPmod::update() {
|
||||
auto mask = get_features_mask();
|
||||
if (mask & (uint64_t)SupportedFeatures::FEAT_GPS) {
|
||||
auto data = get_gps_data();
|
||||
if (data.has_value()) {
|
||||
GPSPosDataMessage msg{data.value().latitude, data.value().longitude, (int32_t)data.value().altitude, (int32_t)data.value().speed, data.value().sats_in_use};
|
||||
EventDispatcher::send_message(msg);
|
||||
}
|
||||
}
|
||||
if (mask & (uint64_t)SupportedFeatures::FEAT_ORIENTATION) {
|
||||
auto data = get_orientation_data();
|
||||
if (data.has_value()) {
|
||||
OrientationDataMessage msg{(uint16_t)data.value().angle, (int16_t)data.value().tilt};
|
||||
EventDispatcher::send_message(msg);
|
||||
}
|
||||
}
|
||||
if (mask & (uint64_t)SupportedFeatures::FEAT_ENVIRONMENT) {
|
||||
auto data = get_environment_data();
|
||||
if (data.has_value()) {
|
||||
EnvironmentDataMessage msg{data.value().temperature, data.value().humidity, data.value().pressure};
|
||||
EventDispatcher::send_message(msg);
|
||||
}
|
||||
}
|
||||
if (mask & (uint64_t)SupportedFeatures::FEAT_LIGHT) {
|
||||
auto data = get_light_data();
|
||||
if (data.has_value()) {
|
||||
LightDataMessage msg{data.value()};
|
||||
EventDispatcher::send_message(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<orientation_t> I2cDev_PPmod::get_orientation_data() {
|
||||
Command cmd = Command::COMMAND_GETFEAT_DATA_ORIENTATION;
|
||||
orientation_t data;
|
||||
bool success = i2c_read((uint8_t*)&cmd, 2, (uint8_t*)&data, sizeof(orientation_t));
|
||||
if (success == false) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
std::optional<gpssmall_t> I2cDev_PPmod::get_gps_data() {
|
||||
Command cmd = Command::COMMAND_GETFEAT_DATA_GPS;
|
||||
gpssmall_t data;
|
||||
bool success = i2c_read((uint8_t*)&cmd, 2, (uint8_t*)&data, sizeof(gpssmall_t));
|
||||
if (success == false) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
std::optional<environment_t> I2cDev_PPmod::get_environment_data() {
|
||||
Command cmd = Command::COMMAND_GETFEAT_DATA_ENVIRONMENT;
|
||||
environment_t data;
|
||||
bool success = i2c_read((uint8_t*)&cmd, 2, (uint8_t*)&data, sizeof(environment_t));
|
||||
if (success == false) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
std::optional<uint16_t> I2cDev_PPmod::get_light_data() {
|
||||
Command cmd = Command::COMMAND_GETFEAT_DATA_LIGHT;
|
||||
uint16_t data;
|
||||
bool success = i2c_read((uint8_t*)&cmd, 2, (uint8_t*)&data, sizeof(uint16_t));
|
||||
if (success == false) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
uint64_t I2cDev_PPmod::get_features_mask() {
|
||||
uint64_t mask = 0;
|
||||
Command cmd = Command::COMMAND_GETFEATURE_MASK;
|
||||
bool success = i2c_read((uint8_t*)&cmd, 2, (uint8_t*)&mask, sizeof(mask));
|
||||
if (success == false) {
|
||||
return 0;
|
||||
}
|
||||
// sanity check
|
||||
if (mask == UINT64_MAX) {
|
||||
return 0;
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
|
||||
std::optional<I2cDev_PPmod::device_info> I2cDev_PPmod::readDeviceInfo() {
|
||||
|
@ -45,7 +128,10 @@ std::optional<I2cDev_PPmod::device_info> I2cDev_PPmod::readDeviceInfo() {
|
|||
if (success == false) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// sanity check
|
||||
if (info.application_count > 1000) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
|
@ -58,6 +144,10 @@ std::optional<I2cDev_PPmod::standalone_app_info> I2cDev_PPmod::getStandaloneAppI
|
|||
if (success == false) {
|
||||
return std::nullopt;
|
||||
}
|
||||
// sanity check
|
||||
if (info.binary_size == UINT32_MAX) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue