draw real clock

This commit is contained in:
Thomas Klaehn 2020-02-20 21:04:11 +01:00
parent 8ecdf59dc6
commit 8234b46a7d
2 changed files with 25 additions and 12 deletions

View File

@ -37,7 +37,7 @@ endif
C_FLAGS += -fpic C_FLAGS += -fpic
C_FLAGS += -O0 -g -Wall C_FLAGS += -O0 -ggdb3 -Wall
CPP_FLAGS += $(addprefix -I, $(INCLUDES)) CPP_FLAGS += $(addprefix -I, $(INCLUDES))
CHECK_FLAGS = $(addprefix -I,$(filter-out $(PREFIX)/include/,$(INCLUDES))) CHECK_FLAGS = $(addprefix -I,$(filter-out $(PREFIX)/include/,$(INCLUDES)))
@ -116,11 +116,11 @@ check: $(CC_SRCS)
$(UNIT_TEST_TARGET): $(UNIT_TEST_OBJS) $(THIS_MAKEFILE) $(UNIT_TEST_TARGET): $(UNIT_TEST_OBJS) $(THIS_MAKEFILE)
@mkdir -p $(BIN_DIR)/$(UNIT_TEST_SRC_DIR) @mkdir -p $(BIN_DIR)/$(UNIT_TEST_SRC_DIR)
$(CC) $(CC_FLAGS) $(LD_FLAGS) $(UNIT_TEST_OBJS) -o $@ $(CC) $(C_FLAGS) $(LD_FLAGS) $(UNIT_TEST_OBJS) -o $@
$(TARGET): $(OBJS) $(THIS_MAKEFILE) $(TARGET): $(OBJS) $(THIS_MAKEFILE)
@mkdir -p $(BIN_DIR) @mkdir -p $(BIN_DIR)
$(CC) $(CC_FLAGS) $(LD_FLAGS) $(OBJS) $(addprefix -l,$(LIBS)) -o $@ $(CC) $(C_FLAGS) $(LD_FLAGS) $(OBJS) $(addprefix -l,$(LIBS)) -o $@
.PRECIOUS: $(OBJ_DIR)/%.d .PRECIOUS: $(OBJ_DIR)/%.d
$(OBJ_DIR)/%.d: $(SRC_DIR)/%.c $(OBJ_DIR)/%.d: $(SRC_DIR)/%.c

View File

@ -4,6 +4,7 @@
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
#include <time.h>
#include "board.h" #include "board.h"
#include "driver.h" #include "driver.h"
@ -90,28 +91,40 @@ int main(void)
double dest_x; double dest_x;
double dest_y; double dest_y;
time_t T;
struct tm tm;
while(1) { while(1) {
img_load(image, clock_face, 240 * 240); img_load(image, clock_face, 240 * 240);
// just to shown image orientation
img_draw_line(image, 10, 10, 12, 12, 0x00f8);
img_draw_line(image, 10, 11, 12, 12, 0x00f8);
img_draw_line(image, 10, 12, 12, 12, 0x00f8);
T = time(NULL);
tm = *localtime(&T);
min_angle = (360 / 60) * tm.tm_min;
if(min_angle >= 360.0) {
min_angle -= 360.0;
}
dest_x = root_x + min_len * cos(min_angle * M_PI / 180); dest_x = root_x + min_len * cos(min_angle * M_PI / 180);
dest_y = root_y + min_len * sin(min_angle * M_PI / 180); dest_y = root_y + min_len * sin(min_angle * M_PI / 180);
img_draw_line(image, (uint16_t)root_x, (uint16_t)root_y, (uint16_t)dest_x, (uint16_t)dest_y, 0xffff); img_draw_line(image, (uint16_t)root_x, (uint16_t)root_y, (uint16_t)dest_x, (uint16_t)dest_y, 0xffff);
min_angle += 360 / 60;
std_angle = 0.5 * (60 * tm.tm_hour + tm.tm_min);
if(std_angle >= 360.0) {
std_angle -= 360.0;
}
dest_x = root_x + std_len * cos(std_angle * M_PI / 180); dest_x = root_x + std_len * cos(std_angle * M_PI / 180);
dest_y = root_y + std_len * sin(std_angle * M_PI / 180); dest_y = root_y + std_len * sin(std_angle * M_PI / 180);
img_draw_line(image, (uint16_t)root_x, (uint16_t)root_y, (uint16_t)dest_x, (uint16_t)dest_y, 0xffff); img_draw_line(image, (uint16_t)root_x, (uint16_t)root_y, (uint16_t)dest_x, (uint16_t)dest_y, 0xffff);
std_angle += 360.0 / (60 * 12);
drv_write(&lcd_drv, (const char *)image, 240 * 240); drv_write(&lcd_drv, (const char *)image, 240 * 240);
sleep(1); sleep(1);
if(min_angle >= 360.0) {
min_angle -= 360.0;
}
if(std_angle >= 360.0) {
std_angle -= 360.0;
}
} }
drv_close(&lcd_drv); drv_close(&lcd_drv);