alles ums licht im Keller und Sommerschein
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.4 KiB

4 months ago
/*
ESP-IDF Sniffer
This example demonstrates how to use the DMX sniffer to read packet
metadata from incoming DMX data packets. Data is read synchronously from the
DMX bus. If there are no errors in the packet a log is written every 1 second
that contains information about the received DMX data packet. When the data
times out, the driver is uninstalled and the program terminates.
Note: this example is for use with the ESP-IDF. It will not work on Arduino!
Created 28 January 2021
By Mitch Weisbrod
https://github.com/someweisguy/esp_dmx
*/
#include "esp_dmx.h"
#include "esp_log.h"
#include "esp_system.h"
#include "freertos/task.h"
#include "dmx/sniffer.h"
#include "driver/gpio.h"
#define TX_PIN 48 // The DMX transmit pin.
#define RX_PIN 47 // The DMX receive pin.
#define EN_PIN 35 // The DMX transmit enable pin.
#define SN_PIN 45 // The DMX sniffer pin.
static const char *TAG = "dmx_sniffer"; // The log tagline.
void task_idf_sniffer(void *arg)
{
ESP_LOGI(TAG, "task_idf_sniffer start");
const dmx_port_t dmx_num = DMX_NUM_1;
// Set communication pins and install the driver
dmx_config_t config = DMX_CONFIG_DEFAULT;
dmx_driver_install(dmx_num, &config, DMX_INTR_FLAGS_DEFAULT);
dmx_set_pin(dmx_num, TX_PIN, RX_PIN, EN_PIN);
// Install the default GPIO ISR and enable the sniffer
ESP_ERROR_CHECK(gpio_install_isr_service(DMX_SNIFFER_INTR_FLAGS_DEFAULT));
dmx_sniffer_enable(dmx_num, SN_PIN);
dmx_metadata_t metadata;
bool is_connected = false;
TickType_t last_update = xTaskGetTickCount();
while (true)
{
// Block until a packet is received
if (dmx_sniffer_get_data(dmx_num, &metadata, DMX_TIMEOUT_TICK))
{
const TickType_t now = xTaskGetTickCount();
if (!is_connected)
{
// Log when we first connect
ESP_LOGI(TAG, "DMX is connected.");
is_connected = true;
}
if (now - last_update >= pdMS_TO_TICKS(1000))
{
// Only log data every 1000ms
ESP_LOGI(TAG, "Break: %li, MAB: %li", metadata.break_len,
metadata.mab_len);
last_update = now;
}
}
else if (is_connected)
{
// DMX timed out after having been previously connected
ESP_LOGI(TAG, "DMX was disconnected.");
dmx_sniffer_disable(dmx_num);
break;
}
}
ESP_LOGI(TAG, "Uninstalling the DMX driver.");
dmx_driver_delete(dmx_num);
ESP_LOGI(TAG, "task_idf_sniffer end");
}