Shohei Yasutake / Mbed 2 deprecated koibumi2000

Dependencies:   fll mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
amutake
Date:
Sat Feb 14 16:39:53 2015 +0000
Parent:
6:d0348b7a2f05
Child:
8:d16a0fcc2735
Commit message:
English comments

Changed in this revision

fll.cpp Show annotated file Show diff for this revision Revisions of this file
fll.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/fll.cpp	Sat Feb 14 08:02:21 2015 +0000
+++ b/fll.cpp	Sat Feb 14 16:39:53 2015 +0000
@@ -4,14 +4,14 @@
 #include "mbed.h"
 #include "rtos.h"
 #include <stdint.h>
-#include <vector>
 #include "fll.h"
 
-Serial pc(USBTX, USBRX);
+// if you want to debug by `printf`, uncomment next line and put `pc.printf("...", ...);` into certain position.
+// Serial pc(USBTX, USBRX);
 
-// ------
+// --------------
 // RepeaterSource
-// ------
+// --------------
 RepeaterSource::RepeaterSource(button_t *bs, int s)
 {
     button_seq = bs;
@@ -29,9 +29,9 @@
     return button_seq[i++];
 }
 
-// ----
+// --------
 // FoldFlow
-// ----
+// --------
 FoldFlow::FoldFlow(Producer **srcs, int srcs_size) {
     sources = srcs;
     sources_size = srcs_size;
@@ -78,7 +78,7 @@
 void Sink::reset(Producer* src)
 {
     mutex->lock();
-    // queue を空にする
+    // consume current (and actually old) buffer
     osEvent e;
     do {
         e = mail_box->get(0);
@@ -86,7 +86,7 @@
             mail_box->free((button_t*)e.value.p);
         }
     } while (e.status == osEventMail);
-    // source の更新
+    // update source
     source = src;
     mutex->unlock();
 }
@@ -102,38 +102,18 @@
 void Output::run()
 {
     osEvent e = mail_box->get(0);
-    if (e.status == osEventMail) {
+    if (e.status == osEventMail) { // getting is success 
         button_t b = *(button_t*)(e.value.p);
         mail_box->free((button_t*)e.value.p);
         press(b);
     } else {
-        press(0); // Mail になかった
+        press(0); // if mail box is empty
     }
 }
 
-// fll_keymap.cpp
-//
-// | uint16 bit | button_t | mbed pin | low/high |
-// +------------+--------+----------+----------+
-// |     0x0000 |        |          |          |
-// |     0x0000 |        |          |          |
-// |     0x0000 |        |          |          |
-// |     0x0000 |        |          |          |
-// |     0x0000 |        |          |          |
-// |     0x0000 |        |          |          |
-// |     0x0000 |        |          |          |
-// |     0x0000 |        |          |          |
-// |     0x0000 |        |          |          |
-// |     0x0000 |        |          |          |
-// |     0x0000 |        |          |          |
-// |     0x0000 |        |          |          |
-// |     0x0000 |        |          |          |
-// |     0x0000 |        |          |          |
-// +------------+--------+----------+----------+
-//
-// Examples:
-//   0000 0000 0000 0000 === nothing is pressed
-//   0010 0100 1000 0001 === ?, ?, ? and ? are pressed
+// --------------------
+// button_t -> mbed pin
+// --------------------
 typedef struct _table {
     button_t mask; // 0000 0000 0000 0001 ~ 0010 0000 0000 0000
     DigitalOut *pin; // pin5~pin19
@@ -156,27 +136,25 @@
 DigitalOut pinL1(p19);
 DigitalOut pinL2(p14);
 
+// button-pin mapping table
 table tables[] = {
     { R1, &pinR1, 0 },
-    { B_TRIANGLE, &pinTriangle, 0 },
-    { B_CIRCLE, &pinCircle, 0 },
-    { B_CROSS, &pinCross, 0 },
-    { B_SQUARE, &pinSquare, 0 },
-    { B_R2, &pinR2, 0 },
-    { B_START, &pinStart, 0 },
-    { B_ANALOG, &pinAnalog, 0 },
-    { B_SELECT, &pinSelect, 0 },
-    { B_L2, &pinL2, 0 },
-    { B_UP, &pinUp, 0 },
-    { B_DOWN, &pinDown, 0 },
-    { B_LEFT, &pinLeft, 0 },
-    { B_RIGHT, &pinRight, 0 },
-    { B_L1, &pinL1, 0 }
+    { TRIANGLE, &pinTriangle, 0 },
+    { CIRCLE, &pinCircle, 0 },
+    { CROSS, &pinCross, 0 },
+    { SQUARE, &pinSquare, 0 },
+    { R2, &pinR2, 0 },
+    { START, &pinStart, 0 },
+    { ANALOG, &pinAnalog, 0 },
+    { SELECT, &pinSelect, 0 },
+    { L2, &pinL2, 0 },
+    { UP, &pinUp, 0 },
+    { DOWN, &pinDown, 0 },
+    { LEFT, &pinLeft, 0 },
+    { RIGHT, &pinRight, 0 },
+    { L1, &pinL1, 0 }
 };
 
-// pc.printf("0x%02x\n", btn);
-
-// 押されるボタンを押す
 void press(button_t btn)
 {
     table t;
--- a/fll.h	Sat Feb 14 08:02:21 2015 +0000
+++ b/fll.h	Sat Feb 14 16:39:53 2015 +0000
@@ -1,39 +1,41 @@
 // Frame Level Language
-// header
+// interface
 
 #include "mbed.h"
 #include "rtos.h"
 #include <stdint.h>
-#include <vector>
 
+// buttons represented by 16 bit 
 #define R1 0x0001
-#define B_TRIANGLE 0x0002
-#define B_CIRCLE 0x0004
-#define B_CROSS 0x0008
-#define B_SQUARE 0x0010
-#define B_R2 0x0020
-#define B_START 0x0040
-#define B_ANALOG 0x0080
-#define B_SELECT 0x0100
-#define B_L2 0x0200
-#define B_UP 0x0400
-#define B_DOWN 0x0800
-#define B_LEFT 0x1000
-#define B_RIGHT 0x2000
-#define B_L1 0x4000
+#define TRIANGLE 0x0002
+#define CIRCLE 0x0004
+#define CROSS 0x0008
+#define SQUARE 0x0010
+#define R2 0x0020
+#define START 0x0040
+#define ANALOG 0x0080
+#define SELECT 0x0100
+#define L2 0x0200
+#define UP 0x0400
+#define DOWN 0x0800
+#define LEFT 0x1000
+#define RIGHT 0x2000
+#define L1 0x4000
 
 #define MAIL_BOX_SIZE 16
 
 typedef uint16_t button_t;
 
 // Base object for stream network
-class Producer {
+class Producer
+{
 public:
     virtual button_t await() = 0;
 };
 
-// 0 input
-class RepeaterSource : public Producer {
+// 0 input and repeat given button sequence
+class RepeaterSource : public Producer
+{
 private:
     int i;
     button_t* button_seq;
@@ -44,7 +46,8 @@
 };
 
 // N inputs
-class FoldFlow : public Producer {
+class FoldFlow : public Producer
+{
 private:
     Producer** sources;
     int sources_size;
@@ -54,7 +57,8 @@
     virtual button_t await();
 };
 
-// ストリームの終端になっていて、キー入力をするスレッドに向けてキーを送る
+// Sink is the end of button stream network
+// It sends next button to Output object through rtos::Mail
 class Sink
 {
 private:
@@ -67,7 +71,8 @@
     void reset(Producer* src);
 };
 
-
+// Output reads the next button from mail box and press the button
+// It must be run per 1/60 sec
 class Output
 {
 private:
@@ -77,4 +82,5 @@
     void run();
 };
 
-void press(button_t btn);
+// tells dualshock2 circuit which button is pressed
+void press(button_t btn);
\ No newline at end of file
--- a/main.cpp	Sat Feb 14 08:02:21 2015 +0000
+++ b/main.cpp	Sat Feb 14 16:39:53 2015 +0000
@@ -4,6 +4,9 @@
 
 #define FRAME 1.0 / 60 // 1 frame (sec)
 
+// [ Up, Right, Down, ... ] 
+//     +--- OrFoldFlow ---> [ Up|Circle, Right, Down|Triangle, Up, Right|Circle, ... ]
+// [ Circle, none, Triangle, none, ... ]
 class OrFoldFlow : public FoldFlow {
     public:
     OrFoldFlow(Producer **srcs, int srcs_size) : FoldFlow(srcs, srcs_size) {}
@@ -19,16 +22,13 @@
 void invoke_sinkrun(const void *p) {
     ((Sink*)p)->run();
 }
-void outputrun(const void *p)
-{
-    ((Output*)p)->run();
-}
 
 int main(void)
 {
     button_t array0[] = {R1, 0};
-    button_t array1[] = {B_CIRCLE, 0};
-    // user must make Source
+    button_t array1[] = {CIRCLE, 0};
+
+    // fll user must make a Producer
     Producer* source0 = new RepeaterSource(array0, sizeof(array0)/sizeof(button_t));
     Producer* source1 = new RepeaterSource(array1, sizeof(array1)/sizeof(button_t));
     Producer* ss[] = {source0, source1};