mirror of
https://github.com/esphome/esphome.git
synced 2024-11-24 16:08:10 +01:00
More stuff to try
This commit is contained in:
parent
2640bd873f
commit
6b224112d6
2 changed files with 10 additions and 15 deletions
|
@ -125,21 +125,16 @@ void Lora::dump_config() {
|
|||
LOG_PIN("M1 Pin:", this->pin_m1);
|
||||
};
|
||||
void Lora::digital_write(uint8_t pin, bool value) {
|
||||
ESP_LOGD(TAG, "Starting to write message");
|
||||
std::string message = str_snprintf("%02x%02x", 9, pin, value);
|
||||
this->sendMessage(message);
|
||||
ESP_LOGD(TAG, "Setting internal state");
|
||||
this->sendPinInfo(pin, value);
|
||||
}
|
||||
bool Lora::sendMessage(std::string message) {
|
||||
uint8_t size = message.length();
|
||||
char messageFixed[size];
|
||||
memcpy(messageFixed, message.c_str(), size);
|
||||
if (size > MAX_SIZE_TX_PACKET + 2) {
|
||||
ESP_LOGD(TAG, "Package to big");
|
||||
return false;
|
||||
}
|
||||
ESP_LOGD(TAG, "Sending: %s", message);
|
||||
this->write_array((uint8_t *) &messageFixed, size);
|
||||
// bool result = this->waitCompleteResponse(5000, 5000);
|
||||
bool Lora::sendPinInfo(uint8_t pin, bool value) {
|
||||
uint8_t request_message[3];
|
||||
request_message[1] = 0xA5; // just some bit to indicate, yo this is pin info
|
||||
request_message[1] = pin; // Pin to send
|
||||
request_message[2] = value; // high or low
|
||||
this->write_array(request_message, sizeof(request_message));
|
||||
this->flush();
|
||||
return true;
|
||||
}
|
||||
void Lora::loop() {
|
||||
|
|
|
@ -51,7 +51,7 @@ class Lora : public PollingComponent, public uart::UARTDevice {
|
|||
bool setMode(MODE_TYPE type);
|
||||
// checks the aux port to see if it is done setting
|
||||
bool waitCompleteResponse(unsigned long timeout = 1000, unsigned int waitNoAux = 100);
|
||||
bool sendMessage(std::string message);
|
||||
bool sendPinInfo(uint8_t pin, bool value);
|
||||
|
||||
protected:
|
||||
int rssi_ = 0;
|
||||
|
|
Loading…
Reference in a new issue