Frame Level Language for controlling DUALSHOCK2

Dependents:   koibumi2000

Committer:
amutake
Date:
Thu Feb 19 13:47:15 2015 +0000
Revision:
1:905fe1a0ca5a
Parent:
0:a436e2063a3d
Change logic of EasySource

Who changed what in which revision?

UserRevisionLine numberNew contents of line
amutake 0:a436e2063a3d 1 // utility producers
amutake 0:a436e2063a3d 2
amutake 0:a436e2063a3d 3 #pragma once
amutake 0:a436e2063a3d 4
amutake 0:a436e2063a3d 5 #include "fll.h"
amutake 0:a436e2063a3d 6
amutake 0:a436e2063a3d 7 // -------
amutake 0:a436e2063a3d 8 // Sources
amutake 0:a436e2063a3d 9 // -------
amutake 0:a436e2063a3d 10 // `Source` is a 0 input producer
amutake 0:a436e2063a3d 11
amutake 0:a436e2063a3d 12 // yields given button sequence exactly once
amutake 0:a436e2063a3d 13 class OnetimeSource : public Producer
amutake 0:a436e2063a3d 14 {
amutake 0:a436e2063a3d 15 private:
amutake 0:a436e2063a3d 16 int i;
amutake 0:a436e2063a3d 17 button_t* button_seq;
amutake 0:a436e2063a3d 18 int size;
amutake 0:a436e2063a3d 19 public:
amutake 0:a436e2063a3d 20 OnetimeSource(button_t *bs, int s);
amutake 0:a436e2063a3d 21 virtual button_t await();
amutake 0:a436e2063a3d 22 virtual bool is_finished();
amutake 0:a436e2063a3d 23 virtual void reset();
amutake 0:a436e2063a3d 24 };
amutake 0:a436e2063a3d 25
amutake 0:a436e2063a3d 26 // 0 input and infinitely yields given button sequence
amutake 0:a436e2063a3d 27 class RepeaterSource : public Producer
amutake 0:a436e2063a3d 28 {
amutake 0:a436e2063a3d 29 private:
amutake 0:a436e2063a3d 30 int i;
amutake 0:a436e2063a3d 31 button_t* button_seq;
amutake 0:a436e2063a3d 32 int size;
amutake 0:a436e2063a3d 33 public:
amutake 0:a436e2063a3d 34 RepeaterSource(button_t *bs, int s);
amutake 0:a436e2063a3d 35 virtual button_t await();
amutake 0:a436e2063a3d 36 virtual bool is_finished();
amutake 0:a436e2063a3d 37 virtual void reset();
amutake 0:a436e2063a3d 38 };
amutake 0:a436e2063a3d 39
amutake 0:a436e2063a3d 40 typedef struct _button_time {
amutake 0:a436e2063a3d 41 button_t button;
amutake 0:a436e2063a3d 42 float sec;
amutake 0:a436e2063a3d 43 } button_time; // TODO: rename
amutake 0:a436e2063a3d 44
amutake 1:905fe1a0ca5a 45 button_time single(button_t btn);
amutake 1:905fe1a0ca5a 46 button_time hold(button_t btn, float sec);
amutake 1:905fe1a0ca5a 47 button_time space(float sec);
amutake 1:905fe1a0ca5a 48
amutake 0:a436e2063a3d 49 // human friendly source
amutake 0:a436e2063a3d 50 class EasySource : public Producer
amutake 0:a436e2063a3d 51 {
amutake 0:a436e2063a3d 52 private:
amutake 0:a436e2063a3d 53 button_time* bt_seq;
amutake 0:a436e2063a3d 54 int bt_size;
amutake 0:a436e2063a3d 55 int index;
amutake 0:a436e2063a3d 56 int frame_i;
amutake 1:905fe1a0ca5a 57 bool spacing;
amutake 1:905fe1a0ca5a 58 int space_frame;
amutake 0:a436e2063a3d 59 public:
amutake 0:a436e2063a3d 60 EasySource(button_time* seq, int size);
amutake 1:905fe1a0ca5a 61 EasySource(button_time* seq, int size, int spacer); // spacer is the number of frame
amutake 0:a436e2063a3d 62 virtual button_t await();
amutake 0:a436e2063a3d 63 virtual bool is_finished();
amutake 0:a436e2063a3d 64 virtual void reset();
amutake 0:a436e2063a3d 65 };
amutake 0:a436e2063a3d 66
amutake 0:a436e2063a3d 67 // -----
amutake 0:a436e2063a3d 68 // Flows
amutake 0:a436e2063a3d 69 // -----
amutake 0:a436e2063a3d 70 // `Flow` is a N inputs producer
amutake 0:a436e2063a3d 71
amutake 0:a436e2063a3d 72 // abstract class for N inputs producer
amutake 0:a436e2063a3d 73 class FoldFlow : public Producer
amutake 0:a436e2063a3d 74 {
amutake 0:a436e2063a3d 75 private:
amutake 0:a436e2063a3d 76 Producer** sources;
amutake 0:a436e2063a3d 77 int sources_size;
amutake 0:a436e2063a3d 78 public:
amutake 0:a436e2063a3d 79 FoldFlow(Producer **srcs, int srcs_size);
amutake 0:a436e2063a3d 80 virtual button_t fold(button_t *bs, int bs_size) = 0;
amutake 0:a436e2063a3d 81 virtual button_t await();
amutake 0:a436e2063a3d 82 virtual bool is_finished();
amutake 0:a436e2063a3d 83 virtual void reset();
amutake 0:a436e2063a3d 84 };
amutake 0:a436e2063a3d 85
amutake 0:a436e2063a3d 86 // merge N streams
amutake 0:a436e2063a3d 87 // Example:
amutake 0:a436e2063a3d 88 // [ Up, Right, Down, ... ]
amutake 0:a436e2063a3d 89 // +--- MergeFlow ---> [ Up|Circle, Right, Down|Triangle, Up, Right|Circle, ... ]
amutake 0:a436e2063a3d 90 // [ Circle, none, Triangle, none, ... ]
amutake 0:a436e2063a3d 91 class MergeFlow : public FoldFlow
amutake 0:a436e2063a3d 92 {
amutake 0:a436e2063a3d 93 public:
amutake 0:a436e2063a3d 94 MergeFlow(Producer **srcs, int srcs_size) : FoldFlow(srcs, srcs_size) {}
amutake 0:a436e2063a3d 95 virtual button_t fold(button_t *bs, int bs_size);
amutake 0:a436e2063a3d 96 };
amutake 0:a436e2063a3d 97
amutake 0:a436e2063a3d 98 // 1 input, 1 output
amutake 0:a436e2063a3d 99 // delay input source
amutake 0:a436e2063a3d 100 class DelayFlow : public Producer
amutake 0:a436e2063a3d 101 {
amutake 0:a436e2063a3d 102 private:
amutake 0:a436e2063a3d 103 Producer* source;
amutake 0:a436e2063a3d 104 float delay; // sec
amutake 0:a436e2063a3d 105 float passing;
amutake 0:a436e2063a3d 106 bool end;
amutake 0:a436e2063a3d 107 public:
amutake 0:a436e2063a3d 108 DelayFlow(Producer *src, float d);
amutake 0:a436e2063a3d 109 virtual button_t await();
amutake 0:a436e2063a3d 110 virtual bool is_finished();
amutake 0:a436e2063a3d 111 virtual void reset();
amutake 0:a436e2063a3d 112 };
amutake 0:a436e2063a3d 113
amutake 0:a436e2063a3d 114 // use sources sequentially
amutake 0:a436e2063a3d 115 class SequentialFlow : public Producer
amutake 0:a436e2063a3d 116 {
amutake 0:a436e2063a3d 117 private:
amutake 0:a436e2063a3d 118 Producer** sources;
amutake 0:a436e2063a3d 119 int sources_size;
amutake 0:a436e2063a3d 120 int index;
amutake 0:a436e2063a3d 121 public:
amutake 0:a436e2063a3d 122 SequentialFlow(Producer **srcs, int srcs_size);
amutake 0:a436e2063a3d 123 virtual button_t await();
amutake 0:a436e2063a3d 124 virtual bool is_finished();
amutake 0:a436e2063a3d 125 virtual void reset();
amutake 0:a436e2063a3d 126 };
amutake 0:a436e2063a3d 127
amutake 0:a436e2063a3d 128 // 1 input, 1 output
amutake 0:a436e2063a3d 129 // repeats upstream
amutake 0:a436e2063a3d 130 class RepeaterFlow : public Producer
amutake 0:a436e2063a3d 131 {
amutake 0:a436e2063a3d 132 private:
amutake 0:a436e2063a3d 133 Producer* source;
amutake 0:a436e2063a3d 134 public:
amutake 0:a436e2063a3d 135 RepeaterFlow(Producer *src);
amutake 0:a436e2063a3d 136 virtual button_t await();
amutake 0:a436e2063a3d 137 virtual bool is_finished();
amutake 0:a436e2063a3d 138 virtual void reset();
amutake 0:a436e2063a3d 139 };
amutake 0:a436e2063a3d 140
amutake 0:a436e2063a3d 141 // 1 input, 1 output
amutake 0:a436e2063a3d 142 // expands upstream N times
amutake 0:a436e2063a3d 143 class ExpanderFlow : public Producer
amutake 0:a436e2063a3d 144 {
amutake 0:a436e2063a3d 145 private:
amutake 0:a436e2063a3d 146 Producer* source;
amutake 0:a436e2063a3d 147 int n_times;
amutake 0:a436e2063a3d 148 int counter;
amutake 0:a436e2063a3d 149 button_t now;
amutake 0:a436e2063a3d 150 bool finished;
amutake 0:a436e2063a3d 151 public:
amutake 0:a436e2063a3d 152 ExpanderFlow(Producer* src, int n);
amutake 0:a436e2063a3d 153 virtual button_t await();
amutake 0:a436e2063a3d 154 virtual bool is_finished();
amutake 0:a436e2063a3d 155 virtual void reset();
amutake 0:a436e2063a3d 156 };