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.
Fork of BlinkLed by
Revision 1:54071e781f77, committed 2012-09-01
- Comitter:
- togayan
- Date:
- Sat Sep 01 11:08:44 2012 +0000
- Parent:
- 0:a55a3351317d
- Child:
- 2:1d0c09c1a8b4
- Commit message:
- Use signal to stop blinking
Changed in this revision
| BlinkLed.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/BlinkLed.cpp Sat Sep 01 04:02:02 2012 +0000
+++ b/BlinkLed.cpp Sat Sep 01 11:08:44 2012 +0000
@@ -1,10 +1,10 @@
#include "BlinkLed.h"
-
+
BlinkLed::BlinkLed(PinName pin, float dutyChangeStep) :
-led(pin),
-dutyChangeStep(dutyChangeStep),
-pause(true),
-thread(0)
+ led(pin),
+ dutyChangeStep(dutyChangeStep),
+ pause(true),
+ thread(0)
{
}
@@ -15,10 +15,11 @@
void BlinkLed::startBlink()
{
pause = false;
- if(thread == 0)
+ if(!thread)
{
thread = new Thread(blink, this, osPriorityNormal, 128, NULL);
}
+ thread->signal_set(1);
}
void BlinkLed::finishBlink()
@@ -29,20 +30,18 @@
void BlinkLed::blink(void const *argument)
{
BlinkLed* self = (BlinkLed*)argument;
-
+
bool sign = false;
- while (1)
+ while(1)
{
if(self->pause)
{
self->led = 0.0F;
+ Thread::signal_wait(1);
}
- else
- {
- float brightness = self->led;
- sign = (brightness <= 0.0F) ? true : (1.0F <= brightness) ? false : sign;
- self->led = sign ? brightness + self->dutyChangeStep : brightness - self->dutyChangeStep;
- }
+ float brightness = self->led;
+ sign = (brightness <= 0.0F) ? true : (1.0F <= brightness) ? false : sign;
+ self->led = sign ? brightness + self->dutyChangeStep : brightness - self->dutyChangeStep;
Thread::wait(20);
}
}
