~toykeeper/flashlight-firmware/trunk

« back to all changes in this revision

Viewing changes to ToyKeeper/spaghetti-monster/anduril/anduril.c

  • Committer: Selene Scriven
  • Date: 2018-08-23 00:44:06 UTC
  • mto: This revision was merged to the branch mainline in revision 212.
  • Revision ID: bzr@toykeeper.net-20180823004406-166nln59is9nsn3f
Replaced hardcoded eeprom index values with auto-calculated enums.

Show diffs side-by-side

added added

removed removed

Lines of Context:
132
132
#define STROBE_BRIGHTNESS MAX_LEVEL
133
133
#endif
134
134
 
135
 
// try to auto-detect how many eeprom bytes
136
 
// FIXME: detect this better, and assign offsets better, for various configs
 
135
#if defined(USE_CANDLE_MODE) || defined(USE_BIKE_FLASHER_MODE) || defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE) || defined(USE_LIGHTNING_MODE)
 
136
#define USE_STROBE_STATE
 
137
#endif
 
138
 
 
139
// auto-detect how many eeprom bytes
137
140
#define USE_EEPROM
138
 
#ifdef USE_INDICATOR_LED
139
 
#define EEPROM_BYTES 15
140
 
#elif defined(USE_THERMAL_REGULATION)
141
 
#define EEPROM_BYTES 14
142
 
#else
143
 
#define EEPROM_BYTES 12
144
 
#endif
 
141
typedef enum {
 
142
    ramp_style_e,
 
143
    ramp_smooth_floor_e,
 
144
    ramp_smooth_ceil_e,
 
145
    ramp_discrete_floor_e,
 
146
    ramp_discrete_ceil_e,
 
147
    ramp_discrete_steps_e,
 
148
    #ifdef USE_STROBE_STATE
 
149
    strobe_type_e,
 
150
    #endif
 
151
    #if defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE)
 
152
    strobe_delays_0_e,
 
153
    strobe_delays_1_e,
 
154
    #endif
 
155
    #ifdef USE_BIKE_FLASHER_MODE
 
156
    bike_flasher_brightness_e,
 
157
    #endif
 
158
    beacon_seconds_e,
 
159
    #ifdef USE_MUGGLE_MODE
 
160
    muggle_mode_active_e,
 
161
    #endif
 
162
    #ifdef USE_THERMAL_REGULATION
 
163
    therm_ceil_e,
 
164
    therm_cal_offset_e,
 
165
    #endif
 
166
    #ifdef USE_INDICATOR_LED
 
167
    indicator_led_mode_e,
 
168
    #endif
 
169
    eeprom_indexes_e_END
 
170
} eeprom_indexes_e;
 
171
#define EEPROM_BYTES eeprom_indexes_e_END
 
172
 
145
173
#ifdef START_AT_MEMORIZED_LEVEL
146
174
#define USE_EEPROM_WL
147
175
#define EEPROM_WL_BYTES 1
167
195
uint8_t steady_state(EventPtr event, uint16_t arg);
168
196
uint8_t ramp_config_state(EventPtr event, uint16_t arg);
169
197
// party and tactical strobes
170
 
#if defined(USE_CANDLE_MODE) || defined(USE_BIKE_FLASHER_MODE) || defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE) || defined(USE_LIGHTNING_MODE)
171
 
#define USE_STROBE_STATE
 
198
#ifdef USE_STROBE_STATE
172
199
uint8_t strobe_state(EventPtr event, uint16_t arg);
173
200
#endif
174
201
#ifdef USE_BATTCHECK
284
311
    lightning_storm_e,
285
312
    #endif
286
313
    strobe_mode_END
287
 
} strobe_mode_te ;
 
314
} strobe_mode_te;
288
315
 
289
316
const int NUM_STROBES = strobe_mode_END;
290
317
 
1604
1631
 
1605
1632
void load_config() {
1606
1633
    if (load_eeprom()) {
1607
 
        ramp_style = eeprom[0];
1608
 
        ramp_smooth_floor = eeprom[1];
1609
 
        ramp_smooth_ceil = eeprom[2];
1610
 
        ramp_discrete_floor = eeprom[3];
1611
 
        ramp_discrete_ceil = eeprom[4];
1612
 
        ramp_discrete_steps = eeprom[5];
 
1634
        ramp_style = eeprom[ramp_style_e];
 
1635
        ramp_smooth_floor = eeprom[ramp_smooth_floor_e];
 
1636
        ramp_smooth_ceil = eeprom[ramp_smooth_ceil_e];
 
1637
        ramp_discrete_floor = eeprom[ramp_discrete_floor_e];
 
1638
        ramp_discrete_ceil = eeprom[ramp_discrete_ceil_e];
 
1639
        ramp_discrete_steps = eeprom[ramp_discrete_steps_e];
1613
1640
        #if defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE)
1614
 
        strobe_type = eeprom[6];  // TODO: move this to eeprom_wl?
1615
 
        strobe_delays[0] = eeprom[7];
1616
 
        strobe_delays[1] = eeprom[8];
 
1641
        strobe_type = eeprom[strobe_type_e];  // TODO: move this to eeprom_wl?
 
1642
        strobe_delays[0] = eeprom[strobe_delays_0_e];
 
1643
        strobe_delays[1] = eeprom[strobe_delays_1_e];
1617
1644
        #endif
1618
1645
        #ifdef USE_BIKE_FLASHER_MODE
1619
 
        bike_flasher_brightness = eeprom[9];
 
1646
        bike_flasher_brightness = eeprom[bike_flasher_brightness_e];
1620
1647
        #endif
1621
 
        beacon_seconds = eeprom[10];
 
1648
        beacon_seconds = eeprom[beacon_seconds_e];
1622
1649
        #ifdef USE_MUGGLE_MODE
1623
 
        muggle_mode_active = eeprom[11];
 
1650
        muggle_mode_active = eeprom[muggle_mode_active_e];
1624
1651
        #endif
1625
1652
        #ifdef USE_THERMAL_REGULATION
1626
 
        therm_ceil = eeprom[12];
1627
 
        therm_cal_offset = eeprom[13];
 
1653
        therm_ceil = eeprom[therm_ceil_e];
 
1654
        therm_cal_offset = eeprom[therm_cal_offset_e];
1628
1655
        #endif
1629
1656
        #ifdef USE_INDICATOR_LED
1630
 
        indicator_led_mode = eeprom[14];
 
1657
        indicator_led_mode = eeprom[indicator_led_mode_e];
1631
1658
        #endif
1632
1659
    }
1633
1660
    #ifdef START_AT_MEMORIZED_LEVEL
1638
1665
}
1639
1666
 
1640
1667
void save_config() {
1641
 
    eeprom[0] = ramp_style;
1642
 
    eeprom[1] = ramp_smooth_floor;
1643
 
    eeprom[2] = ramp_smooth_ceil;
1644
 
    eeprom[3] = ramp_discrete_floor;
1645
 
    eeprom[4] = ramp_discrete_ceil;
1646
 
    eeprom[5] = ramp_discrete_steps;
 
1668
    eeprom[ramp_style_e] = ramp_style;
 
1669
    eeprom[ramp_smooth_floor_e] = ramp_smooth_floor;
 
1670
    eeprom[ramp_smooth_ceil_e] = ramp_smooth_ceil;
 
1671
    eeprom[ramp_discrete_floor_e] = ramp_discrete_floor;
 
1672
    eeprom[ramp_discrete_ceil_e] = ramp_discrete_ceil;
 
1673
    eeprom[ramp_discrete_steps_e] = ramp_discrete_steps;
1647
1674
    #if defined(USE_PARTY_STROBE_MODE) || defined(USE_TACTICAL_STROBE_MODE)
1648
 
    eeprom[6] = strobe_type;  // TODO: move this to eeprom_wl?
1649
 
    eeprom[7] = strobe_delays[0];
1650
 
    eeprom[8] = strobe_delays[1];
 
1675
    eeprom[strobe_type_e] = strobe_type;  // TODO: move this to eeprom_wl?
 
1676
    eeprom[strobe_delays_0_e] = strobe_delays[0];
 
1677
    eeprom[strobe_delays_1_e] = strobe_delays[1];
1651
1678
    #endif
1652
1679
    #ifdef USE_BIKE_FLASHER_MODE
1653
 
    eeprom[9] = bike_flasher_brightness;
 
1680
    eeprom[bike_flasher_brightness_e] = bike_flasher_brightness;
1654
1681
    #endif
1655
 
    eeprom[10] = beacon_seconds;
 
1682
    eeprom[beacon_seconds_e] = beacon_seconds;
1656
1683
    #ifdef USE_MUGGLE_MODE
1657
 
    eeprom[11] = muggle_mode_active;
 
1684
    eeprom[muggle_mode_active_e] = muggle_mode_active;
1658
1685
    #endif
1659
1686
    #ifdef USE_THERMAL_REGULATION
1660
 
    eeprom[12] = therm_ceil;
1661
 
    eeprom[13] = therm_cal_offset;
 
1687
    eeprom[therm_ceil_e] = therm_ceil;
 
1688
    eeprom[therm_cal_offset_e] = therm_cal_offset;
1662
1689
    #endif
1663
1690
    #ifdef USE_INDICATOR_LED
1664
 
    eeprom[14] = indicator_led_mode;
 
1691
    eeprom[indicator_led_mode_e] = indicator_led_mode;
1665
1692
    #endif
1666
1693
 
1667
1694
    save_eeprom();