mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-25 01:42:15 +00:00
add some documentation, cleanup
This commit is contained in:
parent
73c77b663c
commit
09e08e0091
@ -7,7 +7,18 @@
|
|||||||
|
|
||||||
PaxcounterModule *paxcounterModule;
|
PaxcounterModule *paxcounterModule;
|
||||||
|
|
||||||
// paxcounterModule->sendInfo(NODENUM_BROADCAST);
|
/**
|
||||||
|
* Callback function for libpax.
|
||||||
|
* We only clear our sent flag here, since this function is called from another thread, so we
|
||||||
|
* cannot send to the mesh directly.
|
||||||
|
*/
|
||||||
|
void PaxcounterModule::handlePaxCounterReportRequest()
|
||||||
|
{
|
||||||
|
// The libpax library already updated our data structure, just before invoking this callback.
|
||||||
|
LOG_INFO("PaxcounterModule: libpax reported new data: wifi=%d; ble=%d; uptime=%lu\n",
|
||||||
|
paxcounterModule->count_from_libpax.wifi_count, paxcounterModule->count_from_libpax.ble_count, millis() / 1000);
|
||||||
|
paxcounterModule->reportedDataSent = false;
|
||||||
|
}
|
||||||
|
|
||||||
PaxcounterModule::PaxcounterModule()
|
PaxcounterModule::PaxcounterModule()
|
||||||
: concurrency::OSThread("PaxcounterModule"),
|
: concurrency::OSThread("PaxcounterModule"),
|
||||||
@ -15,15 +26,20 @@ PaxcounterModule::PaxcounterModule()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the Pax information to the mesh if we got new data from libpax.
|
||||||
|
* This is called periodically from our runOnce() method and will actually send the data to the mesh
|
||||||
|
* if libpax updated it since the last transmission through the callback.
|
||||||
|
* @param dest - destination node (usually NODENUM_BROADCAST)
|
||||||
|
* @return false if sending is unnecessary, true if information was sent
|
||||||
|
*/
|
||||||
bool PaxcounterModule::sendInfo(NodeNum dest)
|
bool PaxcounterModule::sendInfo(NodeNum dest)
|
||||||
{
|
{
|
||||||
if (paxcounterModule->reportedDataSent)
|
if (paxcounterModule->reportedDataSent)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
LOG_INFO("(Sending): pax: wifi=%d; ble=%d; uptime=%lu\n", count_from_libpax.wifi_count, count_from_libpax.ble_count,
|
LOG_INFO("PaxcounterModule: sending pax info wifi=%d; ble=%d; uptime=%lu\n", count_from_libpax.wifi_count,
|
||||||
millis() / 1000);
|
count_from_libpax.ble_count, millis() / 1000);
|
||||||
|
|
||||||
paxcounterModule->reportedDataSent = true;
|
|
||||||
|
|
||||||
meshtastic_Paxcount pl = meshtastic_Paxcount_init_default;
|
meshtastic_Paxcount pl = meshtastic_Paxcount_init_default;
|
||||||
pl.wifi = count_from_libpax.wifi_count;
|
pl.wifi = count_from_libpax.wifi_count;
|
||||||
@ -33,9 +49,12 @@ bool PaxcounterModule::sendInfo(NodeNum dest)
|
|||||||
meshtastic_MeshPacket *p = allocDataProtobuf(pl);
|
meshtastic_MeshPacket *p = allocDataProtobuf(pl);
|
||||||
p->to = dest;
|
p->to = dest;
|
||||||
p->decoded.want_response = false;
|
p->decoded.want_response = false;
|
||||||
p->priority = meshtastic_MeshPacket_Priority_MIN;
|
p->priority = meshtastic_MeshPacket_Priority_DEFAULT;
|
||||||
|
|
||||||
service.sendToMesh(p, RX_SRC_LOCAL, true);
|
service.sendToMesh(p, RX_SRC_LOCAL, true);
|
||||||
|
|
||||||
|
paxcounterModule->reportedDataSent = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,14 +76,6 @@ meshtastic_MeshPacket *PaxcounterModule::allocReply()
|
|||||||
return allocDataProtobuf(pl);
|
return allocDataProtobuf(pl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaxcounterModule::handlePaxCounterReportRequest()
|
|
||||||
{
|
|
||||||
// libpax_counter_count(&paxcounterModule->count_from_libpax);
|
|
||||||
LOG_INFO("(Reading): libPax reported new data: wifi=%d; ble=%d; uptime=%lu\n", paxcounterModule->count_from_libpax.wifi_count,
|
|
||||||
paxcounterModule->count_from_libpax.ble_count, millis() / 1000);
|
|
||||||
paxcounterModule->reportedDataSent = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t PaxcounterModule::runOnce()
|
int32_t PaxcounterModule::runOnce()
|
||||||
{
|
{
|
||||||
if (isActive()) {
|
if (isActive()) {
|
||||||
|
@ -8,18 +8,19 @@
|
|||||||
#include <libpax_api.h>
|
#include <libpax_api.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple example module that just replies with "Message received" to any message it receives.
|
* Wrapper module for the estimate passenger (PAX) count library (https://github.com/dbinfrago/libpax) which
|
||||||
|
* implements the core functionality of the ESP32 Paxcounter project (https://github.com/cyberman54/ESP32-Paxcounter)
|
||||||
*/
|
*/
|
||||||
class PaxcounterModule : private concurrency::OSThread, public ProtobufModule<meshtastic_Paxcount>
|
class PaxcounterModule : private concurrency::OSThread, public ProtobufModule<meshtastic_Paxcount>
|
||||||
{
|
{
|
||||||
bool firstTime = true;
|
bool firstTime = true;
|
||||||
bool reportedDataSent = true;
|
bool reportedDataSent = true;
|
||||||
|
|
||||||
|
static void handlePaxCounterReportRequest();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PaxcounterModule();
|
PaxcounterModule();
|
||||||
|
|
||||||
static void handlePaxCounterReportRequest();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
struct count_payload_t count_from_libpax = {0, 0, 0};
|
struct count_payload_t count_from_libpax = {0, 0, 0};
|
||||||
virtual int32_t runOnce() override;
|
virtual int32_t runOnce() override;
|
||||||
|
Loading…
Reference in New Issue
Block a user