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:
- 1:1abcd83947bf
- Parent:
- 0:c80e972b4c59
- Child:
- 2:165723d41023
--- a/fll.cpp Fri Feb 13 13:19:29 2015 +0000
+++ b/fll.cpp Fri Feb 13 14:41:00 2015 +0000
@@ -7,12 +7,15 @@
#include <vector>
#include "fll.h"
+Serial pc(USBTX, USBRX);
+
// ------
// Source
// ------
-Source::Source(std::vector<button>* bs, bool l)
+Source::Source(button *bs, int s, bool l)
{
button_seq = bs;
+ size = s;
loop = l;
i = 0;
}
@@ -20,15 +23,12 @@
// TODO: without loop
button Source::await()
{
- int size = button_seq->size();
if (size == 0) {
return 0;
- } else if (i >= size) {
- i = 0;
- return button_seq->at(0);
- } else {
- return button_seq->at(i++);
- }
+ }
+
+ i = i % size;
+ return button_seq[i++];
}
// ----
@@ -44,34 +44,6 @@
return fold(bs);
}
-// -----
-// Carry
-// -----
-Carry::Carry()
-{
- btn = Carry::none;
-}
-
-bool Carry::is_empty()
-{
- if (btn & Carry::none) { // TODO: 冗長
- return true;
- } else {
- return false;
- }
-}
-button Carry::get()
-{
- return btn;
-}
-void Carry::set(button b)
-{
- btn = b;
-}
-void Carry::empty()
-{
- btn = Carry::none;
-}
// ----
// Sink
@@ -79,7 +51,6 @@
Sink::Sink(Source* src, rtos::Mail<button, QUEUE_SIZE>* q, Mutex* mut)
{
source = src;
- carry = new Carry();
queue = q;
queueMutex = mut;
}
@@ -88,20 +59,12 @@
void Sink::run()
{
for (int i = 0; i < 8; i++) { // FIXME: 8?
+ queueMutex->lock();
button* btn = queue->alloc();
- // carry がないならストリームから Pull
- if (carry->is_empty()) {
- *btn = source->await();
- } else {
- *btn = carry->get();
- }
- queueMutex->lock();
- osStatus status = queue->put(btn);
+ if(!btn) break;
+ *btn = source->await();
+ queue->put(btn);
queueMutex->unlock();
- if (status != osOK) {
- carry->set(*btn);
- break;
- }
}
}
@@ -111,8 +74,11 @@
// queue を空にする
osEvent e;
do {
- e = queue->get();
- } while (e.status == osOK);
+ e = queue->get(0);
+ if(e.status == osEventMail) {
+ queue->free((button*)e.value.p);
+ }
+ } while (e.status == osEventMail);
// source の更新
source = src;
queueMutex->unlock();
@@ -128,10 +94,11 @@
void Output::run()
{
- osEvent e = queue->get();
- if (e.status == osEventMessage) {
- button b = (button)e.value.v;
+ osEvent e = queue->get(0);
+ if (e.status == osEventMail) {
+ button b = *(button*)(e.value.p);
press(b);
+ queue->free((button*)e.value.p);
} else {
press(0); // Mail になかった
}
@@ -200,7 +167,6 @@
{ B_L1, &pinL1, 0 }
};
-// Serial pc(USBTX, USBRX);
// pc.printf("0x%02x\n", btn);
// 押されるボタンを押す
