mirror of
https://github.com/alexandrebobkov/ESP-Nodes.git
synced 2025-09-30 21:21:06 +00:00
ESP32-C3 RC & Receiver
This commit is contained in:
@@ -48,4 +48,78 @@ static void rc_send_data_task2 (void *pvParameter) {
|
||||
}
|
||||
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
static void rc_send_data_task (void *arg) {
|
||||
|
||||
while (true) {
|
||||
flagToSend = !flagToSend;
|
||||
if (esp_now_is_peer_exist(receiver_mac)) {
|
||||
sendData();
|
||||
}
|
||||
vTaskDelay (1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
void sendData (void) {
|
||||
// Send data, specify receiver MAC address, pointer to the data being sent, and length of data being sent.
|
||||
sensors_data_t buffer;
|
||||
buffer.type = 1;
|
||||
buffer.crc = 0;
|
||||
buffer.x_axis = 240;
|
||||
buffer.y_axis = 2040;
|
||||
buffer.nav_bttn = 0;
|
||||
buffer.motor1_rpm_pcm = 10;
|
||||
buffer.motor2_rpm_pcm = 0;
|
||||
buffer.motor3_rpm_pcm = 0;
|
||||
buffer.motor4_rpm_pcm = 0;
|
||||
ESP_LOGI(TAG, "x-axis: 0x%04X", (uint8_t)buffer.x_axis);
|
||||
ESP_LOGI(TAG, "y-axis: 0x%04X", (uint8_t)buffer.y_axis);
|
||||
ESP_LOGI(TAG, "pcm 1: 0x%04X", buffer.motor1_rpm_pcm);
|
||||
ESP_LOGI(TAG, "pcm 2: 0x%04X", (uint8_t)buffer.motor2_rpm_pcm);
|
||||
ESP_LOGI(TAG, "pcm 3: 0x%04X", (uint8_t)buffer.motor3_rpm_pcm);
|
||||
ESP_LOGI(TAG, "pcm 4: 0x%04X", (uint8_t)buffer.motor4_rpm_pcm);
|
||||
|
||||
//uint8_t result = esp_now_send(receiver_mac, &flagToSend, sizeof(flagToSend));
|
||||
uint8_t result = esp_now_send(receiver_mac, &buffer, sizeof(buffer));
|
||||
//uint8_t result = esp_now_send(receiver_mac, (sensors_data_t *)&buffer, sizeof(buffer));
|
||||
if (result != 0) {
|
||||
ESP_LOGE("ESP-NOW", "Error sending data!");
|
||||
deletePeer();
|
||||
}
|
||||
else
|
||||
ESP_LOGW("ESP-NOW", "Data was sent.");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
ESP-NOW
|
||||
*/
|
||||
/* Prepare ESPNOW data to be sent. */
|
||||
void sensors_data_prepare(espnow_data_packet_t *send_packet)
|
||||
{
|
||||
//sensors_data_t *buffer;
|
||||
//malloc(sizeof(sensors_data_t));
|
||||
//send_packet->buffer = &buffer;
|
||||
//sensors_data_t *buffer = (sensors_data_t *)send_packet->buffer;
|
||||
sensors_data_t *buffer = (sensors_data_t *)send_packet->buffer;
|
||||
assert(send_packet->len >= sizeof(sensors_data_t));
|
||||
|
||||
buffer->type = 1;
|
||||
buffer->crc = 0;
|
||||
buffer->x_axis = 0;
|
||||
buffer->y_axis = 0;
|
||||
buffer->nav_bttn = 0;
|
||||
buffer->motor1_rpm_pcm = 0;
|
||||
buffer->motor2_rpm_pcm = 0;
|
||||
buffer->motor3_rpm_pcm = 0;
|
||||
buffer->motor4_rpm_pcm = 0;
|
||||
ESP_LOGW(TAG, "x-axis: %x", (uint8_t)buffer->x_axis);
|
||||
buffer->crc = esp_crc16_le(UINT16_MAX, (uint8_t const *)buffer, send_packet->len);
|
||||
}
|
||||
void deletePeer (void) {
|
||||
uint8_t delStatus = esp_now_del_peer(receiver_mac);
|
||||
if (delStatus != 0) {
|
||||
ESP_LOGE("ESP-NOW", "Could not delete peer");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user