diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index 6fbb0f7428..6adf090201 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -519,6 +519,10 @@ void MyMesh::sendFloodScoped(const mesh::GroupChannel& channel, mesh::Packet* pk } } +void MyMesh::onTextMessageNotification() { + board.onMessageNotify(); +} + void MyMesh::onMessageRecv(const ContactInfo &from, mesh::Packet *pkt, uint32_t sender_timestamp, const char *text) { markConnectionActive(from); // in case this is from a server, and we have a connection diff --git a/examples/companion_radio/MyMesh.h b/examples/companion_radio/MyMesh.h index 43d3950beb..5352a3522b 100644 --- a/examples/companion_radio/MyMesh.h +++ b/examples/companion_radio/MyMesh.h @@ -130,6 +130,7 @@ class MyMesh : public BaseChatMesh, public DataStoreHost { void queueMessage(const ContactInfo &from, uint8_t txt_type, mesh::Packet *pkt, uint32_t sender_timestamp, const uint8_t *extra, int extra_len, const char *text); + void onTextMessageNotification() override; void onMessageRecv(const ContactInfo &from, mesh::Packet *pkt, uint32_t sender_timestamp, const char *text) override; void onCommandDataRecv(const ContactInfo &from, mesh::Packet *pkt, uint32_t sender_timestamp, diff --git a/src/MeshCore.h b/src/MeshCore.h index cfa33cf90b..eacfbe904d 100644 --- a/src/MeshCore.h +++ b/src/MeshCore.h @@ -51,6 +51,9 @@ class MainBoard { virtual const char* getManufacturerName() const = 0; virtual void onBeforeTransmit() { } virtual void onAfterTransmit() { } + virtual void onBeforeReceive() { } + virtual void onAfterReceive() { } + virtual void onMessageNotify() { } virtual void reboot() = 0; virtual void powerOff() { /* no op */ } // Called by example setup() functions to signal that boot is complete. diff --git a/src/helpers/BaseChatMesh.cpp b/src/helpers/BaseChatMesh.cpp index d3ef034e67..47387eb496 100644 --- a/src/helpers/BaseChatMesh.cpp +++ b/src/helpers/BaseChatMesh.cpp @@ -224,6 +224,7 @@ void BaseChatMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender if (flags == TXT_TYPE_PLAIN) { from.lastmod = getRTCClock()->getCurrentTime(); // update last heard time + onTextMessageNotification(); onMessageRecv(from, packet, timestamp, (const char *) &data[5]); // let UI know int text_len = strlen((char *)&data[5]); @@ -255,6 +256,7 @@ void BaseChatMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender from.sync_since = timestamp; } from.lastmod = getRTCClock()->getCurrentTime(); // update last heard time + onTextMessageNotification(); onSignedMessageRecv(from, packet, timestamp, &data[5], (const char *) &data[9]); // let UI know uint32_t ack_hash; // calc truncated hash of the message timestamp + text + OUR pub_key, to prove to sender that we got it @@ -384,6 +386,7 @@ void BaseChatMesh::onGroupDataRecv(mesh::Packet* packet, uint8_t type, const mes data[len] = 0; // need to make a C string again, with null terminator // notify UI of this new message + onTextMessageNotification(); onChannelMessageRecv(channel, packet, timestamp, (const char *) &data[5]); // let UI know } else if (type == PAYLOAD_TYPE_GRP_DATA) { if (len < 3) { diff --git a/src/helpers/BaseChatMesh.h b/src/helpers/BaseChatMesh.h index c04bfda38c..2306525600 100644 --- a/src/helpers/BaseChatMesh.h +++ b/src/helpers/BaseChatMesh.h @@ -113,6 +113,7 @@ class BaseChatMesh : public mesh::Mesh { virtual uint32_t calcDirectTimeoutMillisFor(uint32_t pkt_airtime_millis, uint8_t path_len) const = 0; virtual void onSendTimeout() = 0; virtual void onChannelMessageRecv(const mesh::GroupChannel& channel, mesh::Packet* pkt, uint32_t timestamp, const char *text) = 0; + virtual void onTextMessageNotification() { } virtual void onChannelDataRecv(const mesh::GroupChannel& channel, mesh::Packet* pkt, uint16_t data_type, const uint8_t* data, size_t data_len) {} virtual uint8_t onContactRequest(const ContactInfo& contact, uint32_t sender_timestamp, const uint8_t* data, uint8_t len, uint8_t* reply) = 0; diff --git a/src/helpers/radiolib/RadioLibWrappers.cpp b/src/helpers/radiolib/RadioLibWrappers.cpp index b6519aefa7..a6e9c4665d 100644 --- a/src/helpers/radiolib/RadioLibWrappers.cpp +++ b/src/helpers/radiolib/RadioLibWrappers.cpp @@ -122,6 +122,7 @@ int RadioLibWrapper::recvRaw(uint8_t* bytes, int sz) { len = _radio->getPacketLength(); if (len > 0) { if (len > sz) { len = sz; } + _board->onBeforeReceive(); int err = _radio->readData(bytes, len); if (err != RADIOLIB_ERR_NONE) { MESH_DEBUG_PRINTLN("RadioLibWrapper: error: readData(%d)", err); @@ -131,6 +132,7 @@ int RadioLibWrapper::recvRaw(uint8_t* bytes, int sz) { // Serial.print(" readData() -> "); Serial.println(len); n_recv++; } + _board->onAfterReceive(); } state = STATE_IDLE; // need another startReceive() } diff --git a/variants/heltec_t114/T114Board.cpp b/variants/heltec_t114/T114Board.cpp index c03d39afb6..96a351a607 100644 --- a/variants/heltec_t114/T114Board.cpp +++ b/variants/heltec_t114/T114Board.cpp @@ -48,6 +48,11 @@ void T114Board::begin() { digitalWrite(P_LORA_TX_LED, HIGH); #endif +#ifdef P_VIBRO_MOTOR + pinMode(P_VIBRO_MOTOR, OUTPUT); + digitalWrite(P_VIBRO_MOTOR, LOW); +#endif + pinMode(SX126X_POWER_EN, OUTPUT); #ifdef NRF52_POWER_MANAGEMENT // Boot voltage protection check (may not return if voltage too low) diff --git a/variants/heltec_t114/T114Board.h b/variants/heltec_t114/T114Board.h index f27dc291d0..afdec5a99f 100644 --- a/variants/heltec_t114/T114Board.h +++ b/variants/heltec_t114/T114Board.h @@ -28,6 +28,14 @@ class T114Board : public NRF52BoardDCDC { } #endif +#if defined(P_VIBRO_MOTOR) + void onMessageNotify() override { + digitalWrite(P_VIBRO_MOTOR, HIGH); + delay(300); + digitalWrite(P_VIBRO_MOTOR, LOW); + } +#endif + uint16_t getBattMilliVolts() override { int adcvalue = 0; analogReadResolution(12); diff --git a/variants/heltec_t114/platformio.ini b/variants/heltec_t114/platformio.ini index 135babb1a2..2d81e0b1ef 100644 --- a/variants/heltec_t114/platformio.ini +++ b/variants/heltec_t114/platformio.ini @@ -21,6 +21,7 @@ build_flags = ${nrf52_base.build_flags} -D P_LORA_MISO=23 -D P_LORA_MOSI=22 -D P_LORA_TX_LED=35 + -D P_VIBRO_MOTOR=33 -D RADIO_CLASS=CustomSX1262 -D WRAPPER_CLASS=CustomSX1262Wrapper -D LORA_TX_POWER=22