Browse Source

add wordclock

feature/2015
Hendrik Langer 10 years ago
parent
commit
9eed617c20
  1. 4
      src/animations/Makefile
  2. 2
      src/animations/config.in
  3. 376
      src/animations/wordclock.c
  4. 35
      src/animations/wordclock.h
  5. 8
      src/display_loop.c

4
src/animations/Makefile

@ -58,6 +58,10 @@ ifeq ($(ANIMATION_TIME),y)
SRC += borg_time.c
endif
ifeq ($(ANIMATION_CLOCK),y)
SRC += wordclock.c
endif
ifeq ($(ANIMATION_DNA),y)
SRC += dna.c
endif

2
src/animations/config.in

@ -50,6 +50,8 @@ comment "Animations"
int "Request Timeout (ms)" TIME_UPDATE_TIMEOUT 50
endmenu
dep_bool "WordClock" ANIMATION_CLOCK $RANDOM_SUPPORT
source src/animations/bitmapscroller/config.in
mainmenu_option next_comment

376
src/animations/wordclock.c

@ -0,0 +1,376 @@
/*
* Description: Clock
* Author: h3ndrik
* License: AGPLv3+
*/
#include <stdio.h>
#include <stdlib.h>
#include "../random/prng.h"
#include "../config.h"
#include "../pixel.h"
#include "../util.h"
#ifndef COLOR_DEFAULT
#define COLOR_DEFAULT 3
#endif
#ifndef COLOR_OFF
#define COLOR_OFF 0
#endif
uint8_t hours = 10;
uint8_t minutes = 25;
uint8_t seconds = 45;
uint8_t oldhours = 0;
uint8_t oldminutes = 0;
uint8_t time_update(void)
{
//send request
//time_request();
minutes += seconds / 60;
seconds = seconds % 60;
hours += minutes / 60;
minutes = minutes % 60;
return 1;
}
void set_funk(void)
{
setpixel((pixel){ 7, 3},COLOR_DEFAULT);
setpixel((pixel){ 6, 3},COLOR_DEFAULT);
setpixel((pixel){ 5, 3},COLOR_DEFAULT);
setpixel((pixel){ 4, 3},COLOR_DEFAULT);
}
void set_esistuhr(void)
{
setpixel((pixel){10, 0},COLOR_DEFAULT);
setpixel((pixel){ 9, 0},COLOR_DEFAULT);
setpixel((pixel){ 7, 0},COLOR_DEFAULT);
setpixel((pixel){ 6, 0},COLOR_DEFAULT);
setpixel((pixel){ 5, 0},COLOR_DEFAULT);
setpixel((pixel){ 2, 9},COLOR_DEFAULT);
setpixel((pixel){ 1, 9},COLOR_DEFAULT);
setpixel((pixel){ 0, 9},COLOR_DEFAULT);
}
void set_nach(void)
{
setpixel((pixel){ 3, 3},COLOR_DEFAULT);
setpixel((pixel){ 2, 3},COLOR_DEFAULT);
setpixel((pixel){ 1, 3},COLOR_DEFAULT);
setpixel((pixel){ 0, 3},COLOR_DEFAULT);
}
void set_vor(void)
{
setpixel((pixel){10, 3},COLOR_DEFAULT);
setpixel((pixel){ 9, 3},COLOR_DEFAULT);
setpixel((pixel){ 8, 3},COLOR_DEFAULT);
}
void set_hour(uint8_t hour, unsigned char value)
{
switch (hours) {
case 0:
//set_hour(11, COLOR_OFF);
setpixel((pixel){ 4, 8},value);
setpixel((pixel){ 3, 8},value);
setpixel((pixel){ 2, 8},value);
setpixel((pixel){ 1, 8},value);
setpixel((pixel){ 0, 8},value);
break;
case 1:
//set_hour(0, COLOR_OFF);
setpixel((pixel){10, 5},value);
setpixel((pixel){ 9, 5},value);
setpixel((pixel){ 8, 5},value);
setpixel((pixel){ 7, 5},value);
break;
case 2:
//set_hour(1, COLOR_OFF);
setpixel((pixel){ 3, 5},value);
setpixel((pixel){ 2, 5},value);
setpixel((pixel){ 1, 5},value);
setpixel((pixel){ 0, 5},value);
break;
case 3:
//set_hour(2, COLOR_OFF);
setpixel((pixel){10, 6},value);
setpixel((pixel){ 9, 6},value);
setpixel((pixel){ 8, 6},value);
setpixel((pixel){ 7, 6},value);
break;
case 4:
//set_hour(3, COLOR_OFF);
setpixel((pixel){ 3, 6},value);
setpixel((pixel){ 2, 6},value);
setpixel((pixel){ 1, 6},value);
setpixel((pixel){ 0, 6},value);
break;
case 5:
//set_hour(4, COLOR_OFF);
setpixel((pixel){ 3, 4},value);
setpixel((pixel){ 2, 4},value);
setpixel((pixel){ 1, 4},value);
setpixel((pixel){ 0, 4},value);
break;
case 6:
//set_hour(5, COLOR_OFF);
setpixel((pixel){10, 7},value);
setpixel((pixel){ 9, 7},value);
setpixel((pixel){ 8, 7},value);
setpixel((pixel){ 7, 7},value);
setpixel((pixel){ 6, 7},value);
break;
case 7:
//set_hour(6, COLOR_OFF);
setpixel((pixel){10, 8},value);
setpixel((pixel){ 9, 8},value);
setpixel((pixel){ 8, 8},value);
setpixel((pixel){ 7, 8},value);
setpixel((pixel){ 6, 8},value);
setpixel((pixel){ 5, 8},value);
break;
case 8:
//set_hour(7, COLOR_OFF);
setpixel((pixel){ 3, 7},value);
setpixel((pixel){ 2, 7},value);
setpixel((pixel){ 1, 7},value);
setpixel((pixel){ 0, 7},value);
break;
case 9:
//set_hour(8, COLOR_OFF);
setpixel((pixel){ 7, 9},value);
setpixel((pixel){ 6, 9},value);
setpixel((pixel){ 5, 9},value);
setpixel((pixel){ 4, 9},value);
break;
case 10:
//set_hour(9, COLOR_OFF);
setpixel((pixel){10, 9},value);
setpixel((pixel){ 9, 9},value);
setpixel((pixel){ 8, 9},value);
setpixel((pixel){ 7, 9},value);
break;
case 11:
//set_hour(10, COLOR_OFF);
setpixel((pixel){ 5, 4},value);
setpixel((pixel){ 4, 4},value);
setpixel((pixel){ 3, 4},value);
break;
}
}
void set_minute(uint8_t minute, unsigned char value)
{
switch (minutes) {
case 0:
case 1:
case 2:
case 3:
case 4:
break;
case 5:
case 6:
case 7:
case 8:
case 9:
//set_minute(0, COLOR_OFF);
/* fünf */
setpixel((pixel){ 3, 0},value);
setpixel((pixel){ 2, 0},value);
setpixel((pixel){ 1, 0},value);
setpixel((pixel){ 0, 0},value);
set_nach();
break;
case 10:
case 11:
case 12:
case 13:
case 14:
//set_minute(5, COLOR_OFF);
/* zehn */
setpixel((pixel){10, 1},value);
setpixel((pixel){ 9, 1},value);
setpixel((pixel){ 8, 1},value);
setpixel((pixel){ 7, 1},value);
set_nach();
break;
case 15:
case 16:
case 17:
case 18:
case 19:
//set_minute(10, COLOR_OFF);
/* viertel */
setpixel((pixel){ 6, 2},value);
setpixel((pixel){ 5, 2},value);
setpixel((pixel){ 4, 2},value);
setpixel((pixel){ 3, 2},value);
setpixel((pixel){ 2, 2},value);
setpixel((pixel){ 1, 2},value);
setpixel((pixel){ 0, 2},value);
set_nach();
break;
case 20:
case 21:
case 22:
case 23:
case 24:
//set_minute(15, COLOR_OFF);
/* zwanzig */
setpixel((pixel){ 6, 1},value);
setpixel((pixel){ 5, 1},value);
setpixel((pixel){ 4, 1},value);
setpixel((pixel){ 3, 1},value);
setpixel((pixel){ 2, 1},value);
setpixel((pixel){ 1, 1},value);
setpixel((pixel){ 0, 1},value);
set_nach();
break;
case 25:
case 26:
case 27:
case 28:
case 29:
//set_minute(20, COLOR_OFF);
/* fünf */
setpixel((pixel){ 3, 0},value);
setpixel((pixel){ 2, 0},value);
setpixel((pixel){ 1, 0},value);
setpixel((pixel){ 0, 0},value);
set_vor();
/* halb */
setpixel((pixel){10, 4},value);
setpixel((pixel){ 9, 4},value);
setpixel((pixel){ 8, 4},value);
setpixel((pixel){ 7, 4},value);
break;
case 30:
case 31:
case 32:
case 33:
case 34:
//set_minute(25, COLOR_OFF);
/* halb */
setpixel((pixel){10, 4},value);
setpixel((pixel){ 9, 4},value);
setpixel((pixel){ 8, 4},value);
setpixel((pixel){ 7, 4},value);
set_nach();
break;
case 35:
case 36:
case 37:
case 38:
case 39:
//set_minute(30, COLOR_OFF);
/* fünf */
setpixel((pixel){ 3, 0},value);
setpixel((pixel){ 2, 0},value);
setpixel((pixel){ 1, 0},value);
setpixel((pixel){ 0, 0},value);
set_nach();
/* halb */
setpixel((pixel){10, 4},value);
setpixel((pixel){ 9, 4},value);
setpixel((pixel){ 8, 4},value);
setpixel((pixel){ 7, 4},value);
break;
case 40:
case 41:
case 42:
case 43:
case 44:
//set_minute(35, COLOR_OFF);
/* zwanzig */
setpixel((pixel){ 6, 1},value);
setpixel((pixel){ 5, 1},value);
setpixel((pixel){ 4, 1},value);
setpixel((pixel){ 3, 1},value);
setpixel((pixel){ 2, 1},value);
setpixel((pixel){ 1, 1},value);
setpixel((pixel){ 0, 1},value);
set_vor();
break;
case 45:
case 46:
case 47:
case 48:
case 49:
//set_minute(40, COLOR_OFF);
/* viertel */
setpixel((pixel){ 6, 2},value);
setpixel((pixel){ 5, 2},value);
setpixel((pixel){ 4, 2},value);
setpixel((pixel){ 3, 2},value);
setpixel((pixel){ 2, 2},value);
setpixel((pixel){ 1, 2},value);
setpixel((pixel){ 0, 2},value);
set_vor();
break;
case 50:
case 51:
case 52:
case 53:
case 54:
//set_minute(45, COLOR_OFF);
/* zehn */
setpixel((pixel){10, 1},value);
setpixel((pixel){ 9, 1},value);
setpixel((pixel){ 8, 1},value);
setpixel((pixel){ 7, 1},value);
set_vor();
break;
case 55:
case 56:
case 57:
case 58:
case 59:
//set_minute(50, COLOR_OFF);
/* fünf */
setpixel((pixel){ 3, 0},value);
setpixel((pixel){ 2, 0},value);
setpixel((pixel){ 1, 0},value);
setpixel((pixel){ 0, 0},value);
set_vor();
break;
}
}
void wordclock(void)
{
while (1) {
if(time_update() == 0)
{
set_funk();
return;
}
if (oldminutes != minutes) {
clear_screen(COLOR_OFF);
set_minute(minutes, COLOR_DEFAULT);
oldminutes = minutes;
if (oldhours != hours) {
set_hour(hours, COLOR_DEFAULT);
oldhours = hours;
}
set_esistuhr();
}
wait(10); /* milliseconds */
seconds++;
}
}

35
src/animations/wordclock.h

@ -0,0 +1,35 @@
/*
* Description: Clock
* Author: h3ndrik
* License: AGPLv3+
*/
/* ESKISTAFÜNF
* ZEHNZWANZIG
* DREIVIERTEL
* VORFUNKNACH
* HALBAELFÜNF
* EINSXÄMZWEI
* DREIAUSVIER
* SECHSNLACHT
* SIEBENZWÖLF
* ZEHNEUNKUHR
*/
#ifndef BORG_WORDCLOCK_H_
#define BORG_WORDCLOCK_H_
#include <stdint.h>
//update time
uint8_t time_update(void);
void set_funk(void);
void set_esistuhr(void);
void set_nach(void);
void set_vor(void);
//display the time
void wordclock(void);
#endif /* BORG_CLOCK_H_ */

8
src/display_loop.c

@ -26,6 +26,9 @@
#ifdef ANIMATION_TIME
#include "animations/borg_time.h"
#endif
#ifdef ANIMATION_CLOCK
#include "animations/wordclock.h"
#endif
#include "borg_hw/borg_hw.h"
#include "can/borg_can.h"
#include "random/prng.h"
@ -265,6 +268,11 @@ void display_loop(){
dna();
break;
#endif
#ifdef ANIMATION_CLOCK
case 27:
wordclock();
break;
#endif
#ifdef ANIMATION_TESTS
case 31:

Loading…
Cancel
Save