Rev 1199 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1199 | Rev 1437 | ||
---|---|---|---|
1 | /**************************************************************************** |
1 | /**************************************************************************** |
2 | * Copyright (C) 2011 by Claas Anders "CaScAdE" Rathje * |
2 | * Copyright (C) 2011-2012 by Claas Anders "CaScAdE" Rathje * |
3 | * admiralcascade@gmail.com * |
3 | * admiralcascade@gmail.com * |
4 | * Project-URL: http://www.mylifesucks.de/oss/c-epilepsy/ * |
4 | * Project-URL: http://www.mylifesucks.de/oss/c-epilepsy/ * |
5 | * * |
5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * |
6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License as published by * |
7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License. * |
8 | * the Free Software Foundation; either version 2 of the License. * |
9 | * * |
9 | * * |
10 | * This program is distributed in the hope that it will be useful, * |
10 | * This program is distributed in the hope that it will be useful, * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
13 | * GNU General Public License for more details. * |
13 | * GNU General Public License for more details. * |
14 | * * |
14 | * * |
15 | * You should have received a copy of the GNU General Public License * |
15 | * You should have received a copy of the GNU General Public License * |
16 | * along with this program; if not, write to the * |
16 | * along with this program; if not, write to the * |
17 | * Free Software Foundation, Inc., * |
17 | * Free Software Foundation, Inc., * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
19 | ****************************************************************************/ |
19 | ****************************************************************************/ |
20 | 20 | ||
21 | #include "epi_helpers.h" |
21 | #include "epi_helpers.h" |
22 | 22 | ||
23 | // clear anomation |
23 | // clear anomation |
24 | 24 | ||
25 | void clear(void) { |
25 | void clear(void) { |
26 | for (uint8_t i = 0; i < 7; i++) { |
26 | for (uint8_t i = 0; i < 7; i++) { |
27 | animation[i] = 0; |
27 | animation[i] = 0; |
28 | } |
28 | } |
29 | } |
29 | } |
30 | 30 | ||
31 | /** |
31 | /** |
32 | * Display degree on the EPI |
32 | * Display degree on the EPI |
33 | * @param animation the animation array to set the LEDs in |
33 | * @param animation the animation array to set the LEDs in |
34 | * @param degree 0-360 degree to set |
34 | * @param degree 0-360 degree to set |
35 | */ |
35 | */ |
36 | void degree2epi(uint8_t *animation, uint16_t degree) { |
36 | void degree2epi(uint8_t *animation, uint16_t degree) { |
37 | setLed(animation, (degree * 10) / 75, 1); |
37 | setLed(animation, (degree * 10) / 75, 1); |
38 | } |
38 | } |
39 | 39 | ||
40 | void setSingleLed(uint8_t *animation, uint8_t led) { |
40 | void setSingleLed(uint8_t *animation, uint8_t led) { |
41 | uint8_t segment = led / 8; |
41 | uint8_t segment = led / 8; |
42 | uint8_t ledleft = (led - segment * 8); |
42 | uint8_t ledleft = (led - segment * 8); |
43 | animation[segment] |= (128 >> (7 - ledleft)); |
43 | animation[segment] |= (128 >> (7 - ledleft)); |
44 | } |
44 | } |
45 | 45 | ||
46 | void unsetSingleLed(uint8_t *animation, uint8_t led) { |
46 | void unsetSingleLed(uint8_t *animation, uint8_t led) { |
47 | uint8_t segment = led / 8; |
47 | uint8_t segment = led / 8; |
48 | uint8_t ledleft = (led - segment * 8); |
48 | uint8_t ledleft = (led - segment * 8); |
49 | animation[segment] &= ~(128 >> (7 - ledleft)); |
49 | animation[segment] &= ~(128 >> (7 - ledleft)); |
50 | } |
50 | } |
51 | 51 | ||
52 | void setLed(uint8_t *animation, uint8_t led, uint8_t bool_clear) { |
52 | void setLed(uint8_t *animation, uint8_t led, uint8_t bool_clear) { |
53 | if (bool_clear) { |
53 | if (bool_clear) { |
54 | clear(); |
54 | clear(); |
55 | } |
55 | } |
56 | setSingleLed(animation, led); |
56 | setSingleLed(animation, led); |
57 | } |
57 | } |
58 | 58 | ||
59 | void setLedsAround(uint8_t *animation, uint8_t center, uint8_t border, uint8_t bool_clear) { |
59 | void setLedsAround(uint8_t *animation, uint8_t center, uint8_t border, uint8_t bool_clear) { |
60 | animation_locked = 1; |
60 | animation_locked = 1; |
61 | if (bool_clear) { |
61 | if (bool_clear) { |
62 | clear(); |
62 | clear(); |
63 | } |
63 | } |
64 | setSingleLed(animation, center); |
64 | setSingleLed(animation, center); |
65 | for (uint8_t b = 1; b <= border; b++) { |
65 | for (uint8_t b = 1; b <= border; b++) { |
66 | setSingleLed(animation, (center + b) % 48); |
66 | setSingleLed(animation, (center + b) % 48); |
67 | setSingleLed(animation, (center + (48 - b)) % 48); |
67 | setSingleLed(animation, (center + (48 - b)) % 48); |
68 | } |
68 | } |
69 | animation_locked = 0; |
69 | animation_locked = 0; |
70 | } |
70 | } |
71 | 71 | ||
72 | void setLeds(uint8_t *animation, uint8_t leds) { |
72 | void setLeds(uint8_t *animation, uint8_t leds) { |
73 | uint8_t segment = leds / 8; |
73 | uint8_t segment = leds / 8; |
74 | for (uint8_t i = 0; i < 6; i++) { |
74 | for (uint8_t i = 0; i < 6; i++) { |
75 | if (i < segment) { |
75 | if (i < segment) { |
76 | animation[i] = 255; |
76 | animation[i] = 255; |
77 | } else if (i == segment) { |
77 | } else if (i == segment) { |
78 | uint8_t ledsleft = (leds - segment * 8); |
78 | uint8_t ledsleft = (leds - segment * 8); |
79 | //animation[i] = ~((uint8_t) (255 >> ledsleft)); |
79 | //animation[i] = ~((uint8_t) (255 >> ledsleft)); |
80 | animation[i] = ~((uint8_t)(255 << ledsleft)); |
80 | animation[i] = ~((uint8_t)(255 << ledsleft)); |
81 | } else { |
81 | } else { |
82 | animation[i] = 0; |
82 | animation[i] = 0; |
83 | } |
83 | } |
84 | } |
84 | } |
85 | } |
85 | } |
86 | 86 | ||
87 | void blinkNumer(uint8_t *animation, uint8_t num, uint8_t times) { |
87 | void blinkNumer(uint8_t *animation, uint8_t num, uint8_t times) { |
88 | for (uint8_t i = 0; i < times; i++) { |
88 | for (uint8_t i = 0; i < times; i++) { |
89 | setLeds(animation, num); |
89 | setLeds(animation, num); |
90 | _delay_ms(150); |
90 | _delay_ms(150); |
91 | setLeds(animation, 0); |
91 | setLeds(animation, 0); |
92 | _delay_ms(100); |
92 | _delay_ms(100); |
93 | } |
93 | } |
94 | } |
94 | } |
95 | 95 |