3#ifndef __INC_LIB8TION_H
4#define __INC_LIB8TION_H
20#ifndef __INC_LED_SYSDEFS_H
21#error WTH? led_sysdefs needs to be included first
267 return static_cast<sfract15>(f * 32768.0f);
297 uint8_t delta = b - a;
298 uint8_t scaled =
scale8( delta, frac);
301 uint8_t delta = a - b;
302 uint8_t scaled =
scale8( delta, frac);
314 uint16_t delta = b - a;
315 uint16_t scaled =
scale16(delta, frac);
318 uint16_t delta = a - b;
319 uint16_t scaled =
scale16( delta, frac);
331 uint16_t delta = b - a;
335 uint16_t delta = a - b;
348 uint16_t delta = b - a;
352 uint16_t delta = a - b;
365 uint16_t delta = b - a;
366 uint16_t scaled =
scale16( delta, frac);
369 uint16_t delta = a - b;
370 uint16_t scaled =
scale16( delta, frac);
399 uint8_t rangeWidth = rangeEnd - rangeStart;
400 uint8_t out =
scale8( in, rangeWidth);
417#if (EASE8_C == 1) || defined(FASTLED_DOXYGEN)
424 uint8_t jj =
scale8( j, j);
425 uint8_t jj2 = jj << 1;
432#elif EASE8_AVRASM == 1
449 "clr __zero_reg__ \n"
458#error "No implementation for ease8InOutQuad available."
472 uint16_t jj2 = jj << 1;
492 uint32_t r1 = (3 * ii) - (2 * iii);
509 uint16_t r1 = (3 * (uint16_t)(ii)) - ( 2 * (uint16_t)(iii));
532#if (EASE8_C == 1) || defined(FASTLED_DOXYGEN)
538 }
else if( i > (255 - 64)) {
553#elif EASE8_AVRASM == 1
558 " subi %[i], 64 \n\t"
559 " cpi %[i], 128 \n\t"
560 " brcc Lshift_%= \n\t"
563 " mov __tmp_reg__, %[i] \n\t"
564 " lsr __tmp_reg__ \n\t"
565 " add %[i], __tmp_reg__ \n\t"
566 " subi %[i], 224 \n\t"
567 " rjmp Ldone_%= \n\t"
572 " subi %[i], 96 \n\t"
583#error "No implementation for ease8 available."
613 uint8_t out = in << 1;
666 if( in < pulsewidth || (pulsewidth == 255)) {
685#if ((defined(ARDUINO) || defined(SPARK) || defined(FASTLED_HAS_MILLIS)) && !defined(USE_GET_MILLISECOND_TIMER)) || defined(FASTLED_DOXYGEN)
699#define GET_MILLIS millis
701uint32_t get_millisecond_timer();
702#define GET_MILLIS get_millisecond_timer
769 return (((
GET_MILLIS()) - timebase) * beats_per_minute_88 * 280) >> 16;
778 if( beats_per_minute < 256) beats_per_minute <<= 8;
779 return beat88(beats_per_minute, timebase);
787 return beat16( beats_per_minute, timebase) >> 8;
802 uint32_t timebase = 0, uint16_t phase_offset = 0)
804 uint16_t beat =
beat88( beats_per_minute_88, timebase);
805 uint16_t beatsin = (
sin16( beat + phase_offset) + 32768);
806 uint16_t rangewidth = highest - lowest;
807 uint16_t scaledbeat =
scale16( beatsin, rangewidth);
808 uint16_t result = lowest + scaledbeat;
820 uint32_t timebase = 0, uint16_t phase_offset = 0)
822 uint16_t beat =
beat16( beats_per_minute, timebase);
823 uint16_t beatsin = (
sin16( beat + phase_offset) + 32768);
824 uint16_t rangewidth = highest - lowest;
825 uint16_t scaledbeat =
scale16( beatsin, rangewidth);
826 uint16_t result = lowest + scaledbeat;
838 uint32_t timebase = 0, uint8_t phase_offset = 0)
840 uint8_t beat =
beat8( beats_per_minute, timebase);
841 uint8_t beatsin =
sin8( beat + phase_offset);
842 uint8_t rangewidth = highest - lowest;
843 uint8_t scaledbeat =
scale8( beatsin, rangewidth);
844 uint8_t result = lowest + scaledbeat;
874 m16 = (ms / (60000L)) & 0xFFFF;
884 h8 = (ms / (3600000L)) & 0xFF;
913 " mov %B[out],%C[in] \n\t"
914 " mov %A[out],%B[in] \n\t"
919 out16 = (in32 >> 10) & 0xFFFF;
939#define INSTANTIATE_EVERY_N_TIME_PERIODS(NAME,TIMETYPE,TIMEGETTER) \
942 TIMETYPE mPrevTrigger; \
945 NAME() { reset(); mPeriod = 1; }; \
946 NAME(TIMETYPE period) { reset(); setPeriod(period); }; \
947 void setPeriod( TIMETYPE period) { mPeriod = period; }; \
948 TIMETYPE getTime() { return (TIMETYPE)(TIMEGETTER()); }; \
949 TIMETYPE getPeriod() { return mPeriod; }; \
950 TIMETYPE getElapsed() { return getTime() - mPrevTrigger; } \
951 TIMETYPE getRemaining() { return mPeriod - getElapsed(); } \
952 TIMETYPE getLastTriggerTime() { return mPrevTrigger; } \
954 bool isReady = (getElapsed() >= mPeriod); \
955 if( isReady ) { reset(); } \
958 void reset() { mPrevTrigger = getTime(); }; \
959 void trigger() { mPrevTrigger = getTime() - mPeriod; }; \
961 operator bool() { return ready(); } \
969#if defined(FASTLED_DOXYGEN)
997 TIMETYPE
getTime() {
return (TIMETYPE)(TIMEGETTER()); };
1014 if( isReady ) {
reset(); }
1045#define CEveryNMilliseconds CEveryNMillis
1061 if( isReady ) {
reset(); }
1122template<
typename timeType,timeType (*timeGetter)()>
1123class CEveryNTimePeriods {
1125 timeType mPrevTrigger;
1128 CEveryNTimePeriods() { reset(); mPeriod = 1; };
1129 CEveryNTimePeriods(timeType period) { reset(); setPeriod(period); };
1130 void setPeriod( timeType period) { mPeriod = period; };
1131 timeType getTime() {
return (timeType)(timeGetter()); };
1132 timeType getPeriod() {
return mPeriod; };
1133 timeType getElapsed() {
return getTime() - mPrevTrigger; }
1134 timeType getRemaining() {
return mPeriod - getElapsed(); }
1135 timeType getLastTriggerTime() {
return mPrevTrigger; }
1137 bool isReady = (getElapsed() >= mPeriod);
1138 if( isReady ) { reset(); }
1141 void reset() { mPrevTrigger = getTime(); };
1142 void trigger() { mPrevTrigger = getTime() - mPeriod; };
1144 operator bool() {
return ready(); }
1146typedef CEveryNTimePeriods<uint16_t,seconds16> CEveryNSeconds;
1147typedef CEveryNTimePeriods<uint16_t,bseconds16> CEveryNBSeconds;
1148typedef CEveryNTimePeriods<uint32_t,millis> CEveryNMillis;
1149typedef CEveryNTimePeriods<uint16_t,minutes16> CEveryNMinutes;
1150typedef CEveryNTimePeriods<uint8_t,hours8> CEveryNHours;
1170#define CONCAT_HELPER( x, y ) x##y
1171#define CONCAT_MACRO( x, y ) CONCAT_HELPER( x, y )
1177#define EVERY_N_MILLIS(N) EVERY_N_MILLIS_I(CONCAT_MACRO(PER, __COUNTER__ ),N)
1181#define EVERY_N_MILLIS_I(NAME,N) static CEveryNMillis NAME(N); if( NAME )
1186#define EVERY_N_SECONDS(N) EVERY_N_SECONDS_I(CONCAT_MACRO(PER, __COUNTER__ ),N)
1190#define EVERY_N_SECONDS_I(NAME,N) static CEveryNSeconds NAME(N); if( NAME )
1195#define EVERY_N_BSECONDS(N) EVERY_N_BSECONDS_I(CONCAT_MACRO(PER, __COUNTER__ ),N)
1199#define EVERY_N_BSECONDS_I(NAME,N) static CEveryNBSeconds NAME(N); if( NAME )
1204#define EVERY_N_MINUTES(N) EVERY_N_MINUTES_I(CONCAT_MACRO(PER, __COUNTER__ ),N)
1208#define EVERY_N_MINUTES_I(NAME,N) static CEveryNMinutes NAME(N); if( NAME )
1213#define EVERY_N_HOURS(N) EVERY_N_HOURS_I(CONCAT_MACRO(PER, __COUNTER__ ),N)
1217#define EVERY_N_HOURS_I(NAME,N) static CEveryNHours NAME(N); if( NAME )
1221#define EVERY_N_MILLISECONDS(N) EVERY_N_MILLIS(N)
1223#define EVERY_N_MILLISECONDS_I(NAME,N) EVERY_N_MILLIS_I(NAME,N)
1226#define EVERY_N_MILLISECONDS_DYNAMIC(PERIOD_FUNC) EVERY_N_MILLISECONDS_DYNAMIC_I(CONCAT_MACRO(__dynamic_millis_timer, __COUNTER__ ), (PERIOD_FUNC))
1229#define EVERY_N_MILLISECONDS_DYNAMIC_I(NAME, PERIOD_FUNC) \
1230 static CEveryNMillisDynamic NAME(1); \
1231 NAME.setPeriod(PERIOD_FUNC); \
1235#define EVERY_N_MILLISECONDS_RANDOM(MIN, MAX) \
1236 EVERY_N_MILLISECONDS_RANDOM_I( \
1237 CONCAT_MACRO(_permRand, __COUNTER__), MIN, MAX)
1239#define EVERY_N_MILLISECONDS_RANDOM_I(NAME, MIN, MAX) \
1240 static CEveryNMillisRandom NAME(MIN, MAX); \
1249#ifdef FASTLED_DOXYGEN
1253#define USE_GET_MILLISECOND_TIMER
central include file for FastLED, defines the CFastLED class/object
void setPeriod(uint32_t period)
uint32_t getLastTriggerTime()
uint32_t getPeriod() const
CEveryNMillisDynamic(uint32_t period)
CEveryNMillisRandom(uint32_t minPeriod, uint32_t maxPeriod)
void trigger()
Reset the timestamp so it is ready() on next call.
TIMETYPE mPeriod
Timing interval to check.
CEveryNTime(TIMETYPE period)
Constructor.
TIMETYPE getLastTriggerTime()
Get the timestamp of the most recent trigger event.
CEveryNTime()
Default constructor.
TIMETYPE getTime()
Get the current time according to the class' timekeeper.
TIMETYPE getElapsed()
Get the time elapsed since the last trigger event.
void setPeriod(TIMETYPE period)
Set the time interval between triggers.
bool ready()
Check if the time interval has elapsed.
void reset()
Reset the timestamp to the current time.
TIMETYPE getPeriod()
Get the time interval between triggers.
TIMETYPE mPrevTrigger
Timestamp of the last time the class was "ready".
TIMETYPE getRemaining()
Get the time until the next trigger event.
#define FL_DISABLE_WARNING_RETURN_TYPE
#define FL_DISABLE_WARNING_IMPLICIT_INT_CONVERSION
#define FL_DISABLE_WARNING_PUSH
#define FL_DISABLE_WARNING_SIGN_CONVERSION
#define FL_DISABLE_WARNING_POP
#define FL_DISABLE_WARNING_UNUSED_PARAMETER
#define FL_DISABLE_WARNING_FLOAT_CONVERSION
UIButton trigger("Trigger")
LIB8STATIC uint8_t beat8(accum88 beats_per_minute, uint32_t timebase=0)
Generates an 8-bit "sawtooth" wave at a given BPM.
LIB8STATIC uint16_t beat88(accum88 beats_per_minute_88, uint32_t timebase=0)
Generates a 16-bit "sawtooth" wave at a given BPM, with BPM specified in Q8.8 fixed-point format.
LIB8STATIC uint16_t beatsin16(accum88 beats_per_minute, uint16_t lowest=0, uint16_t highest=65535, uint32_t timebase=0, uint16_t phase_offset=0)
Generates a 16-bit sine wave at a given BPM that oscillates within a given range.
LIB8STATIC uint16_t beat16(accum88 beats_per_minute, uint32_t timebase=0)
Generates a 16-bit "sawtooth" wave at a given BPM.
LIB8STATIC uint8_t beatsin8(accum88 beats_per_minute, uint8_t lowest=0, uint8_t highest=255, uint32_t timebase=0, uint8_t phase_offset=0)
Generates an 8-bit sine wave at a given BPM that oscillates within a given range.
LIB8STATIC uint16_t beatsin88(accum88 beats_per_minute_88, uint16_t lowest=0, uint16_t highest=65535, uint32_t timebase=0, uint16_t phase_offset=0)
Generates a 16-bit sine wave at a given BPM that oscillates within a given range.
LIB8STATIC uint16_t ease16InOutQuad(uint16_t i)
LIB8STATIC uint16_t ease16InOutCubic(uint16_t i)
LIB8STATIC fract8 ease8InOutApprox(fract8 i)
Fast, rough 8-bit ease-in/ease-out function.
LIB8STATIC uint8_t ease8InOutQuad(uint8_t i)
8-bit quadratic ease-in / ease-out function.
LIB8STATIC fract8 ease8InOutCubic(fract8 i)
8-bit cubic ease-in / ease-out function.
LIB8STATIC sfract15 floatToSfract15(float f)
Conversion from IEEE754 float in the range (-1,1) to 16-bit fixed point (sfract15).
LIB8STATIC float sfract15ToFloat(sfract15 y)
Conversion from 16-bit fixed point (sfract15) to IEEE754 32-bit float.
LIB8STATIC uint8_t lerp8by8(uint8_t a, uint8_t b, fract8 frac)
Linear interpolation between two unsigned 8-bit values, with 8-bit fraction.
LIB8STATIC uint16_t lerp16by16(uint16_t a, uint16_t b, fract16 frac)
Linear interpolation between two unsigned 16-bit values, with 16-bit fraction.
LIB8STATIC uint16_t lerp16by8(uint16_t a, uint16_t b, fract8 frac)
Linear interpolation between two unsigned 16-bit values, with 8-bit fraction.
LIB8STATIC int16_t lerp15by8(int16_t a, int16_t b, fract8 frac)
Linear interpolation between two signed 15-bit values, with 8-bit fraction.
LIB8STATIC int16_t lerp15by16(int16_t a, int16_t b, fract16 frac)
Linear interpolation between two signed 15-bit values, with 8-bit fraction.
LIB8STATIC uint8_t map8(uint8_t in, uint8_t rangeStart, uint8_t rangeEnd)
Map from one full-range 8-bit value into a narrower range of 8-bit values, possibly a range of hues.
LIB8STATIC uint16_t random16()
Generate a 16-bit random number.
LIB8STATIC_ALWAYS_INLINE uint8_t scale8_LEAVING_R1_DIRTY(uint8_t i, fract8 scale)
This version of scale8() does not clean up the R1 register on AVR.
LIB8STATIC uint16_t scale16(uint16_t i, fract16 scale)
Scale a 16-bit unsigned value by an 16-bit value, which is treated as the numerator of a fraction who...
LIB8STATIC_ALWAYS_INLINE uint16_t scale16by8(uint16_t i, fract8 scale)
Scale a 16-bit unsigned value by an 8-bit value, which is treated as the numerator of a fraction whos...
LIB8STATIC_ALWAYS_INLINE uint8_t scale8(uint8_t i, fract8 scale)
Scale one byte by a second one, which is treated as the numerator of a fraction whose denominator is ...
#define INSTANTIATE_EVERY_N_TIME_PERIODS(NAME, TIMETYPE, TIMEGETTER)
Preprocessor-based class "template" for CEveryNTime, used with EVERY_N_TIME timekeepers.
LIB8STATIC uint16_t minutes16()
Return the current minutes since boot in a 16-bit value.
LIB8STATIC uint16_t bseconds16()
Returns the current time-since-boot in "binary seconds", which are actually 1024/1000 of a second lon...
#define GET_MILLIS
The a number of functions need access to a millisecond counter in order to keep time.
LIB8STATIC uint16_t div1024_32_16(uint32_t in32)
Helper routine to divide a 32-bit value by 1024, returning only the low 16 bits.
LIB8STATIC uint8_t hours8()
Return the current hours since boot in an 8-bit value.
LIB8STATIC uint16_t seconds16()
Return the current seconds since boot in a 16-bit value.
#define sin16
Platform-independent alias of the fast sin implementation.
#define sin8
Platform-independent alias of the fast sin implementation.
#define LIB8STATIC
Define a LIB8TION member function as static inline with an "unused" attribute.
Defines static inlining macros for lib8tion functions.
Defines fractional types used for lib8tion functions.
Fast, efficient 8-bit math functions specifically designed for high-performance LED programming.
#define FASTLED_NAMESPACE_END
#define FASTLED_NAMESPACE_BEGIN
i16 sfract15
ANSI: signed _Fract.
u8 fract8
Fixed-Point Fractional Types.
u16 accum88
ANSI: unsigned short _Accum. 8 bits int, 8 bits fraction.
u16 fract16
ANSI: unsigned _Fract.
Fast, efficient random number generators specifically designed for high-performance LED programming.
Fast, efficient 8-bit scaling functions specifically designed for high-performance LED programming.
Fast, efficient 8-bit trigonometry functions specifically designed for high-performance LED programmi...