RFID tracking with mbed & RS-EDP reference design

Dependencies:   RWDModule mbed SDCard

Committer:
donatien
Date:
Wed Jul 28 11:02:36 2010 +0000
Revision:
0:fd63457452f4

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:fd63457452f4 1 /*
donatien 0:fd63457452f4 2 Copyright (c) 2010 ARM Limited
donatien 0:fd63457452f4 3
donatien 0:fd63457452f4 4 Permission is hereby granted, free of charge, to any person obtaining a copy
donatien 0:fd63457452f4 5 of this software and associated documentation files (the "Software"), to deal
donatien 0:fd63457452f4 6 in the Software without restriction, including without limitation the rights
donatien 0:fd63457452f4 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
donatien 0:fd63457452f4 8 copies of the Software, and to permit persons to whom the Software is
donatien 0:fd63457452f4 9 furnished to do so, subject to the following conditions:
donatien 0:fd63457452f4 10
donatien 0:fd63457452f4 11 The above copyright notice and this permission notice shall be included in
donatien 0:fd63457452f4 12 all copies or substantial portions of the Software.
donatien 0:fd63457452f4 13
donatien 0:fd63457452f4 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
donatien 0:fd63457452f4 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
donatien 0:fd63457452f4 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
donatien 0:fd63457452f4 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
donatien 0:fd63457452f4 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
donatien 0:fd63457452f4 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
donatien 0:fd63457452f4 20 THE SOFTWARE.
donatien 0:fd63457452f4 21 */
donatien 0:fd63457452f4 22
donatien 0:fd63457452f4 23 #include "mbed.h"
donatien 0:fd63457452f4 24 #include "beep.h"
donatien 0:fd63457452f4 25
donatien 0:fd63457452f4 26 Beep::Beep(PinName pin) : m_ticker(), m_timeout(), m_out(pin)
donatien 0:fd63457452f4 27 {
donatien 0:fd63457452f4 28 m_part = NULL;
donatien 0:fd63457452f4 29 m_pos = 0;
donatien 0:fd63457452f4 30 }
donatien 0:fd63457452f4 31
donatien 0:fd63457452f4 32 Beep::~Beep()
donatien 0:fd63457452f4 33 {
donatien 0:fd63457452f4 34
donatien 0:fd63457452f4 35 }
donatien 0:fd63457452f4 36
donatien 0:fd63457452f4 37 //Tones data is { freq1 (Hz), length1 (s), ... }
donatien 0:fd63457452f4 38 //For a pause, frequency is set to 0
donatien 0:fd63457452f4 39 //If length=0, end of tone
donatien 0:fd63457452f4 40 const float Beep::Tones[][8] = { {523.25, 0.025, 783.99, 0.075, 0, 0}, //TONE_OK,
donatien 0:fd63457452f4 41 {440, 0.050, 0, 0}, //TONE_INFO,
donatien 0:fd63457452f4 42 {220, 0.100, 0, 0}, //TONE_WARN,
donatien 0:fd63457452f4 43 {110, 0.250, 0, 0} //TONE_ERR
donatien 0:fd63457452f4 44 };
donatien 0:fd63457452f4 45
donatien 0:fd63457452f4 46 void Beep::beep(BEEP_TONE tone) //New beep
donatien 0:fd63457452f4 47 {
donatien 0:fd63457452f4 48 m_ticker.detach(); //Stop previous beep is existing
donatien 0:fd63457452f4 49 m_timeout.detach();
donatien 0:fd63457452f4 50 m_part = (float*) Beep::Tones[tone]; //Select tone buf
donatien 0:fd63457452f4 51 m_pos = 0;
donatien 0:fd63457452f4 52 beepNote(); //Start with first note
donatien 0:fd63457452f4 53 }
donatien 0:fd63457452f4 54
donatien 0:fd63457452f4 55 void Beep::beepNote()
donatien 0:fd63457452f4 56 {
donatien 0:fd63457452f4 57 float freq = m_part[m_pos]; //Setup frequency and length
donatien 0:fd63457452f4 58 float len = m_part[m_pos+1];
donatien 0:fd63457452f4 59 m_pos+=2;
donatien 0:fd63457452f4 60 if(len==0)
donatien 0:fd63457452f4 61 beepDone();
donatien 0:fd63457452f4 62 m_timeout.attach(this, &Beep::beepDone, len); //Setup timeout for end of note
donatien 0:fd63457452f4 63 if(freq>0)
donatien 0:fd63457452f4 64 m_ticker.attach(this, &Beep::beepTick, .5/freq); //Setup ticker for pin toggling at right freq
donatien 0:fd63457452f4 65 }
donatien 0:fd63457452f4 66
donatien 0:fd63457452f4 67 void Beep::beepTick()
donatien 0:fd63457452f4 68 {
donatien 0:fd63457452f4 69 m_out.write(!m_out.read()); //Toggle output pin
donatien 0:fd63457452f4 70 }
donatien 0:fd63457452f4 71
donatien 0:fd63457452f4 72 void Beep::beepDone()
donatien 0:fd63457452f4 73 {
donatien 0:fd63457452f4 74 m_ticker.detach(); //Note is done, stop toggling output pin
donatien 0:fd63457452f4 75 }