Frame Level Language for controlling DUALSHOCK2

Dependents:   koibumi2000

Committer:
amutake
Date:
Thu Feb 19 06:59:49 2015 +0000
Revision:
0:a436e2063a3d
Child:
1:905fe1a0ca5a
fll is now a library

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 0:a436e2063a3d 45 // human friendly source
amutake 0:a436e2063a3d 46 class EasySource : public Producer
amutake 0:a436e2063a3d 47 {
amutake 0:a436e2063a3d 48 private:
amutake 0:a436e2063a3d 49 button_time* bt_seq;
amutake 0:a436e2063a3d 50 int bt_size;
amutake 0:a436e2063a3d 51 int index;
amutake 0:a436e2063a3d 52 int frame_i;
amutake 0:a436e2063a3d 53 float lag;
amutake 0:a436e2063a3d 54 public:
amutake 0:a436e2063a3d 55 EasySource(button_time* seq, int size);
amutake 0:a436e2063a3d 56 virtual button_t await();
amutake 0:a436e2063a3d 57 virtual bool is_finished();
amutake 0:a436e2063a3d 58 virtual void reset();
amutake 0:a436e2063a3d 59 };
amutake 0:a436e2063a3d 60
amutake 0:a436e2063a3d 61 // -----
amutake 0:a436e2063a3d 62 // Flows
amutake 0:a436e2063a3d 63 // -----
amutake 0:a436e2063a3d 64 // `Flow` is a N inputs producer
amutake 0:a436e2063a3d 65
amutake 0:a436e2063a3d 66 // abstract class for N inputs producer
amutake 0:a436e2063a3d 67 class FoldFlow : public Producer
amutake 0:a436e2063a3d 68 {
amutake 0:a436e2063a3d 69 private:
amutake 0:a436e2063a3d 70 Producer** sources;
amutake 0:a436e2063a3d 71 int sources_size;
amutake 0:a436e2063a3d 72 public:
amutake 0:a436e2063a3d 73 FoldFlow(Producer **srcs, int srcs_size);
amutake 0:a436e2063a3d 74 virtual button_t fold(button_t *bs, int bs_size) = 0;
amutake 0:a436e2063a3d 75 virtual button_t await();
amutake 0:a436e2063a3d 76 virtual bool is_finished();
amutake 0:a436e2063a3d 77 virtual void reset();
amutake 0:a436e2063a3d 78 };
amutake 0:a436e2063a3d 79
amutake 0:a436e2063a3d 80 // merge N streams
amutake 0:a436e2063a3d 81 // Example:
amutake 0:a436e2063a3d 82 // [ Up, Right, Down, ... ]
amutake 0:a436e2063a3d 83 // +--- MergeFlow ---> [ Up|Circle, Right, Down|Triangle, Up, Right|Circle, ... ]
amutake 0:a436e2063a3d 84 // [ Circle, none, Triangle, none, ... ]
amutake 0:a436e2063a3d 85 class MergeFlow : public FoldFlow
amutake 0:a436e2063a3d 86 {
amutake 0:a436e2063a3d 87 public:
amutake 0:a436e2063a3d 88 MergeFlow(Producer **srcs, int srcs_size) : FoldFlow(srcs, srcs_size) {}
amutake 0:a436e2063a3d 89 virtual button_t fold(button_t *bs, int bs_size);
amutake 0:a436e2063a3d 90 };
amutake 0:a436e2063a3d 91
amutake 0:a436e2063a3d 92 // 1 input, 1 output
amutake 0:a436e2063a3d 93 // delay input source
amutake 0:a436e2063a3d 94 class DelayFlow : public Producer
amutake 0:a436e2063a3d 95 {
amutake 0:a436e2063a3d 96 private:
amutake 0:a436e2063a3d 97 Producer* source;
amutake 0:a436e2063a3d 98 float delay; // sec
amutake 0:a436e2063a3d 99 float passing;
amutake 0:a436e2063a3d 100 bool end;
amutake 0:a436e2063a3d 101 public:
amutake 0:a436e2063a3d 102 DelayFlow(Producer *src, float d);
amutake 0:a436e2063a3d 103 virtual button_t await();
amutake 0:a436e2063a3d 104 virtual bool is_finished();
amutake 0:a436e2063a3d 105 virtual void reset();
amutake 0:a436e2063a3d 106 };
amutake 0:a436e2063a3d 107
amutake 0:a436e2063a3d 108 // use sources sequentially
amutake 0:a436e2063a3d 109 class SequentialFlow : public Producer
amutake 0:a436e2063a3d 110 {
amutake 0:a436e2063a3d 111 private:
amutake 0:a436e2063a3d 112 Producer** sources;
amutake 0:a436e2063a3d 113 int sources_size;
amutake 0:a436e2063a3d 114 int index;
amutake 0:a436e2063a3d 115 public:
amutake 0:a436e2063a3d 116 SequentialFlow(Producer **srcs, int srcs_size);
amutake 0:a436e2063a3d 117 virtual button_t await();
amutake 0:a436e2063a3d 118 virtual bool is_finished();
amutake 0:a436e2063a3d 119 virtual void reset();
amutake 0:a436e2063a3d 120 };
amutake 0:a436e2063a3d 121
amutake 0:a436e2063a3d 122 // 1 input, 1 output
amutake 0:a436e2063a3d 123 // repeats upstream
amutake 0:a436e2063a3d 124 class RepeaterFlow : public Producer
amutake 0:a436e2063a3d 125 {
amutake 0:a436e2063a3d 126 private:
amutake 0:a436e2063a3d 127 Producer* source;
amutake 0:a436e2063a3d 128 public:
amutake 0:a436e2063a3d 129 RepeaterFlow(Producer *src);
amutake 0:a436e2063a3d 130 virtual button_t await();
amutake 0:a436e2063a3d 131 virtual bool is_finished();
amutake 0:a436e2063a3d 132 virtual void reset();
amutake 0:a436e2063a3d 133 };
amutake 0:a436e2063a3d 134
amutake 0:a436e2063a3d 135 // 1 input, 1 output
amutake 0:a436e2063a3d 136 // expands upstream N times
amutake 0:a436e2063a3d 137 class ExpanderFlow : public Producer
amutake 0:a436e2063a3d 138 {
amutake 0:a436e2063a3d 139 private:
amutake 0:a436e2063a3d 140 Producer* source;
amutake 0:a436e2063a3d 141 int n_times;
amutake 0:a436e2063a3d 142 int counter;
amutake 0:a436e2063a3d 143 button_t now;
amutake 0:a436e2063a3d 144 bool finished;
amutake 0:a436e2063a3d 145 public:
amutake 0:a436e2063a3d 146 ExpanderFlow(Producer* src, int n);
amutake 0:a436e2063a3d 147 virtual button_t await();
amutake 0:a436e2063a3d 148 virtual bool is_finished();
amutake 0:a436e2063a3d 149 virtual void reset();
amutake 0:a436e2063a3d 150 };