Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: fll mbed-rtos mbed
Diff: fll.cpp
- Revision:
- 3:edbf31a8589f
- Parent:
- 2:165723d41023
- Child:
- 4:9ee673ca05ad
--- a/fll.cpp Sat Feb 14 04:49:28 2015 +0000
+++ b/fll.cpp Sat Feb 14 06:39:14 2015 +0000
@@ -12,33 +12,33 @@
// ------
// Source
// ------
-Source::Source(button *bs, int s, bool l)
+Source::Source(button_t *bs, int s, bool l)
{
- button_seq = bs;
+ button_t_seq = bs;
size = s;
loop = l;
i = 0;
}
// TODO: without loop
-button Source::await()
+button_t Source::await()
{
+
if (size == 0) {
return 0;
- }
-
+ }
i = i % size;
- return button_seq[i++];
+ return button_t_seq[i++];
}
// ----
// Flow
// ----
-button Flow::await()
+button_t Flow::await()
{
- std::vector<button> bs;
+ std::vector<button_t> bs;
for (int k = 0; k < sources.size(); k++) {
- button b = sources[k]->await();
+ button_t b = sources[k]->await();
bs.push_back(b);
}
return fold(bs);
@@ -48,7 +48,7 @@
// ----
// Sink
// ----
-Sink::Sink(Source* src, rtos::Mail<button, MAIL_BOX_SIZE>* box, Mutex* mut)
+Sink::Sink(Source* src, rtos::Mail<button_t, MAIL_BOX_SIZE>* box, Mutex* mut)
{
source = src;
mail_box = box;
@@ -58,9 +58,10 @@
// 何ミリ秒かごとに呼ばれる
void Sink::run()
{
+ button_t *btn;
for (int i = 0; i < 8; i++) { // FIXME: 8?
mutex->lock();
- button* btn = mail_box->alloc();
+ btn = mail_box->alloc();
if(!btn) break;
*btn = source->await();
mail_box->put(btn);
@@ -76,7 +77,7 @@
do {
e = mail_box->get(0);
if(e.status == osEventMail) {
- mail_box->free((button*)e.value.p);
+ mail_box->free((button_t*)e.value.p);
}
} while (e.status == osEventMail);
// source の更新
@@ -87,7 +88,7 @@
// ------
// Output
// ------
-Output::Output(rtos::Mail<button, MAIL_BOX_SIZE>* box)
+Output::Output(rtos::Mail<button_t, MAIL_BOX_SIZE>* box)
{
mail_box = box;
}
@@ -96,9 +97,9 @@
{
osEvent e = mail_box->get(0);
if (e.status == osEventMail) {
- button b = *(button*)(e.value.p);
+ button_t b = *(button_t*)(e.value.p);
+ mail_box->free((button_t*)e.value.p);
press(b);
- mail_box->free((button*)e.value.p);
} else {
press(0); // Mail になかった
}
@@ -106,7 +107,7 @@
// fll_keymap.cpp
//
-// | uint16 bit | button | mbed pin | low/high |
+// | uint16 bit | button_t | mbed pin | low/high |
// +------------+--------+----------+----------+
// | 0x0000 | | | |
// | 0x0000 | | | |
@@ -128,7 +129,7 @@
// 0000 0000 0000 0000 === nothing is pressed
// 0010 0100 1000 0001 === ?, ?, ? and ? are pressed
typedef struct _table {
- button mask; // 0000 0000 0000 0001 ~ 0010 0000 0000 0000
+ button_t mask; // 0000 0000 0000 0001 ~ 0010 0000 0000 0000
DigitalOut *pin; // pin5~pin19
int on; // 1 or 0
} table;
@@ -170,10 +171,11 @@
// pc.printf("0x%02x\n", btn);
// 押されるボタンを押す
-void press(button btn)
+void press(button_t btn)
{
+ table t;
for (int i = 0; i < sizeof(tables)/sizeof(table); i++) {
- table t = tables[i];
+ t = tables[i];
if (btn & t.mask) {
t.pin->write(t.on);
} else {
