ESP-NOW Transmitter

This commit is contained in:
2025-06-17 22:29:29 -04:00
parent 8bfa4477dc
commit 103fca3ac3
2 changed files with 10 additions and 1 deletions

View File

@@ -13,6 +13,14 @@ static sensors_data_t buffer;
static int x, y; // Joystick x and y positions
adc_oneshot_unit_handle_t adc_xy_handle;
// Function to delete peer (i.e. when communication error occurs)
void deleteDev (void) {
uint8_t delStatus = esp_now_del_peer(receiver_mac);
if (delStatus != 0) {
ESP_LOGE("ESP-NOW", "Could not delete peer");
}
}
int convert_axis_to_pwm(int axis_value) {
// Convert the joystick axis value to a PWM value
// Assuming axis_value is in the range of 0-4095 for a 12-bit ADC
@@ -56,6 +64,6 @@ void sendRawData(void) {
ESP_LOGE("sendData()", "Ensure that received MAC is: %02X:%02X:%02X:%02X:%02X:%02X",
receiver_mac[0], receiver_mac[1], receiver_mac[2],
receiver_mac[3], receiver_mac[4], receiver_mac[5]);
deletePeer();
deleteDev();
}
}

View File

@@ -34,6 +34,7 @@ sensors_data_t buffer;
int convert_axis_to_pwm(int axis_value);
void get_joystick_xy_axis(int *x_axis, int *y_axis);
void sendRawData(void);
void deleteDev(void);
//static sensors_data_t buffer;
esp_err_t joystick_adc_init(void) {