Subversion Repositories Projects

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/****************************************************************************
 *   Copyright (C) 2011 by Claas Anders "CaScAdE" Rathje                    *
 *   admiralcascade@gmail.com                                               *
 *   Project-URL: http://www.mylifesucks.de/oss/c-epilepsy/                 *
 *                                                                          *
 *   This program is free software; you can redistribute it and/or modify   *
 *   it under the terms of the GNU General Public License as published by   *
 *   the Free Software Foundation; either version 2 of the License.         *
 *                                                                          *
 *   This program is distributed in the hope that it will be useful,        *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 *   GNU General Public License for more details.                           *
 *                                                                          *
 *   You should have received a copy of the GNU General Public License      *
 *   along with this program; if not, write to the                          *
 *   Free Software Foundation, Inc.,                                        *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.              *
 ****************************************************************************/


#include "epi_helpers.h"

// clear anomation

void clear(void) {
    for (uint8_t i = 0; i < 7; i++) {
        animation[i] = 0;
    }
}

/**
 * Display degree on the EPI
 * @param animation the animation array to set the LEDs in
 * @param degree 0-360 degree to set
 */

void degree2epi(uint8_t *animation, uint16_t degree) {
    setLed(animation, (degree * 10) / 75, 1);
}

void setSingleLed(uint8_t *animation, uint8_t led) {
    uint8_t segment = led / 8;
    uint8_t ledleft = (led - segment * 8);
    animation[segment] |= (128 >> (7 - ledleft));
}

void unsetSingleLed(uint8_t *animation, uint8_t led) {
    uint8_t segment = led / 8;
    uint8_t ledleft = (led - segment * 8);
    animation[segment] &= ~(128 >> (7 - ledleft));
}

void setLed(uint8_t *animation, uint8_t led, uint8_t bool_clear) {
    if (bool_clear) {
        clear();
    }
    setSingleLed(animation, led);
}

void setLedsAround(uint8_t *animation, uint8_t center, uint8_t border, uint8_t bool_clear) {
    animation_locked = 1;
    if (bool_clear) {
        clear();
    }
    setSingleLed(animation, center);
    for (uint8_t b = 1; b <= border; b++) {
        setSingleLed(animation, (center + b) % 48);
        setSingleLed(animation, (center + (48 - b)) % 48);
    }
    animation_locked = 0;
}

void setLeds(uint8_t *animation, uint8_t leds) {
    uint8_t segment = leds / 8;
    for (uint8_t i = 0; i < 6; i++) {
        if (i < segment) {
            animation[i] = 255;
        } else if (i == segment) {
            uint8_t ledsleft = (leds - segment * 8);
            //animation[i] = ~((uint8_t) (255 >> ledsleft));
            animation[i] = ~((uint8_t)(255 << ledsleft));
        } else {
            animation[i] = 0;
        }
    }
}

void blinkNumer(uint8_t *animation, uint8_t num, uint8_t times) {
    for (uint8_t i = 0; i < times; i++) {
        setLeds(animation, num);
        _delay_ms(150);
        setLeds(animation, 0);
        _delay_ms(100);
    }
}