Skip to content

Commit 75e8366

Browse files
Add support for auto on blaster display (#867)
1 parent a3b61ca commit 75e8366

File tree

3 files changed

+46
-22
lines changed

3 files changed

+46
-22
lines changed

display/layer_controller.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ if it is looped.
6565
6666
*/
6767

68-
69-
7068
#include "../common/bytearray.h"
7169

7270
struct VariableSource {
@@ -279,7 +277,6 @@ class BufferedFileReader : public AudioStreamWork {
279277
POLYHOLE;
280278
};
281279

282-
283280
class SCRReader : public BufferedFileReader {
284281
public:
285282
explicit SCRReader(LayeredScreenControl* screen) : screen_(screen) {
@@ -460,7 +457,6 @@ class SCRReader : public BufferedFileReader {
460457
StateMachineState state_machine_;
461458
};
462459

463-
464460
#define ONCE_PER_EFFECT(X) \
465461
X(boot) \
466462
X(font) \
@@ -479,18 +475,17 @@ class SCRReader : public BufferedFileReader {
479475
X(idle) \
480476
X(lowbatt)
481477

482-
483478
#define INIT_SCR(X, ARGS...) ,SCR_##X(ConcatByteArrays<PREFIX, ByteArray<'/'>, STRTYPE(#X)>::str, nullptr, Effect::FileType::SCREEN)
484479
#define DEF_SCR(X, ARGS...) Effect SCR_##X;
485480

486481
template<int W, int H, typename PREFIX = ConcatByteArrays<typename NumberToByteArray<W>::type, ByteArray<'x'>, typename NumberToByteArray<H>::type>>
487-
class StandarColorDisplayController : public SaberBase, public Looper, public CommandParser, public LayerControllerInterface {
482+
class StandardColorDisplayController : public SaberBase, public Looper, public CommandParser, public LayerControllerInterface {
488483
public:
489484
// typedef SizedLayeredScreenControl<W, H> SLSC;
490-
// explicit StandarColorDisplayController(SLSC* screen) : scr_(screen) ONCE_PER_EFFECT(INIT_SCR) {}
485+
// explicit StandardColorDisplayController(SLSC* screen) : scr_(screen) ONCE_PER_EFFECT(INIT_SCR) {}
491486

492487
template<int w, int h>
493-
explicit StandarColorDisplayController(SizedLayeredScreenControl<w, h>* screen) : scr_(screen) ONCE_PER_EFFECT(INIT_SCR) {
488+
explicit StandardColorDisplayController(SizedLayeredScreenControl<w, h>* screen) : scr_(screen) ONCE_PER_EFFECT(INIT_SCR) {
494489
static_assert(w == W, "Width is not matching.");
495490
static_assert(h == H, "Height is not matching.");
496491
screen->LSC_SetController(this);
@@ -659,7 +654,6 @@ class StandarColorDisplayController : public SaberBase, public Looper, public Co
659654
return false;
660655
}
661656

662-
663657
protected:
664658
SCRReader scr_;
665659
ONCE_PER_EFFECT(DEF_SCR)

props/blaster.h

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ class Blaster : public PROP_INHERIT_PREFIX PropBase {
438438
FindBladeAgain();
439439
SaberBase::DoBladeDetect(false);
440440
return true;
441-
#endif
441+
#endif
442442
}
443443
return false;
444444
}
@@ -519,6 +519,7 @@ class Blaster : public PROP_INHERIT_PREFIX PropBase {
519519
#ifdef PROP_BOTTOM
520520

521521
#define ONCE_PER_BLASTER_EFFECT(X) \
522+
X(auto) \
522523
X(stun) \
523524
X(blast) \
524525
X(reload) \
@@ -533,7 +534,7 @@ class Blaster : public PROP_INHERIT_PREFIX PropBase {
533534
struct BlasterDisplayConfigFile : public ConfigFile {
534535
BlasterDisplayConfigFile() { link(&font_config); }
535536
void iterateVariables(VariableOP *op) override {
536-
CONFIG_VARIABLE2(ProffieOSStunImageDuration, 1000.0f);
537+
CONFIG_VARIABLE2(ProffieOSStunImageDuration, 1000.0f);
537538
CONFIG_VARIABLE2(ProffieOSFireImageDuration, 1000.0f);
538539
CONFIG_VARIABLE2(ProffieOSReloadImageDuration, 1000.0f);
539540
CONFIG_VARIABLE2(ProffieOSEmptyImageDuration, 1000.0f);
@@ -561,7 +562,6 @@ struct BlasterDisplayConfigFile : public ConfigFile {
561562
float ProffieOSDestructImageDuration;
562563
};
563564

564-
565565
template<typename PREFIX = ByteArray<>>
566566
struct BlasterDisplayEffects {
567567
BlasterDisplayEffects() : dummy_(0) ONCE_PER_BLASTER_EFFECT(INIT_IMG) {}
@@ -579,6 +579,17 @@ class BlasterDisplayController : public StandardDisplayController<Width, col_t,
579579
blaster_font_config(*getPtr<BlasterDisplayConfigFile>()) {
580580
}
581581

582+
void ShowDefault(bool ignore_lockup = false) override {
583+
if (SaberBase::IsOn() &&
584+
SaberBase::Lockup() == SaberBase::LOCKUP_AUTOFIRE &&
585+
img_.IMG_auto &&
586+
!ignore_lockup) {
587+
this->SetFile(&img_.IMG_auto, 3600000.0);
588+
return;
589+
}
590+
StandardDisplayController<Width, col_t, PREFIX>::ShowDefault(ignore_lockup);
591+
}
592+
582593
void SB_Effect2(EffectType effect, EffectLocation location) override {
583594
switch (effect) {
584595
case EFFECT_STUN:
@@ -619,22 +630,34 @@ class BlasterDisplayController : public StandardDisplayController<Width, col_t,
619630
#endif // INCLUDE_SSD1306
620631

621632
template<int W, int H, typename PREFIX = ConcatByteArrays<typename NumberToByteArray<W>::type, ByteArray<'x'>, typename NumberToByteArray<H>::type>>
622-
class BlasterColorDisplayController : public StandarColorDisplayController<W, H, PREFIX> {
633+
class BlasterColorDisplayController : public StandardColorDisplayController<W, H, PREFIX> {
623634
public:
624635
template<int w, int h>
625-
explicit BlasterColorDisplayController(SizedLayeredScreenControl<w, h>* screen) : StandarColorDisplayController<W, H, PREFIX>(screen) ONCE_PER_BLASTER_EFFECT(INIT_SCR) {
636+
explicit BlasterColorDisplayController(SizedLayeredScreenControl<w, h>* screen) : StandardColorDisplayController<W, H, PREFIX>(screen) ONCE_PER_BLASTER_EFFECT(INIT_SCR) {
626637
}
638+
639+
void ShowDefault(bool ignore_lockup = false) override {
640+
if (SaberBase::IsOn() &&
641+
SaberBase::Lockup() == SaberBase::LOCKUP_AUTOFIRE &&
642+
SCR_auto &&
643+
!ignore_lockup) {
644+
this->scr_.Play(&SCR_auto);
645+
return;
646+
}
647+
StandardColorDisplayController<W, H, PREFIX>::ShowDefault(ignore_lockup);
648+
}
649+
627650
void SB_Effect2(EffectType effect, EffectLocation location) override {
628651
switch (effect) {
629-
case EFFECT_STUN: this->scr_.Play(&SCR_stun); break;
652+
case EFFECT_STUN: this->scr_.Play(&SCR_stun); break;
630653
case EFFECT_FIRE: this->scr_.Play(&SCR_blast); break;
631654
case EFFECT_RELOAD: this->scr_.Play(&SCR_reload); break;
632655
case EFFECT_EMPTY: this->scr_.Play(&SCR_empty); break;
633656
case EFFECT_JAM: this->scr_.Play(&SCR_jam); break;
634657
case EFFECT_CLIP_IN: this->scr_.Play(&SCR_clipin); break;
635658
case EFFECT_CLIP_OUT: this->scr_.Play(&SCR_clipout); break;
636659
default:
637-
StandarColorDisplayController<W, H, PREFIX>::SB_Effect2(effect, location);
660+
StandardColorDisplayController<W, H, PREFIX>::SB_Effect2(effect, location);
638661
}
639662
}
640663

styles/display.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
//
1616
// Then you need a controller for it:
1717
//
18-
// StandarColorDisplayController<8, 8> my_small_display_controller(&my_small_display);
18+
// StandardColorDisplayController<8, 8> my_small_display_controller(&my_small_display);
1919
//
20-
// Now we need give this display a name we can use in a style:
20+
// Now we need to give this display a name we can use in a style:
2121
//
2222
// NAME_INSTANCE(my_small_display, MYDISPLAY);
2323
//
@@ -60,13 +60,16 @@ class InMemoryDisplay : public RGB565Frame<WIDTH, HEIGHT, LAYERS>, public Looper
6060
const char* name() override { return "InMemoryDisplay"; }
6161
InMemoryDisplay() : Looper(HFLINK) {
6262
}
63+
6364
void initDisplay() override {
6465
for (int i = 0; i < NBUF; i++) fb_[i].clear();
6566
target_buffer_ = FrameRef(fb_);
6667
}
68+
6769
void enableDisplay() override {}
6870
void disableDisplay() override {}
6971
void enableBacklight() override {}
72+
7073
void startTransfer() override {
7174
while (SUPER::output_buffers_.size() && SUPER::output_buffers_.data()->done.get()) {
7275
uint16_t *data = SUPER::output_buffers_.data()->chunk.begin();
@@ -75,17 +78,19 @@ class InMemoryDisplay : public RGB565Frame<WIDTH, HEIGHT, LAYERS>, public Looper
7578
SUPER::output_buffers_.pop(1);
7679
}
7780
}
81+
7882
void fixByteOrder() override {}
7983

8084
void swapBuffers() override {
8185
active_buffer_ = target_buffer_;
8286
target_buffer_ = FrameRef(fb_ + next_buffer());
8387
}
84-
88+
8589
void Loop() override { SUPER::frame_loop(); }
8690
FrameRef StartFrame() {
8791
return active_buffer_;
8892
}
93+
8994
private:
9095
int next_buffer() {
9196
for (size_t b = 0; b < NBUF; b++) if (fb_[b].refs == 0) return b;
@@ -98,11 +103,10 @@ class InMemoryDisplay : public RGB565Frame<WIDTH, HEIGHT, LAYERS>, public Looper
98103
FB fb_[NBUF];
99104
};
100105

101-
102106
// TODO: Move to common/malloc_helper.h
103107

104-
#define NAME_INSTANCE(I, T) \
105-
struct T; \
108+
#define NAME_INSTANCE(I, T) \
109+
struct T; \
106110
auto getInstance(T*) -> decltype(& I) { return & I; }
107111

108112
template<class I, bool ZZ=true, int rot=0>
@@ -116,10 +120,12 @@ typedef typename std::remove_reference<decltype( *getInstance((I*)0) )>::type Di
116120
void run(BladeBase* blade) {
117121
frame_ = getInstance((I*)0)->StartFrame();
118122
}
123+
119124
SimpleColor getColor(int x, int y) {
120125
if (x > (int)W || y > (int)H || !frame_) return Color16(0,0,0);
121126
return frame_->getColor(x, y);
122127
}
128+
123129
SimpleColor getColor(int led) {
124130
int x = led % W;
125131
int y = led / W;
@@ -128,6 +134,7 @@ typedef typename std::remove_reference<decltype( *getInstance((I*)0) )>::type Di
128134
if (rot & 2) y = H - y;
129135
return (rot & 4) ? getColor(y, x) : getColor(x, y);
130136
}
137+
131138
private:
132139
FrameRef frame_;
133140
};

0 commit comments

Comments
 (0)