diff options
-rw-r--r-- | common/lightbar.c | 47 |
1 files changed, 19 insertions, 28 deletions
diff --git a/common/lightbar.c b/common/lightbar.c index 6538e04668..12ff8baa88 100644 --- a/common/lightbar.c +++ b/common/lightbar.c @@ -283,41 +283,32 @@ void demo_tap(void) #define F(x) (x * FP_SCALE) static const int _ramp_table[] = { - F(0.000000), F(0.000151), F(0.000602), F(0.001355), F(0.002408), - F(0.003760), F(0.005412), F(0.007361), F(0.009607), F(0.012149), - F(0.014984), F(0.018112), F(0.021530), F(0.025236), F(0.029228), - F(0.033504), F(0.038060), F(0.042895), F(0.048005), F(0.053388), - F(0.059039), F(0.064957), F(0.071136), F(0.077573), F(0.084265), - F(0.091208), F(0.098396), F(0.105827), F(0.113495), F(0.121396), - F(0.129524), F(0.137876), F(0.146447), F(0.155230), F(0.164221), - F(0.173414), F(0.182803), F(0.192384), F(0.202150), F(0.212096), - F(0.222215), F(0.232501), F(0.242949), F(0.253551), F(0.264302), - F(0.275194), F(0.286222), F(0.297379), F(0.308658), F(0.320052), - F(0.331555), F(0.343159), F(0.354858), F(0.366644), F(0.378510), - F(0.390449), F(0.402455), F(0.414519), F(0.426635), F(0.438795), - F(0.450991), F(0.463218), F(0.475466), F(0.487729), F(0.500000), - F(0.512271), F(0.524534), F(0.536782), F(0.549009), F(0.561205), - F(0.573365), F(0.585481), F(0.597545), F(0.609551), F(0.621490), - F(0.633356), F(0.645142), F(0.656841), F(0.668445), F(0.679947), - F(0.691342), F(0.702621), F(0.713778), F(0.724806), F(0.735698), - F(0.746449), F(0.757051), F(0.767499), F(0.777785), F(0.787904), - F(0.797850), F(0.807616), F(0.817197), F(0.826586), F(0.835780), - F(0.844770), F(0.853553), F(0.862124), F(0.870476), F(0.878604), - F(0.886505), F(0.894173), F(0.901604), F(0.908792), F(0.915735), - F(0.922427), F(0.928864), F(0.935044), F(0.940961), F(0.946612), - F(0.951995), F(0.957105), F(0.961940), F(0.966496), F(0.970772), - F(0.974764), F(0.978470), F(0.981888), F(0.985016), F(0.987851), - F(0.990393), F(0.992639), F(0.994588), F(0.996240), F(0.997592), - F(0.998645), F(0.999398), F(0.999849), F(1.000000), + F(0.000000), F(0.002408), F(0.009607), F(0.021530), F(0.038060), + F(0.059039), F(0.084265), F(0.113495), F(0.146447), F(0.182803), + F(0.222215), F(0.264302), F(0.308658), F(0.354858), F(0.402455), + F(0.450991), F(0.500000), F(0.549009), F(0.597545), F(0.645142), + F(0.691342), F(0.735698), F(0.777785), F(0.817197), F(0.853553), + F(0.886505), F(0.915735), F(0.940961), F(0.961940), F(0.978470), + F(0.990393), F(0.997592), F(1.000000), }; #undef F - /* This function provides a smooth ramp up from 0.0 to 1.0 and back to 0.0, * for input from 0x00 to 0xff. */ static inline int cycle_010(uint8_t i) { - return i < 128 ? _ramp_table[i] : _ramp_table[256-i]; + uint8_t bucket, index; + + if (i == 128) + return FP_SCALE; + else if (i > 128) + i = 256 - i; + + bucket = i >> 2; + index = i & 0x3; + + return _ramp_table[bucket] + + ((_ramp_table[bucket + 1] - _ramp_table[bucket]) * index >> 2); } /* This function provides a smooth oscillation between -0.5 and +0.5. |