aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--src/c_defines.h13
-rw-r--r--src/c_halfcab.c49
-rw-r--r--src/c_screen.c112
-rw-r--r--src/c_screen.h57
-rw-r--r--src/esp/halfcab/halfcab.ino28
6 files changed, 226 insertions, 36 deletions
diff --git a/Makefile b/Makefile
index 761ea4c..b0fbb1d 100644
--- a/Makefile
+++ b/Makefile
@@ -34,6 +34,7 @@ TARGET = hc
ESP_NAME = halfcab.ino
SRC_NAME = c_halfcab
+SRC_NAME += c_screen
INC_NAME = c_defines
@@ -56,6 +57,8 @@ ifeq (${OS}, Linux)
CFLAGS += -D_GNU_SOURCE
endif
+LDFLAGS = -lX11
+
ifeq (${OS}, Linux)
CINCS = -isystem /usr/include
endif
diff --git a/src/c_defines.h b/src/c_defines.h
index 2b82bf6..7cc1779 100644
--- a/src/c_defines.h
+++ b/src/c_defines.h
@@ -50,8 +50,9 @@
#ifndef __C_DEFINES_H__
#define __C_DEFINES_H__
-#define PORT_NAME "/dev/ttyUSB0"
-#define PROGNAME "hc"
+#define PORT_NAME "/dev/ttyUSB0"
+#define SCREEN_W 2560
+#define SCREEN_H 1440
#define DATA_PIN D2
#define NUM_LEDS 60
@@ -65,4 +66,12 @@
#define BLUE CRGB(0, 0, 255)
#define GRUV CRGB(255, 80, 0)
+#define VERT_PIXEL_GAP 0
+#define HORZ_PIXEL_GAP 5
+
+enum bool_e {
+ FALSE,
+ TRUE
+};
+
#endif /* __C_DEFINES_H__ */
diff --git a/src/c_halfcab.c b/src/c_halfcab.c
index 68cd7d6..834a65e 100644
--- a/src/c_halfcab.c
+++ b/src/c_halfcab.c
@@ -51,13 +51,17 @@
#include <errno.h>
#include <fcntl.h>
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
+#include <X11/Xlib.h>
+
#include "c_defines.h"
+#include "c_screen.h"
static char
param_esp_com
@@ -122,12 +126,23 @@ open_esp(const char prog_name[])
return (fd);
}
+volatile sig_atomic_t end = 0;
+
+static void
+handle_sigterm(int signum)
+{
+ (void)signum;
+ end = TRUE;
+}
+
int
main
(int argc,
const char* argv[])
{
const char* prog_name = argv[0];
+ struct sigaction act;
+ Display* disp;
int fd;
int i;
unsigned char com[4];
@@ -142,19 +157,31 @@ main
return (EXIT_FAILURE);
}
if (argc < 4) {
- com[0] = 0xfe;
- com[1] = 0x00;
- com[2] = 0xaa;
- com[3] = 0xaa;
- i = 0;
- while (i < NUM_LEDS * 3) {
- memcpy(leds + i, com + 1, 3 * sizeof(unsigned char));
- i += 3;
+ com[0] = 0xff;
+ bzero(leds, (NUM_LEDS * 3) * sizeof(unsigned char));
+ disp = XOpenDisplay(NULL);
+ if (disp == NULL) {
+ i = 0;
+ while (i < NUM_LEDS * 3) {
+ leds[i] = 0xff;
+ i += 3;
+ }
+ write(fd, &com, 1 * sizeof(unsigned char));
+ write(fd, &leds, (NUM_LEDS * 3) * sizeof(unsigned char));
+ return (EXIT_FAILURE);
+ }
+ bzero(&act, sizeof(struct sigaction));
+ act.sa_handler = handle_sigterm;
+ sigaction(SIGTERM, &act, NULL);
+ sigaction(SIGINT, &act, NULL);
+ while (end == FALSE) {
+ c_get_screen_colors(leds, disp);
+ write(fd, &com, 1 * sizeof(unsigned char));
+ write(fd, &leds, (NUM_LEDS * 3) * sizeof(unsigned char));
}
- write(fd, &com, 1 * sizeof(unsigned char));
- write(fd, &leds, (NUM_LEDS * 3) * sizeof(unsigned char));
+ XCloseDisplay(disp);
} else {
- com[0] = 0xff;
+ com[0] = 0xfe;
i = 1;
while (i < 4) {
com[i] = atoi(argv[i]);
diff --git a/src/c_screen.c b/src/c_screen.c
new file mode 100644
index 0000000..5a67f9b
--- /dev/null
+++ b/src/c_screen.c
@@ -0,0 +1,112 @@
+/*
+ * =====================
+ * ==== ===============
+ * =====================
+ * === === ==== ==
+ * ==== == == = =
+ * ==== == = == =
+ * ==== == = == ====
+ * ==== == = == = =
+ * = = === ==== ==
+ * == ================
+ * =====================
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2025, joe
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the organization nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * halfcab: src/c_screen.c
+ * Wed, 24 Sep 2025 20:29:26 +0200
+ * joe <rbo@gmx.us>
+ */
+
+#include <X11/X.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+#include "c_defines.h"
+#include "c_screen.h"
+
+static void
+fill_led
+(unsigned char leds[],
+ const int i,
+ Display* disp,
+ XImage* img,
+ const int min_x,
+ const int max_x,
+ const int min_y,
+ const int max_y)
+{
+ XColor c;
+
+ (void)min_x;
+ (void)max_x;
+ (void)min_y;
+ (void)max_y;
+ c.pixel = XGetPixel(img, 0, 0);
+ XQueryColor(disp, DefaultColormap(disp, DefaultScreen(disp)), &c);
+ leds[i + 0] = c.red;
+ leds[i + 1] = c.green;
+ leds[i + 2] = c.blue;
+}
+
+void
+c_get_screen_colors
+(unsigned char leds[],
+ Display* disp)
+{
+ XImage* img;
+ const int top_leds = NUM_LEDS / 2;
+ const int side_leds = NUM_LEDS / 4;
+ const int top_px_per_led = SCREEN_W / top_leds;
+ const int side_px_per_led = SCREEN_H / side_leds;
+ int i;
+
+ img = XGetImage(
+ disp, RootWindow(disp, DefaultScreen(disp)),
+ 1920, 0,
+ SCREEN_W, SCREEN_H,
+ AllPlanes, ZPixmap
+ );
+ if (img == NULL) {
+ return;
+ }
+ i = 0;
+ fill_led(
+ leds, i,
+ disp, img,
+ 0, side_px_per_led,
+ VERT_PIXEL_GAP + (0 * side_px_per_led),
+ VERT_PIXEL_GAP + ((0 + 1) * side_px_per_led)
+ );
+ (void)top_px_per_led;
+ XDestroyImage(img);
+}
diff --git a/src/c_screen.h b/src/c_screen.h
new file mode 100644
index 0000000..6c93cf4
--- /dev/null
+++ b/src/c_screen.h
@@ -0,0 +1,57 @@
+/*
+ * =====================
+ * ==== ===============
+ * =====================
+ * === === ==== ==
+ * ==== == == = =
+ * ==== == = == =
+ * ==== == = == ====
+ * ==== == = == = =
+ * = = === ==== ==
+ * == ================
+ * =====================
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2025, joe
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the organization nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * halfcab: src/c_screen.h
+ * Wed, 24 Sep 2025 20:29:35 +0200
+ * joe <rbo@gmx.us>
+ */
+
+#ifndef __C_SCREEN_H__
+#define __C_SCREEN_H__
+
+#include <X11/Xlib.h>
+
+void c_get_screen_colors(unsigned char[], Display*);
+
+#endif /* __C_SCREEN_H__ */
diff --git a/src/esp/halfcab/halfcab.ino b/src/esp/halfcab/halfcab.ino
index f99393e..8d416c5 100644
--- a/src/esp/halfcab/halfcab.ino
+++ b/src/esp/halfcab/halfcab.ino
@@ -100,18 +100,9 @@ plain(void)
CRGB color;
color = BLACK;
- while (Serial.available() <= 0) {
- /* empty */
- }
- color.r = Serial.read();
- while (Serial.available() <= 0) {
- /* empty */
- }
- color.g = Serial.read();
- while (Serial.available() <= 0) {
- /* empty */
- }
- color.b = Serial.read();
+ color.r = read_byte();
+ color.g = read_byte();
+ color.b = read_byte();
fill(color);
}
@@ -149,19 +140,10 @@ loop(void)
com = 0;
com = read_byte();
if (com == 0xff) {
- plain();
- return;
- } else if (com == 0xfe) {
dynamic();
+ } else if (com == 0xfe) {
+ plain();
} else {
fill(BLUE);
}
-
-
-
- // else if (com == 0xfe) {
- // dynamic();
- // }
-
- delay(10);
}