58
58
* The higher values reduce parasitic drain - important for e-switch lights.
61
#define FIRMWARE_VERS (10) // v1.0 (in 10ths)
61
#define FIRMWARE_VERS (12) // v1.2 (in 10ths)
63
63
#define FET_7135_LAYOUT
66
//-----------------------------------------------------------------------------
67
// SETUPS Header File defined here:
68
//-----------------------------------------------------------------------------
69
//#include "setups_2C2S.h"
70
//#include "setups_GTBuck.h"
71
#include "setups_Q8_2C1S.h"
72
//#include "setups_3C1S.h"
73
//#include "setups_3C2S.h"
68
75
#if OUT_CHANNELS == 3
69
76
#ifdef VOLT_MON_R1R2
76
83
#include "RegisterSettings.h"
81
// Ignore a spurious warning, we did the cast on purpose
82
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
88
// Ignore a spurious warning, we did the cast on purpose
89
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
84
91
#include <avr/pgmspace.h>
85
92
#include <avr/io.h>
91
98
//#include <avr/power.h>
94
#define F_CPU 8000000UL // 8 Mhz
95
#define BOGOMIPS (F_CPU/4000) // set to 2000 for 8 Mhz
101
#define F_CPU 8000000UL // 8 Mhz
102
#define BOGOMIPS (F_CPU/4000) // set to 2000 for 8 Mhz
96
103
#define OWN_DELAY // Don't use stock delay functions.
97
104
#define USE_DELAY_S // Also use _delay_s(), not just _delay_ms()
99
106
#include "tk-delay.h"
100
107
#include "tk-random.h"
102
#include "tk-calibWight.h" // use this for the BLF Q8 driver (and wight drivers)
103
//#include "tk-calibMTN17DDm.h" // use this for the MtnE MTN17DDm v1.1 driver
109
// Comment out all tk-calib headers if not using R1/R2 (for example: for the BLF Q8)
110
//#include "tk-calibGT.h" // use this for the GT-buck driver
111
//#include "tk-calibWight.h" // use this for the wight style drivers using external R1/R2's
112
//#include "tk-calibMTN17DDm.h" // use this for the MtnE MTN17DDm v1.1 driver with external R1/R2
115
//#include "RampingTables_HiPerf.h" // for very high performance, high output custom mods
116
//#include "ModeSets_HiPerf.h" // for very high performance, high output custom mods
106
117
#include "RampingTables.h"
107
118
#include "ModeSets.h"
123
134
// Config Settings via UI, with default values:
124
135
//----------------------------------------------------------------
125
136
volatile byte ramping; // 1: ramping mode in effect, 0: mode sets
126
#if USING_3807135_BANK
137
#if USING_3807135_BANK
127
138
volatile byte moonlightLevel; // 0..7, 0: disabled, usually set to 3 (350 mA) or 5 (380 mA) - 2 might work on a 350 mA
129
140
volatile byte moonlightLevel; // 0..7, 0: disabled, usually set to 3 (350 mA) or 5 (380 mA) - 2 might work on a 350 mA
142
153
//----------------------------------------------------------------
144
155
volatile byte OffTimeEnable = OFFTIME_ENABLE; // 1: Do OFF time mode memory for Mode Sets on power switching (tailswitch), 0: disabled
156
volatile byte momentaryState = 0; // 1: momentary mode in effect, 0: ramping or mode sets
148
#define MAX_RAMP_LEVEL (RAMP_SIZE)
160
#define MAX_RAMP_LEVEL (RAMP_SIZE)
162
#ifdef TURBO_LEVEL_SUPPORT
163
#define TURBO_LEVEL (MAX_RAMP_LEVEL+1)
165
#define TURBO_LEVEL (MAX_RAMP_LEVEL)
150
169
volatile byte rampingLevel = 0; // 0=OFF, 1..MAX_RAMP_LEVEL is the ramping table index, 255=moon mode
151
170
byte rampState = 0; // 0=OFF, 1=in lowest mode (moon) delay, 2=ramping Up, 3=Ramping Down, 4=ramping completed (Up or Dn)
205
224
// in calib, use it to timeout a click response
206
225
byte byStepdownTemp = DEFAULT_STEPDOWN_TEMP; // the current temperature in C for doing the stepdown
208
byte byBlinkActiveChan = 0; // schedule a onboard LED blink to occur for showing the active channel
227
byte byBlinkActiveChan = 0; // schedule a onboard LED blink to occur for showing the active channel
211
230
// Configuration settings storage in EEPROM
212
231
word eepos = 0; // (0..n) position of mode/settings stored in EEPROM (128/256/512)
417
443
if (BlinkCnt > 5)
420
// Flash 'n' times before lowering
421
while (BlinkCnt-- > 0)
423
SetOutput(OFF_OUTPUT);
446
// Flash 'n' times before lowering
447
while (BlinkCnt-- > 0)
449
SetOutput(OFF_OUTPUT);
426
452
#ifdef ONBOARD_LED
434
460
#if OUT_CHANNELS == 3 // Triple Channel
435
SetOutput(currOutLvl1, currOutLvl2, currOutLvl3);
461
SetOutput(currOutLvl1, currOutLvl2, currOutLvl3);
436
462
#elif OUT_CHANNELS == 2 // two channels
437
SetOutput(currOutLvl1, currOutLvl2);
439
SetOutput(currOutLvl);
463
SetOutput(currOutLvl1, currOutLvl2);
465
SetOutput(currOutLvl);
444
470
#ifdef ONBOARD_LED
450
476
#ifdef ONBOARD_LED
483
509
**************************************************************************************/
484
510
inline static void ClickBlink()
486
#if OUT_CHANNELS == 3 // Triple Channel
488
#elif OUT_CHANNELS == 2 // two channels
512
SetOutput(CLICK_BRIGHTNESS);
494
514
SetOutput(OFF_OUTPUT);
497
/**************************************************************************************
498
* BlinkActiveChannel - blink 1 or 2 times to show which of 2 output channels is
499
* active. Only the Ind. LED is used.
500
**************************************************************************************/
501
inline static void BlinkActiveChannel()
517
/**************************************************************************************
518
* BlinkActiveChannel - blink 1 or 2 times to show which of 2 output channels is
519
* active. Only the Ind. LED is used.
520
**************************************************************************************/
521
inline static void BlinkActiveChannel()
503
523
#ifdef ONBOARD_LED
506
if (outLevel == 0) // if invalid, bail. outLevel should be 1..RAMP_SIZE or 255
509
#if OUT_CHANNELS == 2
510
if ((outLevel >= FET_START_LVL) && (outLevel < 255)) // 255 is special value for moon mode (use 1)
514
#if OUT_CHANNELS == 3
515
if (outLevel < BANK_START_LVL)
517
else if (outLevel < FET_START_LVL)
519
else if (outLevel < 255) // 255 is special value for moon mode (use 1)
523
_delay_ms(300); // delay initially so a button LED can be seen
526
if (outLevel == 0) // if invalid, bail. outLevel should be 1..RAMP_SIZE or 255
529
#if OUT_CHANNELS == 2
530
if ((outLevel >= FET_START_LVL) && (outLevel < 255)) // 255 is special value for moon mode (use 1)
534
#if OUT_CHANNELS == 3
535
if (outLevel < BANK_START_LVL)
537
else if (outLevel < FET_START_LVL)
539
else if (outLevel < 255) // 255 is special value for moon mode (use 1)
543
_delay_ms(300); // delay initially so a button LED can be seen
535
555
/**************************************************************************************
536
556
* IsPressed - debounce the switch release, not the switch press
632
652
cli(); // Disable interrupts
633
653
wdt_reset(); // Reset the WDT
634
654
WDTCR |= (1<<WDCE) | (1<<WDE); // Start timed sequence
635
WDTCR = (1<<WDIE); // Enable interrupt every 16ms (was 1<<WDTIE)
655
WDTCR = (1<<WDIE); // Enable interrupt every 16ms (was 1<<WDTIE)
636
656
sei(); // Enable interrupts
663
683
ADMUX = ADCMUX_VCC_INTREF; // not left-adjust, Vbg
665
DIDR0 |= (1 << ADC1D); // disable digital input on ADC1 pin to reduce power consumption
666
ADCSRA = (1 << ADEN ) | (1 << ADSC ) | 0x07;// enable, start, ADC clock prescale = 128 for 62.5 kHz
685
DIDR0 |= (1 << ADC1D); // disable digital input on ADC1 pin to reduce power consumption
686
ADCSRA = (1 << ADEN ) | (1 << ADSC ) | 0x07;// enable, start, ADC clock prescale = 128 for 62.5 kHz
669
689
/**************************************************************************************
706
726
//-----------------------------------------
708
sleep_bod_disable(); // try to disable Brown-Out Detection to reduce parasitic drain
728
sleep_bod_disable(); // try to disable Brown-Out Detection to reduce parasitic drain
709
729
sleep_cpu(); // go to sleepy beddy bye
711
731
//-----------------------------------------
831
851
byte oldpos = eepos;
833
eepos = (eepos+4) & 127; // wear leveling, use next cell
853
eepos = (eepos+4) & 127; // wear leveling, use next cell
835
855
// Write the current settings (3 bytes)
836
856
WrEEPROM (eepos, config1);
874
894
#ifdef VOLT_MON_R1R2
875
895
byVoltage = (byte)(wAdcVal >> 2); // convert to 8 bits, throw away 2 LSB's
877
// Read cell voltage, applying the
897
// Read cell voltage, applying the equation
878
898
wAdcVal = (11264 + (wAdcVal >> 1))/wAdcVal + D1_DIODE; // in volts * 10: 10 * 1.1 * 1024 / ADC + D1_DIODE, rounded
879
899
if (byVoltage > 0)
932
952
static word wStepdownTicks = 0;
933
953
static byte byModeForClicks = 0;
954
static byte initialLevelForClicks = 0;
955
static byte turboRestoreLevel = 0;
935
957
#ifdef VOLTAGE_MON
936
958
static word wLowBattBlinkTicks = 0;
962
984
//---------------------------------------------------------------------------------------
963
985
// Handle "button stuck" safety timeout
964
986
//---------------------------------------------------------------------------------------
965
if (wPressDuration == 1250) // 20 seconds
987
if ((wPressDuration == 1250) && !momentaryState) // 20 seconds
967
989
modeIdx = outLevel = rampingLevel = 0;
996
1018
if (!holdHandled)
1020
// For Tactical, turn on MAX while button is depressed
1023
if ((wPressDuration == 1) && !byLockOutSet)
1025
outLevel = rampingLevel = TURBO_LEVEL;
998
1030
//------------------------------------------------------------------------------
999
1031
// Ramping - pressed button
1000
1032
//------------------------------------------------------------------------------
1003
1035
if ((wPressDuration >= SHORT_CLICK_DUR) && !byLockOutSet && !byDelayRamping && (modeIdx < BATT_CHECK_MODE))
1037
turboRestoreLevel = 0; // reset on press&holds (for 2X click exit of turbo feature)
1005
1039
switch (rampState)
1007
1041
case 0: // ramping not initialized yet
1011
1045
rampPauseCntDn = RAMP_MOON_PAUSE; // delay a little on moon
1013
#if OUT_CHANNELS == 3 // Triple Channel
1014
SetOutput(moonlightLevel,0,0);
b'\t\t\t\t\t\t #elif OUT_CHANNELS == 2\t// two channels'
1015
SetOutput(moonlightLevel,0);
1017
SetOutput(moonlightLevel);
1047
#if OUT_CHANNELS == 3 // Triple Channel
1048
SetOutput(moonlightLevel,0,0);
1049
#elif OUT_CHANNELS == 2 // two channels
1051
SetOutput(moonlightLevel,25); // 10% for GT-buck analog control channel
1053
SetOutput(moonlightLevel,0);
1056
SetOutput(moonlightLevel);
1020
1059
#ifdef ONBOARD_LED
1022
1061
TurnOnBoardLed(0);
1044
1083
rampState = 2; // lo->hi
1046
if (rampingLevel == MAX_RAMP_LEVEL)
1086
if (rampingLevel == 255) // If stopped in ramping moon mode, start from lowest
1088
rampState = 2; // lo->hi
1089
outLevel = rampingLevel = 1;
1092
else if (rampingLevel >= MAX_RAMP_LEVEL)
1048
1094
rampState = 3; // hi->lo
1049
1095
outLevel = MAX_RAMP_LEVEL;
1050
1096
SetLevel(outLevel);
1052
else if (rampingLevel == 255) // If stopped in ramping moon mode, start from lowest
1054
rampState = 2; // lo->hi
1055
outLevel = rampingLevel = 1;
1058
1098
else if (rampingLevel == 1)
1059
1099
rampState = 2; // lo->hi
1115
1155
//---------------------------------------------------------------------------------------
1116
1156
if (!ramping && (wPressDuration == LONG_PRESS_DUR) && !byLockOutSet)
1158
if ((modeIdx < 16) && !momentaryState)
1165
if (modeIdx == 1) // wrap around from lowest to highest
1126
1170
else if (modeIdx > SPECIAL_MODES)
1128
1172
if (specModeIdx > 0)
1131
modeIdx = specialModes[specModeIdx];
1135
byDelayRamping = 1; // ensure no ramping handling takes place for this hold
1136
ExitSpecialModes(); // bail out of special modes
1175
specModeIdx = specialModesCnt - 1; // wrap around to last special mode
1176
modeIdx = specialModes[specModeIdx];
1188
1227
modeIdx = 0; // clear main mode
1189
1228
SetOutput(OFF_OUTPUT); // suppress main LED output
1191
1230
ConfigMode = 14; // Reset to Factory Defaults
1192
1231
configClicks = 0;
1193
1232
holdHandled = 1; // suppress more hold events on this hold
1195
else if (!ramping && (blinkyMode > 0) && (modeIdx != BATT_CHECK_MODE))
1234
else if (!ramping && (blinkyMode > 0) && (modeIdx != BATT_CHECK_MODE) && !momentaryState)
1197
1236
// Engage first special mode!
1198
1237
EnterSpecialModes ();
1203
1242
//---------------------------------------------------------------------------------------
1204
1243
// CONFIG hold - if it is not locked out or lock-out was just exited on this hold
1205
1244
//---------------------------------------------------------------------------------------
1206
if (byLockOutSet == 0)
1245
if ((byLockOutSet == 0) && !momentaryState)
1208
1247
if ((!ramping && (wPressDuration == CONFIG_ENTER_DUR) && (fastClicks != 2) && (modeIdx != BATT_CHECK_MODE))
1210
(ramping && (wPressDuration == 500))) // 8 secs in ramping mode
1249
(ramping && (wPressDuration == 500))) // 8 secs in ramping mode
1213
1252
rampingLevel = 0;
1216
// turn the light off initially
1255
// turn the light off initially
1217
1256
SetOutput(OFF_OUTPUT); // suppress main LED output
1219
1258
ConfigMode = 1;
1220
1259
configClicks = 0;
1225
1264
wStepdownTicks = 0; // Just always reset stepdown timer whenever the button is pressed
1260
1299
// Was previously pressed
1303
outLevel = rampingLevel = 0; // turn off output as soon as the user lets the switch go
1262
1307
//------------------------------------------------------------------------------
1263
1308
// Ramping - button released
1264
1309
//------------------------------------------------------------------------------
1275
1320
if (fastClicks == 1)
1277
1322
byModeForClicks = modeIdx; // save current mode
1278
if ((modeIdx < 16) && (rampingLevel == MAX_RAMP_LEVEL))
1323
if ((modeIdx < 16) && (rampingLevel == TURBO_LEVEL))
1279
1324
byModeForClicks = 255;
1281
1326
if ((modeIdx == BATT_CHECK_MODE) || (modeIdx == TEMP_CHECK_MODE) || (modeIdx == FIRM_VERS_MODE))
1284
1329
outLevel = rampingLevel = 0; // 08/28/16 TE: zero out outLevel here as well (used in LVP)
1285
1330
byDelayRamping = 1; // don't act on ramping button presses
1333
initialLevelForClicks = rampingLevel;
1288
if (!byLockOutSet && !byDelayRamping)
1335
if (!byLockOutSet && !byDelayRamping && !momentaryState)
1290
1337
//---------------------------------
1291
1338
// Normal click ON in ramping mode
1315
1364
if (outLevel == 255)
1317
#if OUT_CHANNELS == 3 // Triple Channel
1366
#if OUT_CHANNELS == 3 // Triple Channel
1318
1367
SetOutput(moonlightLevel,0,0);
1319
#elif OUT_CHANNELS == 2 // two channels
1320
SetOutput(moonlightLevel,0);
1322
SetOutput(moonlightLevel);
1368
#elif OUT_CHANNELS == 2 // two channels
1370
SetOutput(moonlightLevel,25); // for GT-buck
1372
SetOutput(moonlightLevel,0);
1375
SetOutput(moonlightLevel);
1325
1378
#ifdef ONBOARD_LED
1327
1380
TurnOnBoardLed(0);
1348
1401
byDelayRamping = 0; // restore acting on ramping button presses, if disabled
1351
//------------------------------------------------------------------------------
1352
// Non-Ramping - button released
1353
//------------------------------------------------------------------------------
1404
//------------------------------------------------------------------------------
1405
// Non-Ramping - button released
1406
//------------------------------------------------------------------------------
1356
1409
if (wPressDuration < LONG_PRESS_DUR)
1375
1428
if (modeMemoryEnabled && (modeMemoryLastModeIdx > 0) && (modeIdx == 0))
1377
modeIdx = modeMemoryLastModeIdx;
1378
modeMemoryLastModeIdx = 0;
1430
if (!momentaryState)
1432
modeIdx = modeMemoryLastModeIdx;
1433
modeMemoryLastModeIdx = 0;
1380
1436
else if (modeIdx < 16)
1382
if ((modeIdx > 0) && (wIdleTicks >= IDLE_TIME))
1384
modeMemoryLastModeIdx = modeIdx;
1385
prevModeIdx = modeIdx;
1386
modeIdx = 0; // Turn OFF the light
1390
// Short press - normal modes
1438
if (!momentaryState)
1440
if ((modeIdx > 0) && (wIdleTicks >= IDLE_TIME))
1442
modeMemoryLastModeIdx = modeIdx;
1443
prevModeIdx = modeIdx;
1444
modeIdx = 0; // Turn OFF the light
1448
// Short press - normal modes
1397
1456
else // special modes
1454
1513
// Process multi clicks here, after it times out
1455
1514
//-----------------------------------------------------------------------------------
1516
if (fastClicks == 5) // --> 5X clicks: toggle momentary mode (click&hold - light ON at max)
1518
if (ramping && !byLockOutSet && !momentaryState)
1521
modeIdx = outLevel = rampingLevel = 0;
1522
SetOutput(OFF_OUTPUT); // suppress main LED output
1457
1526
// For Lock-Out, always support 4 quick clicks regardless of mode/state
1458
1527
#ifdef LOCKOUT_ENABLE
1459
if (fastClicks == 4) // --> 4X clicks: do a lock-out
1528
else if (fastClicks == 4) // --> 4X clicks: do a lock-out
1461
modeIdx = outLevel = rampingLevel = 0;
1463
byLockOutSet = 1 - byLockOutSet; // invert "LOCK OUT"
1464
byDelayRamping = 1; // don't act on ramping button presses (ramping ON/OFF code below)
1530
if ((ramping || byLockOutSet) && !momentaryState) // only for ramping, or un-locking out
1532
modeIdx = outLevel = rampingLevel = 0;
1534
byLockOutSet = 1 - byLockOutSet; // invert "LOCK OUT"
1535
byDelayRamping = 1; // don't act on ramping button presses (ramping ON/OFF code below)
1469
1540
// Support 2X clicks for Batt and Temp blink outs in ramping
1470
if ((byModeForClicks == BATT_CHECK_MODE) || (byModeForClicks == TEMP_CHECK_MODE)) // battery check - multi-click checks
1541
else if ((byModeForClicks == BATT_CHECK_MODE) || (byModeForClicks == TEMP_CHECK_MODE)) // battery check - multi-click checks
1472
1543
if (fastClicks == 2) // --> double click: blink out the firmware vers #
1479
1550
SetOutput(OFF_OUTPUT); // suppress main LED output
1482
else if (ramping && !byLockOutSet)
1553
else if (ramping && !byLockOutSet && !momentaryState)
1484
1555
#ifdef TRIPLE_CLICK_BATT
1485
1556
if (fastClicks == 3) // --> triple click: display battery check/status
1493
1564
if (fastClicks == 2) // --> double click: set to MAX level
1495
if (byModeForClicks == 255)
1566
if (byModeForClicks == 255) // Turbo
1497
1568
if (blinkyMode > 0) // must be enabled
1498
1569
EnterSpecialModes (); // Engage first special mode!
1572
// Restore the saved level (last mode memory)
1573
if (savedLevel != MAX_RAMP_LEVEL)
1574
outLevel = rampingLevel = turboRestoreLevel;
1576
outLevel = rampingLevel = 0;
1502
rampingLevel = MAX_RAMP_LEVEL;
1582
rampingLevel = TURBO_LEVEL;
1503
1583
outLevel = rampingLevel;
1504
1584
SetLevel(outLevel);
1585
turboRestoreLevel = initialLevelForClicks;
1587
wThermalTicks = TEMP_ADJ_PERIOD/3; // Delay a temperature step down at least 15 secs or so
1590
} // ramping && !byLockOutSet
1510
1592
fastClicks = 0; // clear it after processing it
1594
} // wIdleTicks > DBL_CLICK_TICKS
1513
1596
// Only do timed stepdown check when switch isn't pressed
1514
1597
if (stepdownMode > 1)
1658
1741
// Load config settings: mode, mode set, lo-hi, mode memory
1661
// Load the configured temperature to use as the threshold to step down output
1744
// Load the configured temperature to use as the threshold to step down output
1662
1745
byte inValue = eeprom_read_byte((const byte *)250); // use address 250 in the EEPROM space
1663
1746
if ((inValue > 0) && (inValue < 255))
1664
byStepdownTemp = inValue;
1747
byStepdownTemp = inValue;
1666
1749
DefineModeSet();
1705
1788
last_modeIdx = 250; // make it invalid for first time
1707
byte byPrevLockOutSet = 0;
1790
byte byPrevLockOutSet = 0; // copy of byLockOutSet to detect transitions
1791
byte byPrevMomentaryState = 0; // copy of momentaryState to detect transitions
1709
1793
byte prevConfigClicks = 0;
1725
1809
if (ConfigMode == 0) // Normal mode
1726
1810
//---------------------------------------------------------------------------------------
1812
// Handle Lockout mode transtions
1728
1813
if (byPrevLockOutSet != byLockOutSet)
1730
1815
byPrevLockOutSet = byLockOutSet;
1732
1817
SetOutput(OFF_OUTPUT);
1736
1820
byDelayRamping = 0; // restore acting on ramping button presses
1741
1825
last_modeIdx = 255; // exiting - force a mode handling to turn on locator LED
1828
// Handle momentary/tactical mode transitions
1829
if (byPrevMomentaryState != momentaryState)
1831
byPrevMomentaryState = momentaryState;
1833
Blink(2, 60); // Special blink sequence for momentary mode (into or out of)
1744
1838
//---------------------------------------------------
1745
1839
// Mode Handling - did the WDT change the mode?
1746
1840
//---------------------------------------------------
1909
2003
// Reached critical battery level
1910
2004
outLevel = 7; // bump it up a little for final shutoff blinks
1911
BlinkLVP(8); // blink more and quicker (to get attention)
2005
BlinkLVP(8); // blink more and quicker (to get attention)
1912
2006
outLevel = rampingLevel = 0; // Shut it down
1917
2011
// Drop the output level
1918
BlinkLVP(3); // normal 3 blinks
2012
BlinkLVP(3); // normal 3 blinks
1919
2013
if (outLevel > MAX_RAMP_LEVEL/16)
1920
2014
outLevel = ((int)outLevel * 4) / 5; // drop the level (index) by 20%
1928
2022
else // Not ramping
1934
2028
// Reached critical battery level
1935
BlinkLVP(8); // blink more and quicker (to get attention)
2029
BlinkLVP(8); // blink more and quicker (to get attention)
1939
2033
// Drop the output level
1940
BlinkLVP(3); // normal 3 blinks
2034
BlinkLVP(3); // normal 3 blinks
1942
2036
if (modeIdx < 16)
1946
2040
LowBattSignal = 0;
1951
2045
// Blink the Indicator LED twice
1952
2046
if (onboardLedEnable)
1954
if ((modeIdx > 0) || (locatorLed == 0))
2048
// Be sure to leave the indicator LED in it's proper state after blinking twice
2049
if ((locatorLed != 0) &&
2050
((ramping && (outLevel != 0)) || (!ramping && (modeIdx > 0))))
1956
2052
BlinkIndLed(500, 2);
1981
if (outLevel >= FET_START_LVL)
2077
if ((outLevel >= FET_START_LVL) && (outLevel < 255)) // 255 is special value for moon mode (use 1)
1983
2079
int newLevel = outLevel - outLevel/6; // reduce by 16.7%
1985
2081
if (newLevel >= FET_START_LVL)
1986
outLevel = newLevel; // reduce by 16.7%
1988
outLevel = FET_START_LVL - 1; // make it the max of the 7135
2082
outLevel = newLevel; // reduce by 16.7%
2084
outLevel = FET_START_LVL - 1; // make it the max of the 7135
1990
2086
SetLevel(outLevel);
1992
2088
wThermalTicks = TEMP_ADJ_PERIOD;
1993
2089
#ifdef ONBOARD_LED
1994
2090
BlinkIndLed(500, 3); // Flash the Ind LED to show it's lowering
2023
2119
#ifdef ONBOARD_LED
2024
2120
// If the battery is currently low, then turn OFF the indicator LED before going to sleep
2025
2121
// to help in saving the battery
2026
#ifdef VOLT_MON_R1R2
2027
if (byVoltage < ADC_LOW)
2029
if (byVoltage < BATT_LOW)
2122
#ifdef VOLT_MON_R1R2
2123
if (byVoltage < ADC_LOW)
2125
if (byVoltage < BATT_LOW)
2031
2127
if (locatorLed)
2032
2128
TurnOnBoardLed(0);
2145
2241
ConfigMode = 15; // all done, go to exit
2148
case 100: // thermal calibration in effect
2149
Blink(3, 40); // 3 quick blinks
2150
SetOutput(MAX_BRIGHTNESS); // set max output
2244
case 100: // thermal calibration in effect
2245
Blink(3, 40); // 3 quick blinks
2246
SetOutput(MAX_BRIGHTNESS); // set max output
2151
2247
wThermalTicks = 312; // set for 5 seconds as the minimum time to set a new stepdown temperature
2154
case 101: // exiting thermal calibration
2155
SetOutput(OFF_OUTPUT);
2157
if (wThermalTicks == 0) // min. time exceeded
2159
// Save the current temperature to use as the threshold to step down output
2160
byStepdownTemp = byTempReading;
2250
case 101: // exiting thermal calibration
2251
SetOutput(OFF_OUTPUT);
2253
if (wThermalTicks == 0) // min. time exceeded
2255
// Save the current temperature to use as the threshold to step down output
2256
byStepdownTemp = byTempReading;
2161
2257
WrEEPROM (250, byStepdownTemp);
2164
2260
// Continue to next setting (blinky modes)
2177
case 40: // timed stepdown calibration in effect (do nothing here)
2273
case 40: // timed stepdown calibration in effect (do nothing here)
2180
case 41: // (exiting) timed stepdown
2276
case 41: // (exiting) timed stepdown
2181
2277
if ((configClicks > 0) && (configClicks <= 6))
2183
2279
stepdownMode = configClicks + 1;
2208
2304
//---------------------------------------------------------------------
2209
2305
switch (ConfigMode)
2211
case 4: // 2 - (exiting) moonlight level selection
2307
case 4: // 2 - (exiting) moonlight level selection
2212
2308
if ((configClicks > 0) && (configClicks <= 7))
2214
2310
moonlightLevel = configClicks;
2230
2326
stepdownMode = 1;
2232
ConfigMode = 100; // thermal configuration in effect!!
2328
ConfigMode = 100; // thermal configuration in effect!!
2234
else if (configClicks == 3) // timed stepdown
2330
else if (configClicks == 3) // timed stepdown
2236
Blink(3, 40); // 3 quick blinks
2332
Blink(3, 40); // 3 quick blinks
2240
2336
ConfigBlink(4);
2257
2353
//---------------------------------------------------------------------
2258
2354
switch (ConfigMode)
2260
case 4: // 2 - (exiting) mode set selection
2356
case 4: // 2 - (exiting) mode set selection
2261
2357
if ((configClicks > 0) && (configClicks <= 12))
2263
2359
modeSetIdx = configClicks - 1;
2317
2413
stepdownMode = 1;
2319
ConfigMode = 100; // thermal configuration in effect!!
2415
ConfigMode = 100; // thermal configuration in effect!!
2321
else if (configClicks == 3) // timed stepdown
2417
else if (configClicks == 3) // timed stepdown
2323
Blink(3, 40); // 3 quick blinks
2419
Blink(3, 40); // 3 quick blinks
2327
2423
ConfigBlink(8);