00001 /* Copyright (c) 2009 by Alex Leone <acleone ~AT~ gmail.com> 00002 00003 This file is part of the Arduino TLC5940 Library. 00004 00005 The Arduino TLC5940 Library is free software: you can redistribute it 00006 and/or modify it under the terms of the GNU General Public License as 00007 published by the Free Software Foundation, either version 3 of the 00008 License, or (at your option) any later version. 00009 00010 The Arduino TLC5940 Library is distributed in the hope that it will be 00011 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with The Arduino TLC5940 Library. If not, see 00017 <http://www.gnu.org/licenses/>. */ 00018 00019 #ifndef TLC_ANIMATIONS_H 00020 #define TLC_ANIMATIONS_H 00021 00025 #include <avr/pgmspace.h> 00026 #include <avr/io.h> 00027 00028 #include "tlc_config.h" 00029 #include "Tlc5940.h" 00030 #include "tlc_progmem_utils.h" 00031 00033 prog_uint8_t *tlc_currentAnimation; 00035 volatile uint16_t tlc_animationFrames; 00037 volatile uint16_t tlc_animationPeriodsPerFrame; 00039 volatile uint16_t tlc_animationPeriodsWait; 00040 00041 volatile void tlc_animationXLATCallback(void); 00042 void tlc_playAnimation(prog_uint8_t *animation, uint16_t frames, uint16_t periodsPerFrame); 00043 00048 /* @{ */ 00049 00058 void tlc_playAnimation(prog_uint8_t *animation, uint16_t frames, uint16_t periodsPerFrame) 00059 { 00060 tlc_currentAnimation = animation; 00061 tlc_animationFrames = frames; 00062 tlc_animationPeriodsPerFrame = periodsPerFrame; 00063 tlc_animationPeriodsWait = 0; 00064 tlc_onUpdateFinished = tlc_animationXLATCallback; 00065 tlc_animationXLATCallback(); 00066 } 00067 00069 volatile void tlc_animationXLATCallback(void) 00070 { 00071 if (tlc_animationPeriodsWait) { 00072 tlc_animationPeriodsWait--; 00073 set_XLAT_interrupt(); 00074 } else { 00075 if (tlc_animationFrames) { 00076 tlc_setGSfromProgmem(tlc_currentAnimation + 00077 (--tlc_animationFrames * NUM_TLCS * 24)); 00078 tlc_animationPeriodsWait = tlc_animationPeriodsPerFrame; 00079 Tlc.update(); 00080 } else { // animation is done 00081 tlc_onUpdateFinished = 0; 00082 } 00083 } 00084 } 00085 00086 /* @} */ 00087 00088 #endif