Skip to content

Commit

Permalink
colorful LEDs
Browse files Browse the repository at this point in the history
  • Loading branch information
drom committed Aug 11, 2024
1 parent a949bc4 commit a4d3a6e
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 22 deletions.
6 changes: 3 additions & 3 deletions sw-panel-v3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ git pull
git submodule update --init --recursive
./install.sh esp32c6

cd ~/work/github/XAPOH/sw-panel-v3
cd ~/work/github/AI6YP/XAPOH/sw-panel-v3
. ~/work/github/espressif/esp-idf/export.sh

idf.py set-target esp32c6

idf.py build # just build

idf.py -p /dev/ttyUSB0 flash # build & flash
idf.py -p /dev/ttyACM0 flash # build & flash

idf.py -p /dev/ttyUSB0 flash monitor # build & flash & monitor -> exit Ctrl+]
idf.py -p /dev/ttyACM0 flash monitor # build & flash & monitor -> exit Ctrl+]
```
6 changes: 4 additions & 2 deletions sw-panel-v3/lib/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ body {
background-color: #088;
color: #fff;
border: 0;
font-size: 24px;
padding: 16px;
margin: 8px;
font-size: 32px;
/* line-height: 2.5; */
/* padding: 0 20px; */
text-shadow: 1px 1px 1px #000;
Expand Down Expand Up @@ -77,6 +79,6 @@ h1 {
.configs {
display: grid;
grid-template-columns: 50% 50%; /* 10%; */
grid-row-gap: 16px;
/* grid-row-gap: 16px; */
}

30 changes: 18 additions & 12 deletions sw-panel-v3/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ const stringify = require('onml/stringify.js');

const sendGpio = (socket, config) => {
console.log(config);
socket.send(Uint8Array.from([0, 0, config.gpios[0], config.gpios[1]]));
socket.send(Uint8Array.from([1, 0, config.gpios[2], config.gpios[3]]));
socket.send(Uint8Array.from([0, 0, config.gpios[0], config.gpios[1]]));
socket.send(Uint8Array.from([1, 0, config.gpios[2], config.gpios[3]]));
socket.send(Uint8Array.from([255].concat(config.gpios.slice(4))));
};

global.XAPOH = async (divName) => {
Expand All @@ -23,12 +24,13 @@ global.XAPOH = async (divName) => {
...state.configs.flatMap((config, i) => [
['input', {id: `send_cfg${i}`, class: 'btn_item', type: 'button', value: config.name}],
// ['input', {class: 'item', type: 'text', value: config.gpios.join('.')}],
['div', {class: 'item'}, config.gpios.join('.')],
// ['div', {class: 'item'}, config.gpios.join('.')],
// ['input', {class: 'btn_item del', type: 'button', value: '\u2715'}]
]),
// ['input', {class: 'num_item', type: 'text'}],
// ['input', {class: 'num_item', type: 'text'}],
// ['input', {class: 'btn_item add', type: 'button', value: '+'}]
// ['input', {id: 'send_lna', class: 'btn_item', type: 'button'}],
],
['div', {class: 'tiny'}, pkg.version]
];
Expand All @@ -37,15 +39,19 @@ global.XAPOH = async (divName) => {
// });

const state = {
configs: [
{name: '144', gpios: [6, 125, 8, 4]},
{name: '432', gpios: [66, 93, 16, 36]},
{name: '1296', gpios: [38, 125, 16, 64]},
{name: '2400', gpios: [102, 61, 20, 4]},
{name: 'SAT A', gpios: [5, 109, 10, 5]},
{name: 'SAT B', gpios: [10, 69, 18, 37]},
{name: 'SAT J', gpios: [6, 107, 10, 5]},
{name: 'SAT Q', gpios: [6, 60, 84, 4]},
configs: [// I2C0 I2C1 / rgb 0 \ / GRB 1 \ / GRB 2 \ / GRB 3 \ / GRB 4 \ / GRB 5 \ / GRB 6 \ / GRB 7 \ / GRB 8 \ / GRB 9 \ / GRB 10\
{name: '144', gpios: [6, 125, 8, 4, 0, 5, 0, 100,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]},
{name: '144+', gpios: [6, 125, 8, 20, 0, 5, 0, 0, 0,100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]},
{name: '432', gpios: [66, 93, 16, 36, 0, 5, 0, 0, 0, 0, 100,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]},
{name: '432+', gpios: [66, 93, 16, 52, 0, 5, 0, 0, 0, 0, 0, 0,100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]},
{name: '1296', gpios: [38, 125, 16, 64, 0, 5, 0, 0, 0, 0, 0, 0, 0, 100,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]},
{name: '1296+', gpios: [38, 125, 16, 80, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0,100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]},
{name: '2400', gpios: [102, 61, 20, 4, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]},
{name: '2400+', gpios: [102, 61, 20, 20, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]},
{name: 'SAT A', gpios: [5, 109, 10, 5, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50, 100,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]},
{name: 'SAT B', gpios: [10, 69, 18, 37, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100,0,100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]},
{name: 'SAT J', gpios: [6, 107, 10, 5, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50, 100,0, 0, 0, 0, 0, 0, 0, 0, 0, 0]},
{name: 'SAT Q', gpios: [6, 60, 84, 4, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100,0,100, 0, 0, 0, 0, 0, 0]},
]
};

Expand Down
80 changes: 76 additions & 4 deletions sw-panel-v3/main/sw-panel-v3-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

#include "driver/gpio.h"
#include "driver/i2c_master.h"
#include "driver/rmt_tx.h"

#include "led_strip_encoder.h"

// WIFI
#include "esp_wifi.h"
Expand All @@ -27,6 +30,11 @@

#include "pages.h"

#define RMT_LED_STRIP_RESOLUTION_HZ 10000000 // 10MHz resolution, 1 tick = 0.1us (led strip needs a high resolution)
#define RMT_LED_STRIP_GPIO_NUM 8

#define NUM_LEDS 11

// pins
#define PWR_SW 0 // pin6 <-
#define FUZE_IN 1 // pin7 -> ADC?
Expand All @@ -36,7 +44,7 @@
#define ON 5 // pin11 <-
#define DISPLAY_RS 6 // pin12 <-
#define DISPLAY_CS 7 // pin13 <-
#define DISPLAY_CLOCK 8 // pin14 <-
#define RGB 8 // pin14 <- LED Strip
#define BOOT 9 // pin15 ->
#define DISPLAY_DATA 14 // pin18 <-
#define DISPLAY_RESET 15 // pin19 <-
Expand All @@ -53,7 +61,8 @@

static const char *TAG = "XAPOH";

#include "lcd.h"

// #include "lcd.h"

/* FreeRTOS event group to signal when we are connected*/
static EventGroupHandle_t s_wifi_event_group;
Expand All @@ -64,11 +73,26 @@ static EventGroupHandle_t s_wifi_event_group;
#define WIFI_CONNECTED_BIT BIT0
#define WIFI_FAIL_BIT BIT1

struct pixels_s {
uint8_t data[NUM_LEDS * 3];
// rmt_channel_handle_t led_chan; // = NULL;
// rmt_encoder_handle_t led_encoder;
// rmt_transmit_config_t tx_config;
};
typedef struct pixels_s pixels_t;




static i2c_master_bus_config_t i2c_master;
static i2c_device_config_t i2c_dev0;
static i2c_device_config_t i2c_dev1;

static pixels_t pixels;
static rmt_channel_handle_t led_chan = NULL;
static rmt_encoder_handle_t led_encoder0 = NULL;

rmt_transmit_config_t tx_config = { .loop_count = 0, };

static int s_retry_num = 0;

Expand Down Expand Up @@ -233,6 +257,11 @@ esp_err_t msg_handler(httpd_req_t *req) {
httpd_ws_frame_t ws_pkt;
uint8_t *buf = NULL;
uint8_t *tx_buf = NULL;
rmt_encoder_handle_t led_encoder = NULL;
led_strip_encoder_config_t encoder_config = {
.resolution = RMT_LED_STRIP_RESOLUTION_HZ,
};

memset(&ws_pkt, 0, sizeof(httpd_ws_frame_t));
ws_pkt.type = HTTPD_WS_TYPE_BINARY;
/* Set max_len = 0 to get the frame len */
Expand Down Expand Up @@ -260,7 +289,14 @@ esp_err_t msg_handler(httpd_req_t *req) {
free(buf);
return ret;
}
rdwr_i2c(i2c_master, buf, tx_buf, ws_pkt.len);
if (buf[0] == 255) { // RGB LEDS
ESP_LOGI(TAG, "pkt_len: %d", ws_pkt.len);
memcpy(&pixels.data, buf + 1, ws_pkt.len - 1);
ESP_ERROR_CHECK(rmt_transmit(led_chan, led_encoder0, pixels.data, sizeof(pixels.data), &tx_config));
ESP_ERROR_CHECK(rmt_tx_wait_all_done(led_chan, portMAX_DELAY));
} else {
rdwr_i2c(i2c_master, buf, tx_buf, ws_pkt.len);
}
ws_pkt.payload = tx_buf;
}
// ESP_LOGI(TAG, "Packet type: %d", ws_pkt.type);
Expand Down Expand Up @@ -350,8 +386,44 @@ void app_main(void) {
rdwr_i2c(i2c_master, default0, default0, 4);
rdwr_i2c(i2c_master, default1, default1, 4);

// RGB init
ESP_LOGI(TAG, "Create RMT TX channel");
rmt_tx_channel_config_t tx_chan_config = {
.clk_src = RMT_CLK_SRC_DEFAULT, // select source clock
.gpio_num = RMT_LED_STRIP_GPIO_NUM,
.mem_block_symbols = 64, // increase the block size can make the LED less flickering
.resolution_hz = RMT_LED_STRIP_RESOLUTION_HZ,
.trans_queue_depth = 4, // set the number of transactions that can be pending in the background
};
ESP_ERROR_CHECK(rmt_new_tx_channel(&tx_chan_config, &led_chan));


ESP_LOGI(TAG, "Install led strip encoder");
rmt_encoder_handle_t led_encoder = NULL;
led_strip_encoder_config_t encoder_config = {
.resolution = RMT_LED_STRIP_RESOLUTION_HZ,
};
ESP_ERROR_CHECK(rmt_new_led_strip_encoder(&encoder_config, &led_encoder));
led_encoder0 = led_encoder;

ESP_LOGI(TAG, "Enable RMT TX channel");
ESP_ERROR_CHECK(rmt_enable(led_chan));

// rmt_transmit_config_t tx_config = {
// .loop_count = 0, // no transfer loop
// };

pixels = (pixels_t) { .data = {
0, 0, 5, // r g b
100,0, 0, // G R B
}};

ESP_ERROR_CHECK(rmt_transmit(led_chan, led_encoder0, pixels.data, sizeof(pixels.data), &tx_config));
ESP_ERROR_CHECK(rmt_tx_wait_all_done(led_chan, portMAX_DELAY));


// SPI LCD
lcd_init(spi);
// lcd_init(spi);

wifi_init_sta();
start_webserver();
Expand Down
2 changes: 1 addition & 1 deletion sw-panel-v3/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xapoh",
"version": "1.1.1",
"version": "1.2.0",
"description": "Web XAPOH",
"main": "index.js",
"directories": {
Expand Down

0 comments on commit a4d3a6e

Please # to comment.