~toykeeper/flashlight-firmware/fsm

« back to all changes in this revision

Viewing changes to ToyKeeper/spaghetti-monster/fsm-channels.h

  • Committer: Selene ToyKeeper
  • Date: 2023-07-10 17:56:04 UTC
  • mto: (483.1.175 anduril2)
  • mto: This revision was merged to the branch mainline in revision 491.
  • Revision ID: bzr@toykeeper.net-20230710175604-sjm29fwj8k5bj8m9
refactored how channel modes are defined, and converted emisar-2ch build

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// fsm-channels.h: Channel mode functions for SpaghettiMonster.
 
2
// Copyright (C) 2023 Selene ToyKeeper
 
3
// SPDX-License-Identifier: GPL-3.0-or-later
 
4
 
 
5
#pragma once
 
6
 
 
7
// always enable channel modes, even if there is only one
 
8
#define USE_CHANNEL_MODES
 
9
 
 
10
// typedefs
 
11
typedef void SetLevelFunc(uint8_t level);
 
12
typedef SetLevelFunc * SetLevelFuncPtr;
 
13
 
 
14
typedef bool GradualTickFunc(uint8_t gt);
 
15
typedef GradualTickFunc * GradualTickFuncPtr;
 
16
 
 
17
typedef struct Channel {
 
18
    SetLevelFuncPtr set_level;
 
19
    #ifdef USE_SET_LEVEL_GRADUALLY
 
20
        GradualTickFuncPtr gradual_tick;
 
21
    #endif
 
22
    #ifdef USE_CHANNEL_MODE_ARGS
 
23
        bool has_args;
 
24
        //uint8_t arg;  // is in the config struct, not here
 
25
    #endif
 
26
} Channel;
 
27
 
 
28
Channel channels[];  // values are defined in the hwdef-*.c
 
29
 
 
30
// TODO: size-optimize the case with only 1 channel mode?
 
31
// (the arrays and stuff shouldn't be needed)
 
32
 
 
33
#ifdef USE_CFG
 
34
    #define CH_MODE cfg.channel_mode
 
35
#else
 
36
    // current multi-channel mode
 
37
    uint8_t channel_mode = DEFAULT_CHANNEL_MODE;
 
38
    #define CH_MODE channel_mode
 
39
#endif
 
40
 
 
41
// FIXME: remove this?
 
42
#if NUM_CHANNEL_MODES > 1
 
43
#define USE_CHANNEL_MODES
 
44
#endif
 
45
 
 
46
#ifdef USE_CUSTOM_CHANNEL_3H_MODES
 
47
// different 3H behavior per channel?
 
48
// TODO: move to progmem
 
49
// TODO: move to Anduril, not FSM
 
50
StatePtr channel_3H_modes[NUM_CHANNEL_MODES];
 
51
#endif
 
52
 
 
53
//#ifdef USE_CHANNEL_MODE_TOGGLES
 
54
#if NUM_CHANNEL_MODES > 1
 
55
// user can take unwanted modes out of the rotation
 
56
// bitmask
 
57
#ifdef USE_CFG
 
58
    #define channel_mode_enabled(n) ((cfg.channel_modes_enabled >> n) & 1)
 
59
    #define channel_mode_enable(n)  cfg.channel_modes_enabled |= (1 << n)
 
60
    #define channel_mode_disable(n) cfg.channel_modes_enabled &= ((1 << n) ^ 0xff)
 
61
#else
 
62
    uint16_t channel_modes_enabled = CHANNEL_MODES_ENABLED;
 
63
    #define channel_mode_enabled(n) ((channel_modes_enabled >> n) & 1)
 
64
    #define channel_mode_enable(n)  channel_modes_enabled |= (1 << n)
 
65
    #define channel_mode_disable(n) channel_modes_enabled &= ((1 << n) ^ 0xff)
 
66
    #endif
 
67
#endif
 
68
 
 
69
#ifdef USE_CHANNEL_MODE_ARGS
 
70
    #ifndef USE_CFG
 
71
    // one byte of extra data per channel mode, like for tint value
 
72
    uint8_t channel_mode_args[NUM_CHANNEL_MODES] = { CHANNEL_MODE_ARGS };
 
73
    #endif
 
74
    // which modes respond to their "arg", and which don't?
 
75
    //const uint8_t channel_has_args = CHANNEL_HAS_ARGS;
 
76
    //#define channel_has_args(n) ((CHANNEL_HAS_ARGS >> n) & 1)
 
77
    // struct member
 
78
    #define channel_has_args(n) (channels[n].has_args)
 
79
#endif
 
80
 
 
81
void set_channel_mode(uint8_t mode);
 
82
 
 
83
#ifdef USE_CALC_2CH_BLEND
 
84
void calc_2ch_blend(
 
85
    PWM_DATATYPE *warm,
 
86
    PWM_DATATYPE *cool,
 
87
    PWM_DATATYPE brightness,
 
88
    PWM_DATATYPE top,
 
89
    uint8_t blend);
 
90
#endif
 
91
 
 
92
#ifdef USE_HSV2RGB
 
93
typedef struct RGB_t {
 
94
    uint8_t r;
 
95
    uint8_t g;
 
96
    uint8_t b;
 
97
} RGB_t;
 
98
RGB_t hsv2rgb(uint8_t h, uint8_t s, uint8_t v);
 
99
#endif  // ifdef USE_HSV2RGB
 
100
 
 
101
 
 
102
#ifdef USE_SET_LEVEL_1CH
 
103
// TODO: remove this
 
104
void set_level_1ch(uint8_t level);
 
105
#endif
 
106
 
 
107
#ifdef USE_SET_LEVEL_2CH_STACKED
 
108
// TODO: remove this
 
109
void set_level_2ch_stacked(uint8_t level);
 
110
#endif
 
111
 
 
112
#ifdef USE_SET_LEVEL_3CH_STACKED
 
113
// TODO: remove this
 
114
void set_level_3ch_stacked(uint8_t level);
 
115
#endif
 
116
 
 
117
#if defined(USE_TINT_RAMPING) && (!defined(TINT_RAMP_TOGGLE_ONLY))
 
118
// TODO: remove this
 
119
void set_level_2ch_blend();
 
120
#endif
 
121
 
 
122
#ifdef USE_GRADUAL_TICK_1CH
 
123
// TODO: remove this
 
124
void gradual_tick_1ch();
 
125
#endif
 
126
 
 
127
#ifdef USE_GRADUAL_TICK_2CH_STACKED
 
128
// TODO: remove this
 
129
void gradual_tick_2ch_stacked();
 
130
#endif
 
131
 
 
132
#ifdef USE_GRADUAL_TICK_3CH_STACKED
 
133
// TODO: remove this
 
134
void gradual_tick_3ch_stacked();
 
135
#endif
 
136