More stuff to try

This commit is contained in:
Daniël Koek 2024-03-24 16:59:10 +00:00
parent 2640bd873f
commit 6b224112d6
2 changed files with 10 additions and 15 deletions

View file

@ -125,21 +125,16 @@ void Lora::dump_config() {
LOG_PIN("M1 Pin:", this->pin_m1); LOG_PIN("M1 Pin:", this->pin_m1);
}; };
void Lora::digital_write(uint8_t pin, bool value) { void Lora::digital_write(uint8_t pin, bool value) {
ESP_LOGD(TAG, "Starting to write message"); ESP_LOGD(TAG, "Setting internal state");
std::string message = str_snprintf("%02x%02x", 9, pin, value); this->sendPinInfo(pin, value);
this->sendMessage(message);
} }
bool Lora::sendMessage(std::string message) { bool Lora::sendPinInfo(uint8_t pin, bool value) {
uint8_t size = message.length(); uint8_t request_message[3];
char messageFixed[size]; request_message[1] = 0xA5; // just some bit to indicate, yo this is pin info
memcpy(messageFixed, message.c_str(), size); request_message[1] = pin; // Pin to send
if (size > MAX_SIZE_TX_PACKET + 2) { request_message[2] = value; // high or low
ESP_LOGD(TAG, "Package to big"); this->write_array(request_message, sizeof(request_message));
return false; this->flush();
}
ESP_LOGD(TAG, "Sending: %s", message);
this->write_array((uint8_t *) &messageFixed, size);
// bool result = this->waitCompleteResponse(5000, 5000);
return true; return true;
} }
void Lora::loop() { void Lora::loop() {

View file

@ -51,7 +51,7 @@ class Lora : public PollingComponent, public uart::UARTDevice {
bool setMode(MODE_TYPE type); bool setMode(MODE_TYPE type);
// checks the aux port to see if it is done setting // checks the aux port to see if it is done setting
bool waitCompleteResponse(unsigned long timeout = 1000, unsigned int waitNoAux = 100); bool waitCompleteResponse(unsigned long timeout = 1000, unsigned int waitNoAux = 100);
bool sendMessage(std::string message); bool sendPinInfo(uint8_t pin, bool value);
protected: protected:
int rssi_ = 0; int rssi_ = 0;