Add health telemetry module (#4927)

* Add stub health telemetry module

* Add detection for MAX30102 Health Sensor

It lives on I2C bus at 0x57, which conflicts with an existing
sensor. Add code to check the PARTID register for its response 0x15
per spec.

* Add detection for MLX90614

An IR Temperature sensor suitable for livestock monitoring.

* Add libraries for MLX90614 and MAX30102 sensors

* Fix Trunk

* Add support for MLX90614 IR Temperature Sensor

* Add support for MAX30102 (Temperature)

* Make it build - our first HealthTelemetry on the mesh.

If a MAX30102 is connected, its temperature will be sent to the
mesh as HealthTelemetry.

* Add spo2 and heart rate calculations to MAX30102

* Switch MLX90614 to Adafruit library

Sparkfun was having fun with SDA/SCL variables which we can avoid
by switching to this highly similar library.

* Enable HealthTelemetry if MLX90614 detected

* Change MLX90614 emissivity for human skin.

* Add health screen!

* Remove autogenerated file from branch

* Preparing for review

* Fix MeshService master sync from before.

* Prepare for review

* For the americans

* Fix native build

* Fix for devices with no screen

* Remove extra log causing issues

---------

Co-authored-by: Tom Fifield <tom@tomfifield.net>
This commit is contained in:
Ben Meadors
2024-10-07 19:50:44 -05:00
committed by GitHub
parent 1c54388bb8
commit 411aedaf5d
13 changed files with 515 additions and 2 deletions

View File

@@ -0,0 +1,60 @@
#include "configuration.h"
#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && !defined(ARCH_PORTDUINO)
#pragma once
#include "../mesh/generated/meshtastic/telemetry.pb.h"
#include "NodeDB.h"
#include "ProtobufModule.h"
#include <OLEDDisplay.h>
#include <OLEDDisplayUi.h>
class HealthTelemetryModule : private concurrency::OSThread, public ProtobufModule<meshtastic_Telemetry>
{
CallbackObserver<HealthTelemetryModule, const meshtastic::Status *> nodeStatusObserver =
CallbackObserver<HealthTelemetryModule, const meshtastic::Status *>(this, &HealthTelemetryModule::handleStatusUpdate);
public:
HealthTelemetryModule()
: concurrency::OSThread("HealthTelemetryModule"),
ProtobufModule("HealthTelemetry", meshtastic_PortNum_TELEMETRY_APP, &meshtastic_Telemetry_msg)
{
lastMeasurementPacket = nullptr;
nodeStatusObserver.observe(&nodeStatus->onNewStatus);
setIntervalFromNow(10 * 1000);
}
#if !HAS_SCREEN
void drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
#else
virtual void drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) override;
#endif
virtual bool wantUIFrame() override;
protected:
/** Called to handle a particular incoming message
@return true if you've guaranteed you've handled this message and no other handlers should be considered for it
*/
virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *p) override;
virtual int32_t runOnce() override;
/** Called to get current Health telemetry data
@return true if it contains valid data
*/
bool getHealthTelemetry(meshtastic_Telemetry *m);
virtual meshtastic_MeshPacket *allocReply() override;
/**
* Send our Telemetry into the mesh
*/
bool sendTelemetry(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false);
private:
bool firstTime = 1;
meshtastic_MeshPacket *lastMeasurementPacket;
uint32_t sendToPhoneIntervalMs = SECONDS_IN_MINUTE * 1000; // Send to phone every minute
uint32_t lastSentToMesh = 0;
uint32_t lastSentToPhone = 0;
uint32_t sensor_read_error_count = 0;
};
#endif