diff options
author | joe <rbo@gmx.us> | 2025-09-20 18:24:36 +0200 |
---|---|---|
committer | joe <rbo@gmx.us> | 2025-09-20 18:24:36 +0200 |
commit | 978bf4e4d1feb0d28ccc3eab0e8b6c781dab32ca (patch) | |
tree | 23d3a9294e61df30dfdcc5d03ae027cd8dc62133 | |
parent | ok (diff) | |
download | halfcab-978bf4e4d1feb0d28ccc3eab0e8b6c781dab32ca.tar.gz halfcab-978bf4e4d1feb0d28ccc3eab0e8b6c781dab32ca.tar.bz2 halfcab-978bf4e4d1feb0d28ccc3eab0e8b6c781dab32ca.tar.xz halfcab-978bf4e4d1feb0d28ccc3eab0e8b6c781dab32ca.tar.zst halfcab-978bf4e4d1feb0d28ccc3eab0e8b6c781dab32ca.zip |
com works
Diffstat (limited to '')
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 19 | ||||
-rw-r--r-- | src/c_defines.h | 74 | ||||
-rw-r--r-- | src/c_halfcab.c | 97 | ||||
-rw-r--r-- | src/esp/halfcab/halfcab.ino | 35 |
5 files changed, 193 insertions, 33 deletions
@@ -186,6 +186,7 @@ $RECYCLE.BIN/ # End of https://www.gitignore.io/api/c++,linux,emacs,windows +.cache/ sketch.yaml hc .ccls* @@ -16,7 +16,7 @@ # # GNU Makefile -default: debug +default: run SHELL := /bin/sh OS = $(shell /usr/bin/uname) @@ -35,8 +35,11 @@ ESP_NAME = halfcab.ino SRC_NAME = c_halfcab +INC_NAME = c_defines + SRCS = $(addprefix ${SRC_DIR}, $(addsuffix .c, ${SRC_NAME})) INCS = $(addprefix ${SRC_DIR}, $(addsuffix .h, ${SRC_NAME})) +INCS += $(addprefix ${SRC_DIR}, $(addsuffix .h, ${INC_NAME})) OBJS = $(patsubst ${SRC_DIR}%.c, ${OBJ_DIR}%.c.o, ${SRCS}) ARDUINO = arduino-cli @@ -49,9 +52,9 @@ CFLAGS += -pedantic CFLAGS += -march=haswell CFLAGS += -O2 CFLAGS += -pipe -# ifeq (${OS}, Linux) -# CFLAGS += -D_GNU_SOURCE -# endif +ifeq (${OS}, Linux) +CFLAGS += -D_GNU_SOURCE +endif ifeq (${OS}, Linux) CINCS = -isystem /usr/include @@ -72,18 +75,18 @@ ${TRG_DIR}${TARGET}: ${OBJ_DIR} ${OBJS} debug: CFLAGS += -O0 debug: CFLAGS += -g3 -debug: all +debug: ${TRG_DIR}${TARGET} asan: CFLAGS += -O0 asan: CFLAGS += -g3 asan: CFLAGS += -fsanitize=address -asan: all +asan: ${TRG_DIR}${TARGET} clean: ${RM} ${OBJS} vgcore.* ${TARGET}.core ${TARGET} ${OBJ_DIR} esp: - ${ARDUINO} compile -v -j8 --warnings all --fqbn ${ESP_FQBN} ${SRC_DIR}${ESP_DIR} + ${ARDUINO} compile -v -j8 --warnings all --fqbn ${ESP_FQBN} --build-property build.extra_flags=-I${SRC_DIR} ${SRC_DIR}${ESP_DIR} ${ARDUINO} upload -p ${ESP_DEV} --fqbn ${ESP_FQBN} ${SRC_DIR}${ESP_DIR} attach: @@ -97,4 +100,4 @@ all: esp ${TRG_DIR}${TARGET} run: debug ${TRG_DIR}${TARGET} -.PHONY: esp attach mon hc +.PHONY: esp attach mon hc clean asan debug all run 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 */ |