-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
043b7e0
commit bf4b9e6
Showing
9 changed files
with
230 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,83 @@ | ||
#ifndef MODE_STYLE_ARGUMENT_HELPERS | ||
#define MODE_STYLE_ARGUMENT_HELPERS | ||
|
||
const char* GetStyle(int blade); | ||
void SetStyle(int blade, LSPtr<char> style); | ||
|
||
namespace mode { | ||
|
||
int menu_current_blade = 1; | ||
int menu_current_arg = 0; | ||
|
||
bool isTimeArg(int arg) { | ||
switch (arg) { | ||
case IGNITION_TIME_ARG: | ||
case IGNITION_DELAY_ARG: | ||
case RETRACTION_TIME_ARG: | ||
case RETRACTION_DELAY_ARG: | ||
return true; | ||
} | ||
} | ||
|
||
bool GetArg(int blade, int arg, char* argspace) { | ||
return style_parser.GetArgument(GetStyle(blade), arg + 2, argspace); | ||
} | ||
void SetArg(int blade, int arg, const char* argument) { | ||
SetStyle(blade, style_parser.SetArgument(GetStyle(blade), arg + 2, argument)); | ||
} | ||
|
||
Color16 GetColorArg(int blade, int arg) { | ||
char argspace[32]; | ||
if (GetArg(blade, arg, argspace)) { | ||
char* tmp; | ||
int r = strtol(argspace, &tmp, 0); | ||
int g = strtol(tmp+1, &tmp, 0); | ||
int b = strtol(tmp+1, NULL, 0); | ||
return Color16(r,g,b); | ||
} | ||
return Color16(65535,0,0); | ||
} | ||
|
||
void SetColorArg(int blade, int arg, Color16 color) { | ||
char tmp[32]; | ||
itoa(color.r, tmp, 10); | ||
strcat(tmp, ","); | ||
itoa(color.g, tmp + strlen(tmp), 10); | ||
strcat(tmp, ","); | ||
itoa(color.b, tmp + strlen(tmp), 10); | ||
|
||
SetArg(blade, arg, tmp); | ||
} | ||
|
||
int GetIntArg(int blade, int arg) { | ||
char argspace[32]; | ||
if (GetArg(blade, arg, argspace)) { | ||
return strtol(argspace, nullptr, 0); | ||
} | ||
return -1; | ||
} | ||
|
||
void SetIntArg(int blade, int arg, int value) { | ||
char tmp[32]; | ||
itoa(value, tmp, 10); | ||
SetArg(blade, arg, tmp); | ||
} | ||
|
||
BladeStyle* GetCurrentBladeStyle() { | ||
BladeBase* blade = GetBladeByNumber(menu_current_blade); | ||
if (!blade) return nullptr; | ||
return blade->current_style(); | ||
} | ||
|
||
int GetMaxStyleArg() { | ||
BladeStyle* style = GetCurrentBladeStyle(); | ||
if (!style) return ARG_MAX_UNKNOWN; | ||
return style->get_max_arg(menu_current_arg); | ||
} | ||
|
||
|
||
} // namespace mode | ||
|
||
Color16 GetColorArg(int blade, int arg); | ||
void SetArg(int blade, int arg, const char* argument); | ||
void SetColorArg(int blade, int arg, Color16 color); | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#ifndef MODES_STYLE_OPTION_MODES_H | ||
#define MODES_STYLE_OPTION_MODES_H | ||
|
||
namespace mode { | ||
|
||
template<class SPEC> | ||
class SelectArgSmoothMode : public SPEC::SmoothMode { | ||
public: | ||
int get() override { return GetIntArg(menu_current_blade, menu_current_arg); } | ||
int set(int x) { | ||
value_ = x; | ||
if (!getSL<SPEC>()->busy()) { | ||
getSL<SPEC>()->SayWhole(x * 100 / 32768); | ||
getSL<SPEC>()->SayPercent(); | ||
} | ||
} | ||
|
||
void select() override { | ||
SPEC::SmoothMode::select(); | ||
SetIntArg(menu_current_blade, menu_current_arg, value_); | ||
popMode(); | ||
} | ||
|
||
private: | ||
int value_ = 0; | ||
}; | ||
|
||
template<class SPEC> | ||
class SelectArgTime : public SPEC::SmoothMode { | ||
public: | ||
int get() override { return GetIntArg(menu_current_blade, menu_current_arg); } | ||
float t(int x) { return powf(x / 32768.0f, 2.0) * 30.0; } | ||
int set(int x) { | ||
value_ = x; | ||
if (!getSL<SPEC>()->busy()) { | ||
getSL<SPEC>()->SayNumber(t(x), SAY_DECIMAL); | ||
getSL<SPEC>()->SaySeconds(); | ||
} | ||
} | ||
|
||
void select() override { | ||
SPEC::SmoothMode::select(); | ||
SetIntArg(menu_current_blade, menu_current_arg, (int)(t(value_) * 1000)); | ||
popMode(); | ||
} | ||
|
||
private: | ||
int value_ = 0; | ||
}; | ||
|
||
template<class SPEC> | ||
class SelectArgNumber : public SPEC::MenuBase { | ||
public: | ||
void activate(bool onreturn) override { | ||
SPEC::MenuBase::activate(onreturn); | ||
if (!onreturn) { | ||
int max = GetMaxStyleArg(); | ||
if (max < 0) max = 32768; | ||
max_ = max; | ||
this->pos_ = GetIntArg(menu_current_blade, menu_current_arg); | ||
// TODO: What if pos_ > max_ ? | ||
} | ||
} | ||
void say() override { | ||
getSL<SPEC>()->SayWhole(this->pos_); | ||
} | ||
uint16_t size() override { return max_; } | ||
|
||
void select() override { | ||
SPEC::SmoothMode::select(); | ||
SetIntArg(menu_current_blade, menu_current_arg, this->pos_); | ||
popMode(); | ||
} | ||
private: | ||
uint16_t max_; | ||
}; | ||
|
||
template<class SPEC> | ||
class SelectArgMode : public SPEC::MenuBase { | ||
public: | ||
void activate(bool onreturn) override { | ||
// TODO: Set pos_ to something reasonable? | ||
arginfo_ = style_parser.GetArgInfo(GetStyle(menu_current_blade)); | ||
SPEC::MenuBase::activate(onreturn); | ||
} | ||
int size() override { return arginfo_.used(); } | ||
void say() override { | ||
getSL<SPEC>()->SayArgument(getCurrentArgument()); | ||
} | ||
|
||
void select() override { | ||
menu_current_arg = getCurrentArgument(); | ||
if (arginfo_.iscolor(menu_current_arg)) { | ||
pushMode<SPEC::SelectArgColor>(); | ||
} else { | ||
int max_arg = GetMaxStyleArg(); | ||
if (max_arg == 32768 || max_arg == 32767) { | ||
pushMode<SPEC::SelectArgSmooth>(); | ||
} else if (max_arg <= 0 && isTimeArg(menu_current_arg)) { | ||
pushMode<SPEC::SelectArgTime>(); | ||
} else { | ||
pushMode<SPEC::SelectArgNumber>(); | ||
} | ||
} | ||
} | ||
|
||
protected: | ||
int getCurrentArgument() { return arginfo_.nth(this->pos_); } | ||
ArgInfo arginfo_; | ||
}; | ||
|
||
} // namespace mode | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters