Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/companion_radio/MyMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/companion_radio/MyMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/MeshCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions src/helpers/BaseChatMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/helpers/BaseChatMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/radiolib/RadioLibWrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()
}
Expand Down
5 changes: 5 additions & 0 deletions variants/heltec_t114/T114Board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions variants/heltec_t114/T114Board.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions variants/heltec_t114/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down