Skip to content

Commit 272f80d

Browse files
committed
Adding DickesG and bugfix for timelib
1 parent 94ddcba commit 272f80d

File tree

8 files changed

+187
-6
lines changed

8 files changed

+187
-6
lines changed

dickesg/Makefile

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FILE=dickesg.hex
2+
CFLAGS=-mmcu=atmega644 -O2 -std=c99
3+
4+
%.o: %.c
5+
avr-gcc $(CFLAGS) -o $@ $< ../lib/ledmatrix.c ../lib/font.c
6+
7+
%.hex: %.o
8+
avr-objcopy -j .text -j .data -O ihex $< $@
9+
10+
%.s: %.c
11+
avr-gcc $(CFLAGS) -S -o $@ $< ../lib/ledmatrix.c ../lib/font.c
12+
13+
%.bin: %.o
14+
avr-objcopy -j .text -j .data -O binary $< $@
15+
16+
all: $(FILE)
17+
asm: $(FILE:.hex=.s)
18+
bin: $(FILE:.hex=.bin)
19+
20+
clean:
21+
rm -f *.o *.s *.hex
22+
23+
flash: $(FILE)
24+
avrdude -C /etc/avrdude.conf -p m644 -P usb -c usbasp -U flash:w:$<:a
25+
26+
simulate:
27+
../simulate.sh $(FILE:.hex=.c)

dickesg/dickesg.c

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/* Marquee (scrolling message) for LED-Matrix 2
2+
* Code by Endres */
3+
#define F_CPU 8000000UL
4+
#include <avr/io.h>
5+
#include <util/delay.h>
6+
#include <string.h>
7+
#include "../lib/ledmatrix.h"
8+
#include "../lib/font.h"
9+
#include "nyan-animation.h"
10+
11+
char devtal[] = "/dev/tal e.V.";
12+
char hackerspace[] = "Hackerspace Wuppertal";
13+
char dickesg[] = " auf dem Dicken G";
14+
15+
uint8_t msg_length = 0;
16+
17+
uint16_t tick = 0;
18+
uint8_t i, j, b;
19+
20+
// Nyan
21+
uint8_t x;
22+
23+
void drawNyan(uint8_t x, uint8_t frame) {
24+
uint16_t *s = &nyan[frame*31];
25+
uint16_t *m = &nyan_mask[frame*31];
26+
for(uint8_t i = 0; i < 31; i++) {
27+
if(x+i > 231) break;
28+
if(x+i >= 31) {
29+
panelData[x+i-31] |= *s;
30+
panelData[x+i-31] &= ~(~*s & *m);
31+
}
32+
s++; m++;
33+
}
34+
}
35+
36+
uint8_t f;
37+
uint8_t s;
38+
39+
void setup() {
40+
ledmatrix_setup();
41+
msg_length = strlen(devtal);
42+
}
43+
44+
void loop() {
45+
clear();
46+
if(tick == 0) {
47+
i = 200;
48+
b = 0;
49+
j = 1;
50+
51+
x = 0;
52+
f = 0;
53+
s = 0;
54+
}
55+
if(tick < 150) {
56+
writeText(devtal, i);
57+
i--;
58+
} else if(tick < 200) {
59+
if(b) {
60+
writeText(devtal, i);
61+
}
62+
b = b ^ 1;
63+
} else if(tick < 300) {
64+
writeText(devtal, i);
65+
} else if(tick < 316) {
66+
//addDoubleRowDown(i, 0xff, 16-j);
67+
writeTextY(devtal, i, j);
68+
writeTextY(hackerspace, 16, 32-j);
69+
//_delay_ms(990);
70+
j++;
71+
} else if(tick < 500) {
72+
writeText(hackerspace, 16);
73+
} else if(tick < 900) {
74+
if(x>=31)
75+
panelData[x-31] = 0;
76+
if(x < 231) {
77+
x++;
78+
} else {
79+
x = 0;
80+
}
81+
clear();
82+
if(x >= 24) {
83+
for(uint8_t i = 0; i < x - 24; i++) {
84+
if((i/5)%2 == s/2) {
85+
panelData[i] = 0x9112;
86+
} else {
87+
panelData[i] = 0x4889;
88+
}
89+
}
90+
}
91+
s++;
92+
if(s==4) s = 0;
93+
drawNyan(x, f++);
94+
if(f == 6) f = 0;
95+
shiftPixelData();
96+
_delay_ms(40);
97+
} else {
98+
tick = -1;
99+
}
100+
shiftPixelData();
101+
_delay_ms(10);
102+
tick++;
103+
}
104+
105+
int main() {
106+
setup();
107+
while(1) loop();
108+
}

dickesg/nyan-animation.h

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
static uint16_t nyan[] = {
2+
0x0000, 0x1c00, 0x1300, 0x1980, 0x0c8e, 0x06d2, 0x7ff2, 0x8016, 0x1f8c, 0x3ec8, 0x6fee, 0x7fea, 0x7fac, 0x7be8, 0x5ee8, 0x7fe8, 0x7c28, 0x4058, 0x404c, 0x608a, 0x79ae, 0x3828, 0x182c, 0x88aa, 0x702a, 0x20ac, 0x4188, 0x4050, 0x3c60, 0x03c0, 0x0000,
3+
0x0000, 0x0600, 0x0880, 0x0680, 0x0240, 0x024e, 0x7ff2, 0x8012, 0x1f8c, 0x3ec8, 0x6fec, 0x7fea, 0x7fae, 0x7be8, 0x5ee8, 0x7fe8, 0x7fe8, 0x7c28, 0x4058, 0x404a, 0x608a, 0x39ae, 0x1828, 0x882c, 0x78aa, 0x102a, 0x20ae, 0x4188, 0x4050, 0x3c60, 0x03c0,
4+
0x0000, 0x0040, 0x00a0, 0x00a0, 0x00a0, 0x0180, 0x3fff, 0x4009, 0x8fc5, 0x9f66, 0xb7f4, 0xbff5, 0xbfd5, 0xbdf7, 0xaf74, 0xbff4, 0xbff4, 0xbe14, 0xa02c, 0xa024, 0xb045, 0x9cd5, 0x8c17, 0x4414, 0x3c56, 0x0815, 0x1055, 0x20c7, 0x2028, 0x1e30, 0x01e0,
5+
0x0000, 0x0020, 0x0090, 0x00a0, 0x0100, 0x0107, 0x3ff9, 0x4009, 0x8fc6, 0x9f64, 0xb7f6, 0xbff5, 0xbfd7, 0xbdf4, 0xaf74, 0xbff4, 0xbff4, 0xbe14, 0xa02c, 0xa026, 0xb045, 0x9cd7, 0x8c14, 0x4416, 0x3c55, 0x0815, 0x1057, 0x20c4, 0x2028, 0x1e30, 0x01e0,
6+
0x0300, 0x0480, 0x0480, 0x0687, 0x02c9, 0x0359, 0x3ffa, 0x400c, 0x8fc6, 0x9f65, 0xb7f5, 0xbff4, 0xbfd4, 0xbdf4, 0xaf74, 0xbff4, 0xbe14, 0xa02e, 0xa025, 0xb045, 0xbcd7, 0x9c16, 0x8c15, 0x4455, 0x3817, 0x1054, 0x20c4, 0x2028, 0x1e30, 0x01e0, 0x0000,
7+
0x0000, 0x0600, 0x0880, 0x0687, 0x0249, 0x0251, 0x3ffa, 0x400c, 0x8fc7, 0x9f65, 0xb7f5, 0xbff4, 0xbfd4, 0xbdf4, 0xaf74, 0xbff4, 0xbc34, 0x8057, 0x804d, 0xa08d, 0xb9ae, 0x982e, 0x882d, 0x48a9, 0x302f, 0x20a8, 0x4188, 0x4050, 0x3c60, 0x03c0, 0x0000,
8+
};
9+
static uint16_t nyan_mask[] = {
10+
0x0000, 0x1c00, 0x1f00, 0x1f80, 0x0f8e, 0x07de, 0x7ffe, 0xfffe, 0xfffc, 0xfff8, 0xfffe, 0xfffe, 0xfffc, 0xfff8, 0xfff8, 0xfff8, 0xfff8, 0xfff8, 0xfffc, 0xfffe, 0xfffe, 0xfff8, 0xfffc, 0xfffe, 0x7ffe, 0x3ffc, 0x7ff8, 0x7ff0, 0x3fe0, 0x03c0, 0x0000,
11+
0x0000, 0x0600, 0x0f80, 0x0780, 0x03c0, 0x03ce, 0x7ffe, 0xfffe, 0xfffc, 0xfff8, 0xfffc, 0xfffe, 0xfffe, 0xfff8, 0xfff8, 0xfff8, 0xfff8, 0xfff8, 0xfff8, 0xfffe, 0xfffe, 0xfffe, 0xfff8, 0xfffc, 0x7ffe, 0x1ffe, 0x3ffe, 0x7ff8, 0x7ff0, 0x3fe0, 0x03c0,
12+
0x0000, 0x0040, 0x00e0, 0x00e0, 0x00e0, 0x01c0, 0x3fff, 0x7fff, 0xffff, 0xfffe, 0xfffc, 0xffff, 0xffff, 0xffff, 0xfffc, 0xfffc, 0xfffc, 0xfffc, 0xfffc, 0xfffc, 0xffff, 0xffff, 0xffff, 0x7ffc, 0x3ffe, 0x0fff, 0x1fff, 0x3fff, 0x3ff8, 0x1ff0, 0x01e0,
13+
0x0000, 0x0020, 0x00f0, 0x00e0, 0x0180, 0x0187, 0x3fff, 0x7fff, 0xfffe, 0xfffc, 0xfffe, 0xffff, 0xffff, 0xfffc, 0xfffc, 0xfffc, 0xfffc, 0xfffc, 0xfffc, 0xfffe, 0xffff, 0xffff, 0xfffc, 0x7ffe, 0x3fff, 0x0fff, 0x1fff, 0x3ffc, 0x3ff8, 0x1ff0, 0x01e0,
14+
0x0300, 0x0780, 0x0780, 0x0787, 0x03cf, 0x03df, 0x3ffe, 0x7ffc, 0xfffe, 0xffff, 0xffff, 0xfffc, 0xfffc, 0xfffc, 0xfffc, 0xfffc, 0xfffc, 0xfffe, 0xffff, 0xffff, 0xffff, 0xfffe, 0xffff, 0x7fff, 0x3fff, 0x1ffc, 0x3ffc, 0x3ff8, 0x1ff0, 0x01e0, 0x0000,
15+
0x0000, 0x0600, 0x0f80, 0x0787, 0x03cf, 0x03df, 0x3ffe, 0x7ffc, 0xffff, 0xffff, 0xffff, 0xfffc, 0xfffc, 0xfffc, 0xfffc, 0xfffc, 0xfffc, 0xffff, 0xffff, 0xffff, 0xfffe, 0xfffe, 0xffff, 0x7fff, 0x3fff, 0x3ff8, 0x7ff8, 0x7ff0, 0x3fe0, 0x03c0, 0x0000,
16+
};

lib/font.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,23 @@ uint8_t* getNextFontChar(void) {
3535
return pointer;
3636
}
3737

38+
3839
void writeText(char* txt, uint8_t x) {
40+
writeTextY(txt, x, 16);
41+
}
42+
43+
void writeTextY(char* txt, uint8_t x, uint8_t y) {
3944
msg = txt;
4045
uint8_t *chr;
4146
uint8_t c;
42-
while(*(msg) != 0) { // msg+1?
47+
while(*(msg) != 0 && x < 200) { // msg+1?
4348
chr = getNextFontChar();
4449
for(int i = 0; i < 8; i++) {
45-
setDoubleRow(x++, *(chr++));
50+
if(y < 16) {
51+
addDoubleRowUp(x++, *(chr++), y);
52+
} else {
53+
addDoubleRowDown(x++, *(chr++), y-16);
54+
}
4655
}
4756
}
4857
}

lib/font.h

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#include <avr/io.h>
22
uint8_t* getNextFontChar(void);
33
void writeText(char* txt, uint8_t x);
4+
void writeTextY(char* txt, uint8_t x, uint8_t y);

lib/ledmatrix.c

+16-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
#define SRCK PC6
1111
#define RCK PC7
1212

13-
#define PANELS 5
14-
#define PANELDATA_SIZE (40*PANELS)
15-
1613
uint16_t panelData[PANELDATA_SIZE];
1714

1815
void clear() {
@@ -36,6 +33,22 @@ void setDoubleRow(uint8_t x, uint8_t value) {
3633
}
3734
}
3835

36+
void addDoubleRowUp(uint8_t x, uint8_t value, uint8_t y) {
37+
panelData[x] &= 0xffff >> y;
38+
for(int i = 0; i < 16-y; i++) {
39+
panelData[x] |= ((value&1)*3)<<(i*2+y);
40+
value = value >> 1;
41+
}
42+
}
43+
44+
void addDoubleRowDown(uint8_t x, uint8_t value, uint8_t y) {
45+
panelData[x] &= 0xffff << 16-y;
46+
for(int i = 0; i < 16-y; i++) {
47+
panelData[x] |= ((value&1)*3)<<(i*2-y);
48+
value = value >> 1;
49+
}
50+
}
51+
3952
void setRow(uint8_t x, uint16_t value) {
4053
panelData[x] = value;
4154
}

lib/ledmatrix.h

+7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
#include <avr/io.h>
2+
3+
#define PANELS 5
4+
#define PANELDATA_SIZE (40*PANELS)
5+
6+
extern uint16_t panelData[PANELDATA_SIZE];
27
void clear(void);
38
void setPixel(uint16_t x, uint8_t y, uint8_t value);
49
void setDoubleRow(uint8_t x, uint8_t value);
10+
void addDoubleRowUp(uint8_t x, uint8_t value, uint8_t y);
11+
void addDoubleRowDown(uint8_t x, uint8_t value, uint8_t y);
512
void setRow(uint8_t x, uint16_t value);
613
uint16_t getPixel(int x, int y);
714
void screen_off(void);

net_time/timelib.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void gmtime_r(uint32_t time, struct tm* output) {
3838

3939
output->tm_yday = day_number;
4040
uint8_t mon = 0;
41-
while(day_number >= days_month(mon, year)) {
41+
while(day_number > days_month(mon, year)) {
4242
day_number -= days_month(mon, year);
4343
mon++;
4444
}

0 commit comments

Comments
 (0)