This commit is contained in:
Hendrik Rauh 2026-03-20 23:02:14 +01:00 committed by GitHub
commit 60061e655c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 110 additions and 3 deletions

View file

@ -1 +1,8 @@
idf_component_register(SRCS "src/dmx.c" INCLUDE_DIRS "include")
idf_component_register(
SRCS
"src/dmx.c"
INCLUDE_DIRS
"include"
REQUIRES
logger
esp_dmx)

View file

@ -1,9 +1,25 @@
#pragma once
#include "esp_dmx.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Initialize the DMX interface.
* @param port The DMX port to initialize.
* @param pin_tx The pin for TX of the RS485.
* @param pin_rx The pin for RX of the RS485.
*/
void init_dmx(dmx_port_t port, int pin_tx, int pin_rx);
/**
* @brief Send some test DMX data on the specified port.
* @param port The DMX port to send data on.
*/
void send_dmx(dmx_port_t port);
#ifdef __cplusplus
}
#endif

View file

@ -0,0 +1,43 @@
#define LOG_TAG "DMX" ///< "DMX" log tag for this file
#include <stdint.h>
#include "dmx.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "logger.h"
static void dmx_sender_task(void *pv_parameters) {
dmx_port_t port = (dmx_port_t)(intptr_t)pv_parameters;
TickType_t last_wake_time = xTaskGetTickCount();
while (1) {
send_dmx(port);
vTaskDelayUntil(&last_wake_time, pdMS_TO_TICKS(1000));
}
}
void init_dmx(dmx_port_t port, int pin_tx, int pin_rx) {
LOGI("Initializing DMX port %d on pin %d (TX) and %d (RX)", port, pin_tx,
pin_rx);
dmx_config_t config = DMX_CONFIG_DEFAULT;
dmx_personality_t personalities[] = {};
dmx_driver_install(port, &config, personalities, 0);
dmx_set_pin(port, pin_tx, pin_rx, DMX_PIN_NO_CHANGE); // RTS pin is not used
BaseType_t task_created = xTaskCreate(dmx_sender_task, "dmx_sender", 2048,
(void *)(intptr_t)port, 5, NULL);
if (task_created != pdPASS) {
LOGE("Failed to create DMX sender task for port %d", port);
}
}
void send_dmx(dmx_port_t port) {
LOGD("Sending DMX data on port %d", port);
uint8_t dmx_data[DMX_PACKET_SIZE] = {DMX_SC, 0, 0, 0, 255, 100, 0, 100, 0};
dmx_write(port, dmx_data, DMX_PACKET_SIZE);
dmx_send(port);
}

37
include/README Normal file
View file

@ -0,0 +1,37 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the convention is to give header files names that end with `.h'.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

View file

@ -4,5 +4,6 @@ idf_component_register(
INCLUDE_DIRS
"."
REQUIRES
web_server
logger)
dmx
logger
web_server)

View file

@ -2,6 +2,7 @@
#include <stdio.h>
#include "dmx.h"
#include "esp_err.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
@ -34,6 +35,8 @@ void app_main(void) {
LOGI("Web server started successfully");
LOGI("Open http://192.168.4.1 in your browser");
init_dmx(DMX_NUM_1, 21, 33);
// Keep the app running
while (1) {
vTaskDelay(pdMS_TO_TICKS(1000));