Subversion Repositories Projects

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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