diff --git a/.gitignore b/.gitignore index c9d18ee..f32d5e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /dist/ +/build/ *.o *.out diff --git a/.vscode/settings.json b/.vscode/settings.json index 1f5ed49..712b88a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,23 +1,11 @@ { "files.associations": { "*.py": "python", - "types.h": "c", - "spidev.h": "c", - "fcntl.h": "c", - "stdlib.h": "c", - "math.h": "c", - "spi_utils.h": "c", - "cstdint": "c", - "color_utils.h": "c", - "data_sban_period2.h": "c", - "shader.h": "c", - "signal.h": "c", - "ioctl.h": "c", - "stdio.h": "c", - "ostream": "c", - "system_error": "c", - "variant": "c", - "string.h": "c", - "cstdlib": "c" - } + "app.h": "c", + "time.h": "c" + }, + "C_Cpp.errorSquiggles": "enabled", + "C_Cpp.default.includePath": [ + "./include" + ] } \ No newline at end of file diff --git a/Makefile b/Makefile index 37814ad..3726eaf 100644 --- a/Makefile +++ b/Makefile @@ -1,27 +1,46 @@ -CC = gcc -CFLAGS = -Wall -Wextra -O2 -LDFLAGS = -lm +# 编译器设置 +CC := gcc +CFLAGS := -Wall -Wextra -O2 -I./include +LDFLAGS := -lm +LIBS := -SRC_DIR = src -DIST_DIR = dist +# 目录设置 +SRC_DIR := src +BUILD_DIR := build +DIST_DIR := dist +INCLUDE_DIR := include -SRCS = $(wildcard $(SRC_DIR)/*.c) -OBJS = $(SRCS:$(SRC_DIR)/%.c=$(DIST_DIR)/%.o) -TARGET = $(DIST_DIR)/main +# 获取源文件和目标文件 +SOURCES := $(wildcard $(SRC_DIR)/*.c) +OBJECTS := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SOURCES)) +DEPS := $(OBJECTS:.o=.d) # 自动生成的依赖文件 -MKDIR_P = mkdir -p +# 最终可执行文件 +TARGET := $(DIST_DIR)/main +# 默认目标 all: $(TARGET) -$(TARGET): $(OBJS) - $(MKDIR_P) $(DIST_DIR) - $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) +# 链接可执行文件 +$(TARGET): $(OBJECTS) | $(DIST_DIR) + $(CC) $(LDFLAGS) $^ -o $@ $(LIBS) -$(DIST_DIR)/%.o: $(SRC_DIR)/%.c - $(MKDIR_P) $(DIST_DIR) - $(CC) $(CFLAGS) -c $< -o $@ +# 编译源文件并生成依赖 +$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | $(BUILD_DIR) + $(CC) $(CFLAGS) -MMD -MP -c $< -o $@ +# 创建必要的目录 +$(BUILD_DIR): + mkdir -p $@ + +$(DIST_DIR): + mkdir -p $@ + +# 包含自动生成的依赖 +-include $(DEPS) + +# 清理构建 clean: - rm -rf $(DIST_DIR) + rm -rf $(BUILD_DIR) $(TARGET) .PHONY: all clean \ No newline at end of file diff --git a/src/app.h b/include/app.h similarity index 99% rename from src/app.h rename to include/app.h index 1bf453e..fe1ca7b 100644 --- a/src/app.h +++ b/include/app.h @@ -7,11 +7,15 @@ typedef struct AppContext { int stop_flag; + int light_fd; + uint8_t* buffer; Color* colors; Status* status; + struct timeval start_time; + int num_leds; int data_size; } AppContext; diff --git a/src/color_utils.h b/include/color_utils.h similarity index 100% rename from src/color_utils.h rename to include/color_utils.h diff --git a/src/data_sban_period2.h b/include/data_sban_period2.h similarity index 100% rename from src/data_sban_period2.h rename to include/data_sban_period2.h diff --git a/src/shader.h b/include/shader.h similarity index 100% rename from src/shader.h rename to include/shader.h diff --git a/src/spi_utils.h b/include/spi_utils.h similarity index 100% rename from src/spi_utils.h rename to include/spi_utils.h diff --git a/src/main.c b/src/main.c index c7ae289..2b618db 100644 --- a/src/main.c +++ b/src/main.c @@ -1,13 +1,3 @@ -#include -#include -#include -#include -#include -#include - -#include "color_utils.h" -#include "shader.h" -#include "spi_utils.h" #include "app.h" int main() {