Skip to content

Commit

Permalink
move arg getting/setting to the prop since it owns current_preset_
Browse files Browse the repository at this point in the history
  • Loading branch information
profezzorn committed Mar 18, 2024
1 parent 80ac2bb commit 432471a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 29 deletions.
9 changes: 9 additions & 0 deletions ProffieOS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,13 @@ class NoLED;
#include "styles/show_color.h"
#include "styles/blade_shortener.h"

#include "sound/sound_library.h"

#include "modes/mode.h"
#include "modes/stepped_mode.h"
#include "modes/color_change_modes.h"
#include "modes/menu_list.h"
#include "modes/bool_setting.h"

BladeConfig* current_config = nullptr;
class BladeBase* GetPrimaryBlade() {
Expand Down Expand Up @@ -683,6 +687,11 @@ int prop_GetBulletCount() {
}
#endif

class Color16 GetColorArg(int blade, int arg) { return prop.GetColorArg(blade, arg); }
void SetArg(int blade, int arg, const char* argument) { prop.SetArg(blade, arg, argument); }
void SetColorArg(int blade, int arg, Color16 color) { prop.SetColorArg(blade, arg, color); }


#if 0
#include "scripts/test_motion_timeout.h"
#warning MOTION TEST SCRIPT ACTIVE
Expand Down
33 changes: 4 additions & 29 deletions modes/style_argument_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,10 @@ namespace mode {
int menu_current_blade = 1;
int menu_current_arg = 0;

Color16 GetColorArg(int blade, int arg) {
char argspace[32];
if (style_parser.GetArgument(current_preset_.GetStyle(blade), arg + 2, 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 SetArg(int blade, int arg, const char* argument) {
current_preset_.SetStyle(blade, style_parser.SetArgument(current_preset_.GetStyle(blade), arg + 2, argument));
}

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(menu_current_blade, menu_current_arg, tmp);

current_preset_.Save();
}

} // 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
30 changes: 30 additions & 0 deletions props/prop_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,36 @@ class PropBase : CommandParser, Looper, protected SaberBase, public ModeInterfac
}
virtual bool Event2(enum BUTTON button, EVENT event, uint32_t modifiers) = 0;


Color16 GetColorArg(int blade, int arg) {
char argspace[32];
if (style_parser.GetArgument(current_preset_.GetStyle(blade), arg + 2, 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 SetArg(int blade, int arg, const char* argument) {
current_preset_.SetStyle(blade, style_parser.SetArgument(current_preset_.GetStyle(blade), arg + 2, argument));
}

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);

current_preset_.Save();
}

private:
bool CommonIgnition() {
if (IsOn()) return false;
Expand Down

0 comments on commit 432471a

Please sign in to comment.