aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/c_defines.h74
-rw-r--r--src/c_halfcab.c97
-rw-r--r--src/esp/halfcab/halfcab.ino35
3 files changed, 181 insertions, 25 deletions
diff --git a/src/c_defines.h b/src/c_defines.h
new file mode 100644
index 0000000..608a057
--- /dev/null
+++ b/src/c_defines.h
@@ -0,0 +1,74 @@
+/*
+ * =====================
+ * ==== ===============
+ * =====================
+ * === === ==== ==
+ * ==== == == = =
+ * ==== == = == =
+ * ==== == = == ====
+ * ==== == = == = =
+ * = = === ==== ==
+ * == ================
+ * =====================
+ *
+ * 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_defines.h
+ * Sat, 20 Sep 2025 17:24:52 +0200
+ * joe <rbo@gmx.us>
+ */
+
+#ifndef __C_DEFINES_H__
+#define __C_DEFINES_H__
+
+#define PORT_NAME "/dev/ttyUSB0"
+#define PROGNAME "hc"
+
+#define DATA_PIN D2
+#define NUM_LEDS 60
+#define BRIGHTNESS 254
+#define LED_TYPE WS2812B
+#define COLOR_ORDER GRB
+
+#define BLACK CRGB(0, 0, 0)
+#define RED CRGB(255, 0, 0)
+#define GREEN CRGB(0, 255, 0)
+#define BLUE CRGB(0, 0, 255)
+#define GRUV CRGB(255, 80, 0)
+
+enum colors_e {
+ R,
+ G,
+ B
+};
+
+#endif /* __C_DEFINES_H__ */
diff --git a/src/c_halfcab.c b/src/c_halfcab.c
index 68943f0..cab333c 100644
--- a/src/c_halfcab.c
+++ b/src/c_halfcab.c
@@ -49,14 +49,107 @@
* the main
*/
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include <termios.h>
+#include <unistd.h>
+
+#include "c_defines.h"
+
+static char
+param_esp_com
+(int fd,
+ const char prog_name[])
+{
+ struct termios tty;
+
+ if (tcgetattr(fd, &tty) != 0) {
+ dprintf(
+ STDERR_FILENO,
+ "%s: %s: %s\n",
+ prog_name,
+ "tcgetattr error with esp",
+ strerror(errno)
+ );
+ return (1);
+ }
+ cfsetospeed(&tty, B115200);
+ cfsetispeed(&tty, B115200);
+ tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; /* 8-bit chars */
+ tty.c_iflag &= ~IGNBRK; /* disable break processing */
+ tty.c_lflag = 0; /* no signaling chars, no echo, */
+ tty.c_oflag = 0; /* no remapping, no delays */
+ tty.c_cc[VMIN] = 1; /* read doesn't block */
+ tty.c_cc[VTIME] = 5; /* 0.5 seconds read timeout */
+ tty.c_iflag &= ~(IXON | IXOFF | IXANY); /* shut off xon/xoff ctrl */
+ tty.c_cflag |= (CLOCAL | CREAD);/* ignore modem controls, enable reading */
+ tty.c_cflag &= ~(PARENB | PARODD); /* no parity */
+ tty.c_cflag &= ~CSTOPB; /* 1 stop bit */
+ tty.c_cflag &= ~CRTSCTS; /* no hardware flow control */
+ if(tcsetattr(fd, TCSANOW, &tty) != 0) {
+ dprintf(
+ STDERR_FILENO,
+ "%s: %s: %s\n",
+ prog_name,
+ "tcgetattr error with esp",
+ strerror(errno)
+ );
+ return (1);
+ }
+ return (0);
+}
+
+static int
+open_esp(const char prog_name[])
+{
+ int fd;
+
+ fd = open(PORT_NAME, O_WRONLY | O_NOCTTY | O_SYNC);
+ if (fd < 0) {
+ dprintf(
+ STDERR_FILENO,
+ "%s: %s: %s\n",
+ prog_name,
+ "error opening esp",
+ strerror(errno)
+ );
+ return (-1);
+ }
+ return (fd);
+}
int
main
(int argc,
const char* argv[])
{
- (void)argc;
- (void)argv;
+ const char* prog_name = argv[0];
+ int fd;
+ const unsigned char com = 0xff;
+/* const unsigned char data[2] = { 0xfe, 0x00 }; */
+ /* unsigned char rgb[3];
+ unsigned char i; */
+
+ fd = open_esp(prog_name);
+ if (fd < 0) {
+ return (EXIT_FAILURE);
+ }
+ if (param_esp_com(fd, prog_name) != 0) {
+ close(fd);
+ return (EXIT_FAILURE);
+ }
+ if (argc < 4) {
+ write(fd, &com, 1 * sizeof(unsigned char));
+ } else {
+ /* i = 1;
+ while (i < 4) {
+ rgb[i] = atoi(argv[i]);
+ i++;
+ } */
+ }
+ close(fd);
return (EXIT_SUCCESS);
}
diff --git a/src/esp/halfcab/halfcab.ino b/src/esp/halfcab/halfcab.ino
index 9dac98c..c8935f5 100644
--- a/src/esp/halfcab/halfcab.ino
+++ b/src/esp/halfcab/halfcab.ino
@@ -51,23 +51,7 @@
#include <FastLED.h>
-#define DATA_PIN D2
-#define NUM_LEDS 60
-#define BRIGHTNESS 254
-#define LED_TYPE WS2812B
-#define COLOR_ORDER GRB
-
-enum colors_e {
- R,
- G,
- B
-};
-
-#define BLACK CRGB(0, 0, 0)
-#define RED CRGB(255, 0, 0)
-#define GREEN CRGB(0, 255, 0)
-#define BLUE CRGB(0, 0, 255)
-#define GRUV CRGB(255, 80, 0)
+#include "c_defines.h"
CRGB leds[NUM_LEDS];
@@ -87,12 +71,16 @@ fill(CRGB color)
void
blink(void)
{
- fill(BLUE);
- delay(100);
+ fill(RED);
+ delay(60);
+ fill(BLACK);
+ delay(60);
+ fill(RED);
+ delay(60);
fill(BLACK);
- delay(100);
- fill(BLUE);
- delay(100);
+ delay(60);
+ fill(RED);
+ delay(60);
fill(BLACK);
delay(1000);
}
@@ -100,6 +88,7 @@ blink(void)
void
plain(void)
{
+ fill(GRUV);
}
void
@@ -110,6 +99,7 @@ setup(void)
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
fill(BLACK);
+ blink();
}
void
@@ -118,7 +108,6 @@ loop(void)
uint8_t i;
uint8_t com;
- blink();
com = 0;
while (Serial.available() <= 0) {
/* empty */