From 81790b4bb6f1bdad4fdb6735a75de0fdcc292715 Mon Sep 17 00:00:00 2001 From: klein panic Date: Tue, 22 Oct 2024 21:37:15 -0400 Subject: [PATCH] added shit --- Earth/README.md | 3 + timer/README.md | 3 + timer/build/Makefile | 25 ++++++++ timer/include/timer.h | 48 +++++++++++++++ timer/obj/main.o | Bin 0 -> 8920 bytes timer/src/main.c | 133 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 212 insertions(+) create mode 100644 Earth/README.md create mode 100644 timer/README.md create mode 100644 timer/build/Makefile create mode 100644 timer/include/timer.h create mode 100644 timer/obj/main.o create mode 100644 timer/src/main.c diff --git a/Earth/README.md b/Earth/README.md new file mode 100644 index 0000000..b62acc9 --- /dev/null +++ b/Earth/README.md @@ -0,0 +1,3 @@ +# Earth Project + +This is a C project generated with the setup tool. diff --git a/timer/README.md b/timer/README.md new file mode 100644 index 0000000..c494e32 --- /dev/null +++ b/timer/README.md @@ -0,0 +1,3 @@ +# timer Project + +This is a C project generated with the setup tool. diff --git a/timer/build/Makefile b/timer/build/Makefile new file mode 100644 index 0000000..c896579 --- /dev/null +++ b/timer/build/Makefile @@ -0,0 +1,25 @@ +# Makefile + +CC = gcc +CFLAGS = -Wall -I../include +LDFLAGS = -lm + +SRC_DIR = ../src +OBJ_DIR = ../obj +INCLUDE_DIR = ../include + +SOURCES = $(wildcard $(SRC_DIR)/*.c) +OBJECTS = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SOURCES)) + +TARGET = timer_app + +all: $(TARGET) + +$(TARGET): $(OBJECTS) + $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) + +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -f $(OBJ_DIR)/*.o $(TARGET) diff --git a/timer/include/timer.h b/timer/include/timer.h new file mode 100644 index 0000000..88f360c --- /dev/null +++ b/timer/include/timer.h @@ -0,0 +1,48 @@ +// include/timer.h +#ifndef TIMER_H +#define TIMER_H + +#include +#include +#include +#include +#include // Include this for framebuffer structures +#include +#include +#include +#include +#include +#include +#include +#include // For disk usage calculations + +#define SCREEN_WIDTH 800 +#define SCREEN_HEIGHT 600 +#define CENTER_X (SCREEN_WIDTH / 2) +#define CENTER_Y (SCREEN_HEIGHT / 2) +#define RADIUS 200 +#define HOUR_HAND_LENGTH 100 +#define MINUTE_HAND_LENGTH 150 + +#define RING_COLOR 0xFFFFFF // White color +#define TIMER_COLOR 0xFFA500 // Orange color +#define TIMER_START_VALUE 60 // Start value of the countdown timer in seconds + +typedef struct { + int x; + int y; +} Point; + +typedef struct fb_var_screeninfo fb_var_screeninfo; // Alias for convenience + +typedef int framebuffer_t; // Define the framebuffer_t as an int for this context + +void draw_ring(int *framebuffer, fb_var_screeninfo vinfo, int center_x, int center_y, int radius, int thickness, int color); +void draw_static_ring(int *framebuffer, fb_var_screeninfo vinfo); +void draw_dynamic_ring(int *framebuffer, fb_var_screeninfo vinfo); +void draw_countdown_timer(int *framebuffer, fb_var_screeninfo vinfo); +void draw_clock_face(int *framebuffer, fb_var_screeninfo vinfo); +void update_time(int *framebuffer, fb_var_screeninfo vinfo); +void draw_text(int *framebuffer, fb_var_screeninfo vinfo, const char *text, int x, int y, int size, int color); + +#endif // TIMER_H diff --git a/timer/obj/main.o b/timer/obj/main.o new file mode 100644 index 0000000000000000000000000000000000000000..f05c8187b25dc6e4fb704fc12431d62785f07a09 GIT binary patch literal 8920 zcmb<-^>JfjWMqH=Mg}_u1P><4z%WA|!FB*M9T<2Sco;%GI-h!U*8b=${n8owq0{$G zbL|&~3cGGsiSE!ZmWPT>nrlBWROofP%5;Z*usl?((j6+%?fQX#{e^DVFN_yD4|w#7 zw1Uj@=yv_#!FZ_K^-U+!gxJF%bAvsa-*|X**52qWz0w(aq0{$_OQ-7zmrma!-L5A( z4;_3Z&v@bDkMB1+4|ThqVZ6}k`sU?gMh1rCt}j3azHDP;U`XSCf9VsyR_L2g{DPr7 z()iz>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c7vb`Nh;vl!f!fh5*9A)u7A?jbD&fn0OD8xGa*tKy5XU(?IS7VGtXHp$%Vfc?%MU zwR=FLcp!O@7zo4KF`#w?vN)_A11k?eYC#y*jsex%$m(J3k}n`ZXt@DW4{Lu&K+AKG z7zo4K0StP@mANH}Nep_$B}EWA1I8*!%}LY)*MfQ}i6w~)dP&8_40=WR5KeM_ZfljhA;1=0&EH=xqsb}C35l*d5&VE6{qUXa-^F%XT; z*I{5_0GWxd{|;0?NDndw*@etE1oeHO@ro?|0IDA}X@D#aO1sE>OQ?QO9}!u62dHpn zfb^4)#bNftXeX$CWHli64XAz)8yUm&!NkI$`ax+ACI+Hm`VG)DfWitS55qywJc%BE z1#%D-2Oty!DE>ftK^P +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define RING_COLOR 0xFFFFFF // White for the static ring +#define TIMER_COLOR 0xFFA500 // Orange for the dynamic ring and timer +#define TIMER_START_VALUE 60 // Start value of the countdown timer in seconds + +int countdown = TIMER_START_VALUE; + +// Set a pixel at (x, y) with color in the framebuffer +void set_pixel(int *framebuffer, struct fb_var_screeninfo vinfo, int x, int y, int color) { + if (x >= 0 && x < vinfo.xres_virtual && y >= 0 && y < vinfo.yres_virtual) { + framebuffer[y * vinfo.xres_virtual + x] = color; + } +} + +// Draw a ring with specified thickness +void draw_ring(int *framebuffer, struct fb_var_screeninfo vinfo, int center_x, int center_y, int radius, int thickness, int color) { + for (int r = radius - thickness / 2; r <= radius + thickness / 2; r++) { + for (int angle = 0; angle < 360; ++angle) { + int x = center_x + (int)(r * cos(angle * M_PI / 180)); + int y = center_y + (int)(r * sin(angle * M_PI / 180)); + set_pixel(framebuffer, vinfo, x, y, color); + } + } +} + +// Draw the static ring for the clock face +void draw_static_ring(int *framebuffer, struct fb_var_screeninfo vinfo) { + draw_ring(framebuffer, vinfo, CENTER_X, CENTER_Y, RADIUS, 5, RING_COLOR); // Draw a thick white ring +} + +// Draw the dynamic ring with decreasing radius +void draw_dynamic_ring(int *framebuffer, struct fb_var_screeninfo vinfo) { + int dynamic_radius = RADIUS * countdown / TIMER_START_VALUE; // Scale the radius based on remaining time + draw_ring(framebuffer, vinfo, CENTER_X, CENTER_Y, dynamic_radius, 3, TIMER_COLOR); // Draw an orange ring +} + +// Draw the countdown timer inside the ring +void draw_countdown_timer(int *framebuffer, struct fb_var_screeninfo vinfo) { + char timer_text[10]; + sprintf(timer_text, "%d", countdown); + draw_text(framebuffer, vinfo, timer_text, CENTER_X - 10, CENTER_Y - 10, 3, TIMER_COLOR); // Center the text +} + +// Draw the clock face with rings and numbers +void draw_clock_face(int *framebuffer, struct fb_var_screeninfo vinfo) { + memset(framebuffer, 0, vinfo.yres_virtual * vinfo.xres_virtual * sizeof(int)); // Clear screen + draw_static_ring(framebuffer, vinfo); // Draw the static white ring + draw_dynamic_ring(framebuffer, vinfo); // Draw the dynamic orange ring + draw_countdown_timer(framebuffer, vinfo); // Draw the countdown timer +} + +// Update the clock hands, date/time display, and system information +void update_time(int *framebuffer, struct fb_var_screeninfo vinfo) { + time_t rawtime; + struct tm *timeinfo; + char date_buffer[80]; + char time_buffer[80]; + + time(&rawtime); + timeinfo = localtime(&rawtime); + + float hour_angle_degrees = (30 * (timeinfo->tm_hour % 12)) + (timeinfo->tm_min * 0.5); + float hour_angle = -hour_angle_degrees * M_PI / 180.0 + M_PI / 2; + + float minute_angle_degrees = 6 * timeinfo->tm_min; + float minute_angle = -minute_angle_degrees * M_PI / 180.0 + M_PI / 2; + + draw_hand(framebuffer, vinfo, hour_angle, HOUR_HAND_LENGTH, 0xFFFFFF); // Hour hand + draw_hand(framebuffer, vinfo, minute_angle, MINUTE_HAND_LENGTH, 0xFFFFFF); // Minute hand + + strftime(date_buffer, sizeof(date_buffer), "%Y-%m-%d", timeinfo); + draw_text(framebuffer, vinfo, date_buffer, CENTER_X - 100, CENTER_Y + 200, 3, 0xFFFFFF); + + strftime(time_buffer, sizeof(time_buffer), "%H:%M:%S", timeinfo); + draw_text(framebuffer, vinfo, time_buffer, CENTER_X - 80, CENTER_Y + 250, 3, 0xFFFFFF); + + update_system_info(framebuffer, vinfo); // Display system info + + // Countdown timer logic + draw_countdown_timer(framebuffer, vinfo); + + if (countdown > 0) { + countdown--; + } +} + +// Main function to continuously update the clock +int main() { + int fbfd = open("/dev/fb0", O_RDWR); + if (fbfd == -1) { + perror("Error: cannot open framebuffer device"); + exit(1); + } + + struct fb_var_screeninfo vinfo; + if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) { + perror("Error reading variable information"); + close(fbfd); + exit(2); + } + + size_t screensize = vinfo.yres_virtual * vinfo.xres_virtual * vinfo.bits_per_pixel / 8; + int *framebuffer = (int *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0); + if (framebuffer == MAP_FAILED) { + perror("Error mapping framebuffer device to memory"); + close(fbfd); + exit(3); + } + + // Continuously update the clock + while (1) { + draw_clock_face(framebuffer, vinfo); + update_time(framebuffer, vinfo); + sleep(1); // Sleep for 1 second to update the clock every second + } + + // Cleanup + munmap(framebuffer, screensize); + close(fbfd); + + return 0; +}