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: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
Diff: io/DeviceFeedback.cpp
- Revision:
- 67:c360a2b2c948
- Parent:
- 65:a62dbef2f924
- Child:
- 71:063c45e99578
--- a/io/DeviceFeedback.cpp Thu Oct 30 14:46:22 2014 +0000
+++ b/io/DeviceFeedback.cpp Sun Nov 30 19:34:49 2014 +0000
@@ -2,8 +2,10 @@
#include <stdlib.h>
#include <string.h>
-#define MSG_CLOSE_RELAY 1
-#define MSG_OPEN_RELAY 2
+#define MSG_BEEP_SUCCESS 1
+#define MSG_BEEP_FAILURE 2
+#define MSG_CLOSE_RELAY 3
+#define MSG_OPEN_RELAY 4
DeviceFeedback::DeviceFeedback(PwmOut speaker) :
_speaker(speaker),
@@ -11,22 +13,33 @@
{
}
+void DeviceFeedback::beepSuccess()
+{
+ sendMessage(MSG_BEEP_SUCCESS);
+}
+
+void DeviceFeedback::beepFailure()
+{
+ sendMessage(MSG_BEEP_FAILURE);
+}
+
void DeviceFeedback::closeRelay()
{
- uint8_t *msg;
-
- msg = _mail.alloc();
- *msg = MSG_CLOSE_RELAY;
- _mail.put(msg);
+ sendMessage(MSG_CLOSE_RELAY);
}
void DeviceFeedback::openRelay()
{
- uint8_t *msg;
+ sendMessage(MSG_OPEN_RELAY);
+}
+
+void DeviceFeedback::sendMessage(uint8_t msg)
+{
+ uint8_t *msgPtr;
- msg = _mail.alloc();
- *msg = MSG_OPEN_RELAY;
- _mail.put(msg);
+ msgPtr = _mail.alloc();
+ *msgPtr = msg;
+ _mail.put(msgPtr);
}
void DeviceFeedback::thread()
@@ -38,6 +51,24 @@
if ((evt = _mail.get(1000)).status == osEventMail) {
msg = (uint8_t*)evt.value.p;
switch (*msg) {
+ case MSG_BEEP_SUCCESS:
+ for (float i=2000.0; i<10000.0; i+=2000.0) {
+ _speaker.period(1.0/i);
+ _speaker = 0.5;
+ Thread::wait(200);
+ _speaker = 0.0;
+ Thread::wait(50);
+ }
+ break;
+ case MSG_BEEP_FAILURE:
+ for (float i=10000.0; i>2000.0; i-=2000.0) {
+ _speaker.period(1.0/i);
+ _speaker = 0.5;
+ Thread::wait(200);
+ _speaker = 0.0;
+ Thread::wait(50);
+ }
+ break;
case MSG_CLOSE_RELAY:
if (!relayState) {
relayState = true;
