diff options
| -rw-r--r-- | hwdef-BLF_LT1.h | 4 | ||||
| -rw-r--r-- | hwdef-Emisar_D4Sv2-tintramp.h | 5 | ||||
| -rw-r--r-- | hwdef-Noctigon_KR4-tintramp.h | 46 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/MODELS | 1 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/anduril-manual.txt | 11 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/cfg-blf-lantern.h | 24 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp-fet.h | 24 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h | 15 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/cfg-noctigon-kr4-tintramp.h | 12 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/load-save-config-fsm.h | 1 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/load-save-config.c | 2 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/ramp-mode-fsm.h | 2 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/ramp-mode.c | 11 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/ramp-mode.h | 10 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/tint-ramping.c | 46 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/tint-ramping.h | 8 | ||||
| -rw-r--r-- | spaghetti-monster/fsm-ramping.c | 43 | ||||
| -rw-r--r-- | spaghetti-monster/fsm-ramping.h | 34 |
18 files changed, 218 insertions, 81 deletions
diff --git a/hwdef-BLF_LT1.h b/hwdef-BLF_LT1.h index d0c2821..16e1c90 100644 --- a/hwdef-BLF_LT1.h +++ b/hwdef-BLF_LT1.h @@ -14,7 +14,7 @@ #include <avr/io.h> #define PWM_CHANNELS 1 // 1 virtual channel (1 for main LEDs + 1 for 2nd LEDs) -#define PWM_BITS 8 // 0 to 255 at 15.6 kHz +#define PWM_BITS 9 // 0 to 255 at 15.6 kHz, but goes to 510 for "200%" turbo #define PWM_TOP 255 // dynamic PWM with tint ramping (not supported on attiny85) @@ -25,7 +25,7 @@ // it out to a soft brightness value, in order to handle tint ramping // (this allows smooth thermal regulation to work, and makes things // otherwise simpler and easier) -uint8_t PWM1_LVL; +uint16_t PWM1_LVL; #define PWM1_PIN PB0 // pin 5, warm tint PWM #define TINT1_LVL OCR0A // OCR0A is the output compare register for PB0 diff --git a/hwdef-Emisar_D4Sv2-tintramp.h b/hwdef-Emisar_D4Sv2-tintramp.h index 76f6097..90545f4 100644 --- a/hwdef-Emisar_D4Sv2-tintramp.h +++ b/hwdef-Emisar_D4Sv2-tintramp.h @@ -47,12 +47,15 @@ #define USE_DYN_PWM // dynamic frequency and speed #define PWM_DATATYPE2 uint32_t // only needs 32-bit if ramp values go over 255 +#ifndef SWITCH_PIN #define SWITCH_PIN PA7 // pin 20 #define SWITCH_PCINT PCINT7 // pin 20 pin change interrupt #define SWITCH_PCIE PCIE0 // PCIE1 is for PCINT[7:0] #define SWITCH_PCMSK PCMSK0 // PCMSK1 is for PCINT[7:0] #define SWITCH_PORT PINA // PINA or PINB or PINC +#define SWITCH_PUE PUEA // pullup group A #define PCINT_vect PCINT0_vect // ISR for PCINT[7:0] +#endif // usually PWM1_LVL would be a hardware register, but we need to abstract // it out to a soft brightness value, in order to handle tint ramping @@ -173,7 +176,7 @@ inline void hwdef_setup() { PWM1_TOP = PWM_TOP; // set up e-switch - PUEA = (1 << SWITCH_PIN); // pull-up for e-switch + SWITCH_PUE = (1 << SWITCH_PIN); // pull-up for e-switch SWITCH_PCMSK = (1 << SWITCH_PCINT); // enable pin change interrupt } diff --git a/hwdef-Noctigon_KR4-tintramp.h b/hwdef-Noctigon_KR4-tintramp.h new file mode 100644 index 0000000..3bd57fe --- /dev/null +++ b/hwdef-Noctigon_KR4-tintramp.h @@ -0,0 +1,46 @@ +#ifndef HWDEF_KR4_TINTRAMP_H +#define HWDEF_KR4_TINTRAMP_H + +/* Noctigon KR4 w/ tint ramping + * (same driver as D4Sv2-tintramp, but with the switch on a different pin) + * + * Pin / Name / Function + * 1 PA6 2nd LED PWM (linear) (PWM1B) + * 2 PA5 R: red aux LED (PWM0B) + * 3 PA4 G: green aux LED + * 4 PA3 B: blue aux LED + * 5 PA2 button LED + * 6 PA1 Opamp 2 enable (2nd LEDs) + * 7 PA0 Opamp 1 enable (main LEDs) + * 8 GND GND + * 9 VCC VCC + * 10 PC5 (none) + * 11 PC4 (none) + * 12 PC3 RESET + * 13 PC2 (none) + * 14 PC1 SCK + * 15 PC0 main LED PWM (FET) (PWM0A) (unused on some models because tint ramping) + * 16 PB3 main LED PWM (linear) (PWM1A) + * 17 PB2 MISO / e-switch (PCINT10) + * 18 PB1 MOSI / battery voltage (ADC6) + * 19 PB0 (none) + * 20 PA7 (none) + * ADC12 thermal sensor + */ + +#define ATTINY 1634 +#include <avr/io.h> + +// move the switch to a different pin +#define SWITCH_PIN PB2 // pin 17 +#define SWITCH_PCINT PCINT10 // pin 17 pin change interrupt +#define SWITCH_PCIE PCIE1 // PCIE1 is for PCINT[11:8] +#define SWITCH_PCMSK PCMSK1 // PCMSK1 is for PCINT[11:8] +#define SWITCH_PORT PINB // PINA or PINB or PINC +#define SWITCH_PUE PUEB // pullup group B +#define PCINT_vect PCINT1_vect // ISR for PCINT[11:8] + +// the rest of the config is the same as D4Sv2-tintramp +#include "hwdef-Emisar_D4Sv2-tintramp.h" + +#endif diff --git a/spaghetti-monster/anduril/MODELS b/spaghetti-monster/anduril/MODELS index 317bb6a..c6fe6be 100644 --- a/spaghetti-monster/anduril/MODELS +++ b/spaghetti-monster/anduril/MODELS @@ -20,6 +20,7 @@ Model Name MCU 0212 noctigon-kr4-nofet attiny1634 0213 noctigon-kr4-219 attiny1634 0214 noctigon-kr4-219b attiny1634 +0215 noctigon-kr4-tintramp attiny1634 0251 noctigon-k1 attiny1634 0252 noctigon-k1-sbt90 attiny1634 0253 noctigon-k1-12v attiny1634 diff --git a/spaghetti-monster/anduril/anduril-manual.txt b/spaghetti-monster/anduril/anduril-manual.txt index 009e95e..8d6ad75 100644 --- a/spaghetti-monster/anduril/anduril-manual.txt +++ b/spaghetti-monster/anduril/anduril-manual.txt @@ -692,6 +692,11 @@ Misc Config Menu Some models may have an extra config menu for settings which don't fit anywhere else. These settings are, in order: + - Tint ramp style: + + 0 = smooth (blend channels in any proportion) + 1 = toggle (only one channel active at a time) + - Jump Start level: Some lights are prone to starting up slowly at low levels, so they @@ -728,6 +733,11 @@ be warm white while dim, or cool white while bright. Or vice-versa. To access this, ramp to the end of the tint range, then keep holding until the light blinks a second time. +The misc config menu also has a setting to choose a tint ramp style. +This can be smooth, allowing the user to smoothly blend both channels in +whatever ratio they desire... or it can be "tint toggle" style, where +only one channel is active at a time. + UI Reference Table ------------------ @@ -819,3 +829,4 @@ Config menus Full Hold Skip current item with no changes Config menus Full Release Configure current item Number entry Full Click Add 1 to value for current item +Number entry Full Hold Add 10 to value for current item diff --git a/spaghetti-monster/anduril/cfg-blf-lantern.h b/spaghetti-monster/anduril/cfg-blf-lantern.h index a989ca4..56ed410 100644 --- a/spaghetti-monster/anduril/cfg-blf-lantern.h +++ b/spaghetti-monster/anduril/cfg-blf-lantern.h @@ -19,15 +19,20 @@ // (0 = 100% brightness, 64 = 200% brightness) //#define TINT_RAMPING_CORRECTION 26 // prototype, 140% #define TINT_RAMPING_CORRECTION 10 // production model, 115% +//#define TINT_RAMPING_CORRECTION 0 // none #ifdef RAMP_LENGTH #undef RAMP_LENGTH #endif -// level_calc.py 1 150 7135 1 30 800 +// 1-130: 0 to 100% power +// level_calc.py 3.0 1 130 7135 1 30 800 --pwm 255 +// 131-150: 101% to 200% power +// level_calc.py 8.69 1 150 7135 1 1 1600 --pwm 510 #define RAMP_LENGTH 150 -#define PWM1_LEVELS 1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,11,11,12,13,13,14,15,15,16,17,18,18,19,20,21,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,43,44,45,46,48,49,50,51,53,54,56,57,58,60,61,63,64,66,67,69,70,72,74,75,77,79,80,82,84,85,87,89,91,93,95,97,98,100,102,104,106,108,111,113,115,117,119,121,124,126,128,130,133,135,137,140,142,145,147,150,152,155,157,160,163,165,168,171,173,176,179,182,185,188,190,193,196,199,202,205,209,212,215,218,221,224,228,231,234,238,241,245,248,251,255 -#define MAX_1x7135 65 +#define PWM1_LEVELS 1,1,2,2,3,3,4,5,5,6,6,7,8,8,9,10,10,11,12,12,13,14,15,16,17,17,18,19,20,21,22,23,24,25,26,27,28,29,31,32,33,34,35,37,38,39,40,42,43,45,46,47,49,50,52,54,55,57,58,60,62,63,65,67,69,70,72,74,76,78,80,82,84,86,88,90,92,95,97,99,101,104,106,108,111,113,115,118,121,123,126,128,131,134,136,139,142,145,148,150,153,156,159,162,166,169,172,175,178,181,185,188,191,195,198,202,205,209,213,216,220,224,227,231,235,239,243,247,251,255,264,274,284,294,305,316,327,339,351,363,376,389,403,417,431,446,461,477,493,510 +#define MAX_1x7135 130 +#define DEFAULT_LEVEL 70 #define HALFSPEED_LEVEL 14 #define QUARTERSPEED_LEVEL 5 @@ -40,7 +45,7 @@ // set floor and ceiling as far apart as possible // because this lantern isn't overpowered #define RAMP_SMOOTH_FLOOR 1 -#define RAMP_SMOOTH_CEIL 150 +#define RAMP_SMOOTH_CEIL 130 #define RAMP_DISCRETE_FLOOR 10 #define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL #define RAMP_DISCRETE_STEPS 5 @@ -65,14 +70,15 @@ #undef USE_THERMAL_REGULATION #endif -// don't blink while ramping -#ifdef BLINK_AT_RAMP_MIDDLE -#undef BLINK_AT_RAMP_MIDDLE -#endif +// don't blink at floor #ifdef BLINK_AT_RAMP_FLOOR #undef BLINK_AT_RAMP_FLOOR #endif -// except the top... blink at the top +// blink at 100% power +#ifndef BLINK_AT_RAMP_MIDDLE +#define BLINK_AT_RAMP_MIDDLE +#endif +// blink again at the 200% power / ceil / turbo #ifndef BLINK_AT_RAMP_CEIL #define BLINK_AT_RAMP_CEIL #endif diff --git a/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp-fet.h b/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp-fet.h index 3c638a7..657e25d 100644 --- a/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp-fet.h +++ b/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp-fet.h @@ -14,22 +14,30 @@ // 2nd LEDs // output: unknown, 2000 lm? #define RAMP_LENGTH 150 +///// copy non-FET ramp, but add FET to the top 10 levels from 141 to 150 +/* old // level_calc.py 5.01 1 140 7135 1 0.2 2000 --pwm dyn:69:16383:511 // plus a FET segment -// level_calc.py 2 1 10 7135 5 50.0 3000 --pwm 255 // abstract ramp (power is split between both sets of LEDs) +// level_calc.py 2 1 10 7135 5 50.0 3000 --pwm 255 // append: ,500,482,456,420,374,318,252,178,94,0 -#undef PWM1_LEVELS -#define PWM1_LEVELS 1,1,1,2,2,3,3,4,5,5,6,7,8,9,10,12,13,14,16,18,19,21,23,25,27,30,32,35,37,40,43,45,48,51,54,58,61,64,67,70,74,77,80,83,86,89,92,95,97,99,101,103,105,106,106,107,106,106,104,102,100,96,92,87,81,73,65,56,45,33,35,37,39,41,43,45,47,49,52,54,57,59,62,65,68,71,74,78,81,85,89,92,96,100,105,109,114,118,123,128,133,139,144,150,156,162,168,175,181,188,195,202,210,217,225,233,242,250,259,268,278,287,297,307,318,328,339,351,362,374,386,399,412,425,438,452,466,481,496,511,500,482,456,420,374,318,252,178,94,0 +*/ +/* also old +// level_calc.py 3 1 11 7135 511 2000 5000 --pwm 1022 +// append: 549,589,633,679,728,780,836,894,957,1022 +//#undef PWM1_LEVELS +//#define PWM1_LEVELS 1,1,1,2,2,3,3,4,5,5,6,7,8,9,10,12,13,14,16,18,19,21,23,25,27,30,32,35,37,40,43,45,48,51,54,58,61,64,67,70,74,77,80,83,86,89,92,95,97,99,101,103,105,106,106,107,106,106,104,102,100,96,92,87,81,73,65,56,45,33,35,37,39,41,43,45,47,49,52,54,57,59,62,65,68,71,74,78,81,85,89,92,96,100,105,109,114,118,123,128,133,139,144,150,156,162,168,175,181,188,195,202,210,217,225,233,242,250,259,268,278,287,297,307,318,328,339,351,362,374,386,399,412,425,438,452,466,481,496,511,549,589,633,679,728,780,836,894,957,1022 // append: ,511,511,511,511,511,511,511,511,511,511 -#undef PWM_TOPS -#define PWM_TOPS 16383,13469,10296,14694,10845,14620,11496,13507,14400,11954,12507,12676,12605,12376,12036,12805,12240,11650,11882,11933,11243,11155,10988,10763,10497,10569,10223,10164,9781,9646,9475,9071,8870,8652,8422,8330,8077,7823,7569,7318,7169,6919,6676,6439,6209,5986,5770,5561,5305,5063,4834,4618,4413,4180,3925,3723,3468,3264,3016,2787,2576,2333,2111,1885,1658,1412,1189,968,734,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511 +//#undef PWM_TOPS +//#define PWM_TOPS 16383,13469,10296,14694,10845,14620,11496,13507,14400,11954,12507,12676,12605,12376,12036,12805,12240,11650,11882,11933,11243,11155,10988,10763,10497,10569,10223,10164,9781,9646,9475,9071,8870,8652,8422,8330,8077,7823,7569,7318,7169,6919,6676,6439,6209,5986,5770,5561,5305,5063,4834,4618,4413,4180,3925,3723,3468,3264,3016,2787,2576,2333,2111,1885,1658,1412,1189,968,734,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511 +*/ + // prepend: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, #define PWM2_LEVELS 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,14,27,45,68,96,129,166,208,255 #undef DEFAULT_LEVEL #define DEFAULT_LEVEL 70 #undef MAX_1x7135 -#define MAX_1x7135 140 +#define MAX_1x7135 130 #undef RAMP_SMOOTH_FLOOR #define RAMP_SMOOTH_FLOOR 10 // level 1 is unreliable (?) @@ -53,9 +61,9 @@ // stop panicking at ~2000 lm #undef THERM_FASTER_LEVEL -#define THERM_FASTER_LEVEL 140 +#define THERM_FASTER_LEVEL 130 #undef MIN_THERM_STEPDOWN -#define MIN_THERM_STEPDOWN 70 // should be above highest dyn_pwm level +#define MIN_THERM_STEPDOWN 65 // should be above highest dyn_pwm level // speed up party strobe; the FET is really fast #undef PARTY_STROBE_ONTIME diff --git a/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h b/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h index c170645..3e54dca 100644 --- a/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h +++ b/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h @@ -28,10 +28,13 @@ // 2nd LEDs // output: unknown, 2000 lm? #define RAMP_LENGTH 150 -// level_calc.py 5.01 1 150 7135 1 0.2 2000 --pwm dyn:74:16383:511 // abstract ramp (power is split between both sets of LEDs) -#define PWM1_LEVELS 1,1,1,2,2,2,3,4,4,5,6,6,7,8,9,10,12,13,14,16,17,19,20,22,24,26,28,30,32,35,37,40,42,45,47,50,53,56,59,62,65,68,71,74,77,80,83,86,89,91,94,96,98,100,102,104,105,106,107,107,107,106,105,103,101,98,94,90,84,78,71,63,54,44,33,35,37,38,40,42,44,46,48,50,53,55,57,60,63,65,68,71,74,77,80,83,87,90,94,98,102,106,110,114,118,123,128,132,137,142,148,153,159,164,170,176,183,189,196,202,209,216,224,231,239,247,255,263,272,281,290,299,309,318,328,339,349,360,371,382,394,406,418,430,443,456,469,483,497,511 -#define PWM_TOPS 16383,13673,10738,15435,11908,8123,12779,14756,12240,13447,14013,11907,12263,12351,12261,12048,12926,12464,11972,12278,11704,11789,11180,11134,11013,10837,10620,10371,10100,10113,9793,9718,9376,9248,8898,8738,8560,8369,8168,7961,7749,7535,7321,7107,6895,6686,6480,6278,6080,5823,5639,5403,5178,4965,4763,4570,4346,4134,3936,3714,3507,3283,3074,2853,2648,2433,2211,2006,1776,1564,1351,1137,924,714,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511 +// 1-130: 0 to 100% power +// level_calc.py 5.01 1 130 7135 2 0.2 2000 --pwm dyn:64:16383:511 +// 131 to 150: 101% to 200% power +// level_calc.py 6.44 1 150 7135 1 0.2 2000 --pwm dyn:74:16383:1022 +#define PWM1_LEVELS 2,2,2,3,3,4,4,5,6,7,8,9,10,11,13,14,16,17,19,21,23,25,28,30,33,35,38,41,44,47,50,54,57,60,64,67,71,74,78,81,84,88,91,94,97,99,101,103,105,106,107,107,107,106,105,102,99,95,90,84,77,68,58,47,34,36,38,40,42,44,47,49,52,54,57,60,63,66,69,73,76,80,83,87,91,96,100,104,109,114,119,124,130,135,141,147,153,160,166,173,180,187,195,203,211,219,228,236,245,255,264,274,285,295,306,317,329,340,353,365,378,391,405,419,433,448,463,479,495,511,530,550,570,591,612,634,657,680,705,730,755,782,809,837,865,895,925,957,989,1022 +#define PWM_TOPS 16383,13234,9781,13826,9593,13434,9973,12021,12900,13193,13150,12899,12508,12023,12666,11982,12181,11422,11393,11247,11018,10731,10826,10434,10365,9927,9767,9565,9332,9076,8806,8693,8395,8096,7928,7626,7439,7143,6948,6665,6393,6203,5946,5700,5465,5187,4926,4681,4451,4195,3957,3700,3463,3213,2983,2718,2476,2231,1986,1742,1501,1245,997,756,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511 #define DEFAULT_LEVEL 70 #define MAX_1x7135 150 #define HALFSPEED_LEVEL 10 @@ -54,8 +57,8 @@ #define SIMPLE_UI_STEPS 5 // stop panicking at ~1500 lm -#define THERM_FASTER_LEVEL 140 -#define MIN_THERM_STEPDOWN 75 // should be above highest dyn_pwm level +#define THERM_FASTER_LEVEL 130 +#define MIN_THERM_STEPDOWN 65 // should be above highest dyn_pwm level // use the brightest setting for strobe #define STROBE_BRIGHTNESS MAX_LEVEL @@ -63,7 +66,7 @@ #define PARTY_STROBE_ONTIME 2 // the default of 26 looks a bit flat, so increase it -#define CANDLE_AMPLITUDE 40 +#define CANDLE_AMPLITUDE 33 // the power regulator is a bit slow, so push it harder for a quick response from off #define DEFAULT_JUMP_START_LEVEL 21 diff --git a/spaghetti-monster/anduril/cfg-noctigon-kr4-tintramp.h b/spaghetti-monster/anduril/cfg-noctigon-kr4-tintramp.h new file mode 100644 index 0000000..f19744d --- /dev/null +++ b/spaghetti-monster/anduril/cfg-noctigon-kr4-tintramp.h @@ -0,0 +1,12 @@ +// Noctigon KR4 tint-ramping config options for Anduril +// (basically the same as Emisar D4S V2 tint-ramping, +// but switch on a different pin, and no lighted button) +// ATTINY: 1634 +#include "hwdef-Noctigon_KR4-tintramp.h" +#include "cfg-emisar-d4sv2-tintramp.h" +#undef MODEL_NUMBER +#define MODEL_NUMBER "0215" + +// the button doesn't light up +#undef USE_BUTTON_LED + diff --git a/spaghetti-monster/anduril/load-save-config-fsm.h b/spaghetti-monster/anduril/load-save-config-fsm.h index 894c344..ba3c69b 100644 --- a/spaghetti-monster/anduril/load-save-config-fsm.h +++ b/spaghetti-monster/anduril/load-save-config-fsm.h @@ -60,6 +60,7 @@ typedef enum { #endif #ifdef USE_TINT_RAMPING tint_e, + tint_style_e, #endif #ifdef USE_JUMP_START jump_start_level_e, diff --git a/spaghetti-monster/anduril/load-save-config.c b/spaghetti-monster/anduril/load-save-config.c index ee451ac..4987def 100644 --- a/spaghetti-monster/anduril/load-save-config.c +++ b/spaghetti-monster/anduril/load-save-config.c @@ -62,6 +62,7 @@ void load_config() { #endif #ifdef USE_TINT_RAMPING tint = eeprom[tint_e]; + tint_style = eeprom[tint_style_e]; #endif #ifdef USE_JUMP_START jump_start_level = eeprom[jump_start_level_e], @@ -140,6 +141,7 @@ void save_config() { #endif #ifdef USE_TINT_RAMPING eeprom[tint_e] = tint; + eeprom[tint_style_e] = tint_style; #endif #ifdef USE_JUMP_START eeprom[jump_start_level_e] = jump_start_level, diff --git a/spaghetti-monster/anduril/ramp-mode-fsm.h b/spaghetti-monster/anduril/ramp-mode-fsm.h index 7f67d1e..1a062e9 100644 --- a/spaghetti-monster/anduril/ramp-mode-fsm.h +++ b/spaghetti-monster/anduril/ramp-mode-fsm.h @@ -47,7 +47,7 @@ #endif // include an extra config mode for random stuff which doesn't fit elsewhere -#if defined(USE_JUMP_START) +#if defined(USE_TINT_RAMPING) || defined(USE_JUMP_START) #define USE_GLOBALS_CONFIG #endif diff --git a/spaghetti-monster/anduril/ramp-mode.c b/spaghetti-monster/anduril/ramp-mode.c index ce3f473..6f51f1f 100644 --- a/spaghetti-monster/anduril/ramp-mode.c +++ b/spaghetti-monster/anduril/ramp-mode.c @@ -559,14 +559,21 @@ uint8_t ramp_extras_config_state(Event event, uint16_t arg) { #ifdef USE_GLOBALS_CONFIG void globals_config_save(uint8_t step, uint8_t value) { if (0) {} + #ifdef USE_TINT_RAMPING + else if (step == 1+tint_style_config_step) { + tint_style = !(!(value)); + // set tint to middle or edge depending on style being smooth or toggle + tint = tint_style ? 1 : 127; + } + #endif #ifdef USE_JUMP_START - else { jump_start_level = value; } + else if (step == 1+jump_start_config_step) { jump_start_level = value; } #endif } uint8_t globals_config_state(Event event, uint16_t arg) { // TODO: set number of steps based on how many configurable options - return config_state_base(event, arg, 1, globals_config_save); + return config_state_base(event, arg, globals_config_num_steps, globals_config_save); } #endif diff --git a/spaghetti-monster/anduril/ramp-mode.h b/spaghetti-monster/anduril/ramp-mode.h index bba6d96..93756ab 100644 --- a/spaghetti-monster/anduril/ramp-mode.h +++ b/spaghetti-monster/anduril/ramp-mode.h @@ -224,6 +224,16 @@ uint8_t ramp_stepss[] = { uint8_t ramp_discrete_step_size; // don't set this #ifdef USE_GLOBALS_CONFIG +typedef enum { + #ifdef USE_TINT_RAMPING + tint_style_config_step, + #endif + #ifdef USE_JUMP_START + jump_start_config_step, + #endif + globals_config_num_steps +} globals_config_steps_e; + void globals_config_save(uint8_t step, uint8_t value); uint8_t globals_config_state(Event event, uint16_t arg); #endif diff --git a/spaghetti-monster/anduril/tint-ramping.c b/spaghetti-monster/anduril/tint-ramping.c index aa9b1f6..6cc0616 100644 --- a/spaghetti-monster/anduril/tint-ramping.c +++ b/spaghetti-monster/anduril/tint-ramping.c @@ -22,31 +22,6 @@ #include "tint-ramping.h" -#ifdef TINT_RAMP_TOGGLE_ONLY - -uint8_t tint_ramping_state(Event event, uint16_t arg) { - // click, click, hold: change the tint - if (event == EV_click3_hold) { - // toggle once on first frame; ignore other frames - if (! arg) { - tint = !tint; - set_level(actual_level); - //blink_once(); // unnecessary, and kind of annoying on moon - } - return EVENT_HANDLED; - } - - // click, click, hold, release: save config - else if (event == EV_click3_hold_release) { - // remember tint after battery change - save_config(); - return EVENT_HANDLED; - } - - return EVENT_NOT_HANDLED; -} - -#else // no TINT_RAMP_TOGGLE_ONLY uint8_t tint_ramping_state(Event event, uint16_t arg) { static int8_t tint_ramp_direction = 1; @@ -61,6 +36,21 @@ uint8_t tint_ramping_state(Event event, uint16_t arg) { // click, click, hold: change the tint if (event == EV_click3_hold) { + ///// tint-toggle mode + // toggle once on first frame; ignore other frames + if (tint_style) { + // only respond on first frame + if (arg) return EVENT_NOT_HANDLED; + + // force tint to be 1 or 254 + if (tint != 254) { tint = 1; } + // invert between 1 and 254 + tint = tint ^ 0xFF; + set_level(actual_level); + return EVENT_HANDLED; + } + + ///// smooth tint-ramp mode // reset at beginning of movement if (! arg) { active = 1; // first frame means this is for us @@ -98,8 +88,8 @@ uint8_t tint_ramping_state(Event event, uint16_t arg) { active = 0; // ignore next hold if it wasn't meant for us // reverse tint_ramp_direction = -tint_ramp_direction; - if (tint == 0) tint_ramp_direction = 1; - else if (tint == 255) tint_ramp_direction = -1; + if (tint <= 1) tint_ramp_direction = 1; + else if (tint >= 254) tint_ramp_direction = -1; // remember tint after battery change save_config(); return EVENT_HANDLED; @@ -108,8 +98,6 @@ uint8_t tint_ramping_state(Event event, uint16_t arg) { return EVENT_NOT_HANDLED; } -#endif // ifdef TINT_RAMP_TOGGLE_ONLY - #endif diff --git a/spaghetti-monster/anduril/tint-ramping.h b/spaghetti-monster/anduril/tint-ramping.h index e482999..1c5e22a 100644 --- a/spaghetti-monster/anduril/tint-ramping.h +++ b/spaghetti-monster/anduril/tint-ramping.h @@ -20,6 +20,14 @@ #ifndef TINT_RAMPING_H #define TINT_RAMPING_H +// 0: smooth tint ramp +// 1: toggle tint only between two extremes +#ifdef TINT_RAMP_TOGGLE_ONLY +uint8_t tint_style = 1; +#else +uint8_t tint_style = 0; +#endif + #ifdef USE_MANUAL_MEMORY uint8_t manual_memory_tint; #endif diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index 05c2e0e..49e173f 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -102,6 +102,7 @@ void set_level(uint8_t level) { #endif } else { // enable the power channel, if relevant + #ifndef USE_TINT_RAMPING // update_tint handles this better #ifdef LED_ENABLE_PIN #ifndef LED_ENABLE_PIN_LEVEL_MIN LED_ENABLE_PORT |= (1 << LED_ENABLE_PIN); @@ -117,6 +118,7 @@ void set_level(uint8_t level) { #ifdef LED2_ENABLE_PIN LED2_ENABLE_PORT |= (1 << LED2_ENABLE_PIN); #endif + #endif // ifndef USE_TINT_RAMPING // PWM array index = level - 1 level --; @@ -293,8 +295,14 @@ void update_tint() { // calculate actual PWM levels based on a single-channel ramp // and a global tint value //PWM_DATATYPE brightness = PWM_GET(pwm1_levels, level); - PWM_DATATYPE brightness = PWM1_LVL; - PWM_DATATYPE warm_PWM, cool_PWM; + uint16_t brightness = PWM1_LVL; + uint16_t warm_PWM, cool_PWM; + #ifdef USE_DYN_PWM + uint16_t top = PWM1_TOP; + //uint16_t top = PWM_GET(pwm_tops, actual_level-1); + #else + const uint16_t top = PWM_TOP; + #endif // auto-tint modes uint8_t mytint; @@ -311,29 +319,52 @@ void update_tint() { // stretch 1-254 to fit 0-255 range (hits every value except 98 and 198) else { mytint = (tint * 100 / 99) - 1; } - // middle tints sag, so correct for that effect PWM_DATATYPE2 base_PWM = brightness; - // correction is only necessary when PWM is fast #if defined(TINT_RAMPING_CORRECTION) && (TINT_RAMPING_CORRECTION > 0) + // middle tints sag, so correct for that effect + // by adding extra power which peaks at the middle tint + // (correction is only necessary when PWM is fast) if (level > HALFSPEED_LEVEL) { base_PWM = brightness + ((((PWM_DATATYPE2)brightness) * TINT_RAMPING_CORRECTION / 64) * triangle_wave(mytint) / 255); } + // fade the triangle wave out when above 100% power, + // so it won't go over 200% + if (brightness > top) { + base_PWM -= 2 * ( + ((brightness - top) * TINT_RAMPING_CORRECTION / 64) + * triangle_wave(mytint) / 255 + ); + } + // guarantee no more than 200% power + if (base_PWM > (top << 1)) { base_PWM = top << 1; } #endif cool_PWM = (((PWM_DATATYPE2)mytint * (PWM_DATATYPE2)base_PWM) + 127) / 255; warm_PWM = base_PWM - cool_PWM; + // when running at > 100% power, spill extra over to other channel + if (cool_PWM > top) { + warm_PWM += (cool_PWM - top); + cool_PWM = top; + } else if (warm_PWM > top) { + cool_PWM += (warm_PWM - top); + warm_PWM = top; + } TINT1_LVL = warm_PWM; TINT2_LVL = cool_PWM; // disable the power channel, if relevant #ifdef LED_ENABLE_PIN - if (! warm_PWM) + if (warm_PWM) + LED_ENABLE_PORT |= (1 << LED_ENABLE_PIN); + else LED_ENABLE_PORT &= ~(1 << LED_ENABLE_PIN); #endif #ifdef LED2_ENABLE_PIN - if (! cool_PWM) + if (cool_PWM) + LED2_ENABLE_PORT |= (1 << LED2_ENABLE_PIN); + else LED2_ENABLE_PORT &= ~(1 << LED2_ENABLE_PIN); #endif } diff --git a/spaghetti-monster/fsm-ramping.h b/spaghetti-monster/fsm-ramping.h index c1f6064..de090c2 100644 --- a/spaghetti-monster/fsm-ramping.h +++ b/spaghetti-monster/fsm-ramping.h @@ -48,26 +48,26 @@ void update_tint(); // auto-detect the data type for PWM tables #ifndef PWM_BITS -#define PWM_BITS 8 -#define PWM_TOP 255 + #define PWM_BITS 8 + #define PWM_TOP 255 #endif #if PWM_BITS <= 8 -#define PWM_DATATYPE uint8_t -#define PWM_DATATYPE2 uint16_t -#define PWM_TOP 255 -#define PWM_GET(x,y) pgm_read_byte(x+y) + #define PWM_DATATYPE uint8_t + #define PWM_DATATYPE2 uint16_t + #define PWM_TOP 255 + #define PWM_GET(x,y) pgm_read_byte(x+y) #else -#define PWM_DATATYPE uint16_t -#ifndef PWM_DATATYPE2 -#define PWM_DATATYPE2 uint32_t -#endif -#ifndef PWM_TOP -#define PWM_TOP 1023 // 10 bits by default -#endif -// pointer plus 2*y bytes -//#define PWM_GET(x,y) pgm_read_word(x+(2*y)) -// nope, the compiler was already doing the math correctly -#define PWM_GET(x,y) pgm_read_word(x+y) + #define PWM_DATATYPE uint16_t + #ifndef PWM_DATATYPE2 + #define PWM_DATATYPE2 uint32_t + #endif + #ifndef PWM_TOP + #define PWM_TOP 1023 // 10 bits by default + #endif + // pointer plus 2*y bytes + //#define PWM_GET(x,y) pgm_read_word(x+(2*y)) + // nope, the compiler was already doing the math correctly + #define PWM_GET(x,y) pgm_read_word(x+y) #endif // use UI-defined ramp tables if they exist |
