libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
MappedValue.h
Go to the documentation of this file.
1#pragma once
2#include <stdint.h>
3#include "FixedCapStr.h"
4
5namespace daisy
6{
12{
13 public:
14 virtual ~MappedValue() {}
15
19 virtual void AppentToString(FixedCapStrBase<char>& string) const = 0;
20
22 virtual void ResetToDefault() = 0;
23
26 virtual float GetAs0to1() const = 0;
27
29 virtual void SetFrom0to1(float normalizedValue0to1) = 0;
30
34 virtual void Step(int16_t numStepsUp, bool useCoarseStepSize) = 0;
35};
36
42{
43 public:
45 enum class Mapping
46 {
48 lin,
52 log,
54 pow2
55 };
56
69 float max,
70 float defaultValue,
72 const char* unitStr = "",
74 bool forceSign = false);
75
76 ~MappedFloatValue() override {}
77
79 float Get() const { return value_; }
80
82 const float* GetPtr() const { return &value_; }
83
85 void Set(float newValue);
86
88 operator float() const { return value_; }
89
92 {
93 Set(val);
94 return *this;
95 }
96
97 // inherited form MappedValue
98 void AppentToString(FixedCapStrBase<char>& string) const override;
99
100 // inherited form MappedValue
101 void ResetToDefault() override;
102
103 // inherited form MappedValue
104 float GetAs0to1() const override;
105
106 // inherited form MappedValue
107 void SetFrom0to1(float normalizedValue0to1) override;
108
113
114 private:
115 float value_;
116 const float min_;
117 const float max_;
118 const float default_;
119 Mapping mapping_;
120 const char* unitStr_;
121 const uint8_t numDecimals_;
122 const bool forceSign_;
123 static constexpr float coarseStepSize0to1_ = 0.05f;
124 static constexpr float fineStepSize0to1_ = 0.01f;
125};
126
132{
133 public:
145 int max,
146 int defaultValue,
147 int stepSizeFine,
148 int stepSizeCoarse,
149 const char* unitStr = "",
150 bool forceSign = false);
151
152 ~MappedIntValue() override {}
153
155 int Get() const { return value_; }
156
158 const int* GetPtr() const { return &value_; }
159
161 void Set(int newValue);
162
164 operator int() const { return value_; }
165
168 {
169 Set(val);
170 return *this;
171 }
172
173 // inherited form MappedValue
174 void AppentToString(FixedCapStrBase<char>& string) const override;
175
176 // inherited form MappedValue
177 void ResetToDefault() override;
178
179 // inherited form MappedValue
180 float GetAs0to1() const override;
181
182 // inherited form MappedValue
183 void SetFrom0to1(float normalizedValue0to1) override;
184
187
188 private:
189 int value_;
190 const int min_;
191 const int max_;
192 const int default_;
193 const int stepSizeFine_;
194 const int stepSizeCoarse_;
195 const char* unitStr_;
196 const bool forceSign_;
197};
203{
204 public:
213
215
217 int GetIndex() const { return index_; }
218
220 const char* GetString() const { return itemStrings_[index_]; }
221
223 const uint32_t* GetIndexPtr() const { return &index_; }
224
226 void SetIndex(uint32_t index);
227
229 operator int() const { return index_; }
230
232 operator const char*() const { return itemStrings_[index_]; }
233
236 {
237 SetIndex(index);
238 return *this;
239 }
240
241 // inherited form MappedValue
242 void AppentToString(FixedCapStrBase<char>& string) const override;
243
244 // inherited form MappedValue
245 void ResetToDefault() override;
246
247 // inherited form MappedValue
248 float GetAs0to1() const override;
249
250 // inherited form MappedValue
251 void SetFrom0to1(float normalizedValue0to1) override;
252
256
257 private:
258 uint32_t index_;
259 const char** itemStrings_;
260 const int numItems_;
261 uint32_t defaultIndex_;
262};
263
264
265} // namespace daisy
Definition leddriver.h:33
Definition MappedValue.h:42
~MappedFloatValue() override
Definition MappedValue.h:76
float Get() const
Definition MappedValue.h:79
void SetFrom0to1(float normalizedValue0to1) override
Mapping
Definition MappedValue.h:46
void Set(float newValue)
void Step(int16_t numStepsUp, bool useCoarseStepSize) override
MappedFloatValue(float min, float max, float defaultValue, Mapping mapping=Mapping::lin, const char *unitStr="", uint8_t numDecimals=1, bool forceSign=false)
void AppentToString(FixedCapStrBase< char > &string) const override
MappedFloatValue & operator=(float val)
Definition MappedValue.h:91
void ResetToDefault() override
float GetAs0to1() const override
const float * GetPtr() const
Definition MappedValue.h:82
Definition MappedValue.h:132
float GetAs0to1() const override
int Get() const
Definition MappedValue.h:155
~MappedIntValue() override
Definition MappedValue.h:152
const int * GetPtr() const
Definition MappedValue.h:158
void ResetToDefault() override
MappedIntValue(int min, int max, int defaultValue, int stepSizeFine, int stepSizeCoarse, const char *unitStr="", bool forceSign=false)
void SetFrom0to1(float normalizedValue0to1) override
void Set(int newValue)
void Step(int16_t numStepsUp, bool useCoarseStepSize) override
MappedIntValue & operator=(int val)
Definition MappedValue.h:167
void AppentToString(FixedCapStrBase< char > &string) const override
Definition MappedValue.h:203
const uint32_t * GetIndexPtr() const
Definition MappedValue.h:223
MappedStringListValue & operator=(int index)
Definition MappedValue.h:235
MappedStringListValue(const char **itemStrings, uint16_t numItems, uint32_t defaultIndex)
void AppentToString(FixedCapStrBase< char > &string) const override
const char * GetString() const
Definition MappedValue.h:220
void SetFrom0to1(float normalizedValue0to1) override
void Step(int16_t numStepsUp, bool useCoarseStepSize) override
void ResetToDefault() override
~MappedStringListValue() override
Definition MappedValue.h:214
void SetIndex(uint32_t index)
float GetAs0to1() const override
int GetIndex() const
Definition MappedValue.h:217
Definition MappedValue.h:12
virtual void SetFrom0to1(float normalizedValue0to1)=0
virtual void AppentToString(FixedCapStrBase< char > &string) const =0
virtual void ResetToDefault()=0
virtual float GetAs0to1() const =0
virtual void Step(int16_t numStepsUp, bool useCoarseStepSize)=0
virtual ~MappedValue()
Definition MappedValue.h:14
Hardware defines and helpers for daisy field platform.
Definition index.h:2