A DTMF sequence editor and player for HAM radio equipment command & control.

Dependencies:   mbed ExtTextLCD

Committer:
osmeest
Date:
Mon Mar 07 22:51:19 2011 +0000
Revision:
0:1324e7d9d471

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
osmeest 0:1324e7d9d471 1 #include "kbd_mgr/KeyboardMonitor.h"
osmeest 0:1324e7d9d471 2
osmeest 0:1324e7d9d471 3 namespace kbd_mgr {
osmeest 0:1324e7d9d471 4
osmeest 0:1324e7d9d471 5 KeyboardMonitor::KeyboardMonitor(PortName inPort, std::size_t numKeysPerRow, std::size_t inLowestBit,
osmeest 0:1324e7d9d471 6 const KeyboardMonitor::OutPinsSet &outPins) :
osmeest 0:1324e7d9d471 7 in(inPort, ((1 << numKeysPerRow)-1) << inLowestBit), inBitShift(inLowestBit), outPins(outPins),
osmeest 0:1324e7d9d471 8 ticker(), scanRow(0), currentState(outPins.size(), numKeysPerRow)
osmeest 0:1324e7d9d471 9 { }
osmeest 0:1324e7d9d471 10
osmeest 0:1324e7d9d471 11 KeyboardMonitor::~KeyboardMonitor()
osmeest 0:1324e7d9d471 12 {
osmeest 0:1324e7d9d471 13 stop();
osmeest 0:1324e7d9d471 14 }
osmeest 0:1324e7d9d471 15
osmeest 0:1324e7d9d471 16 void KeyboardMonitor::start(float pollingPeriod)
osmeest 0:1324e7d9d471 17 {
osmeest 0:1324e7d9d471 18 if (this->outPins.empty()) {
osmeest 0:1324e7d9d471 19 return;
osmeest 0:1324e7d9d471 20 }
osmeest 0:1324e7d9d471 21
osmeest 0:1324e7d9d471 22 if (pollingPeriod < 20e-6) {
osmeest 0:1324e7d9d471 23 pollingPeriod = 20e-6;
osmeest 0:1324e7d9d471 24 }
osmeest 0:1324e7d9d471 25
osmeest 0:1324e7d9d471 26 for(OutPinsSet::const_iterator p = this->outPins.begin(); p != this->outPins.end(); ++p) {
osmeest 0:1324e7d9d471 27 DigitalOut out(*p);
osmeest 0:1324e7d9d471 28 out.write( p == this->outPins.begin() ? 1 : 0 );
osmeest 0:1324e7d9d471 29 }
osmeest 0:1324e7d9d471 30 this->in.mode(PullDown);
osmeest 0:1324e7d9d471 31 this->scanRow = 0;
osmeest 0:1324e7d9d471 32 this->ticker.attach(this, &KeyboardMonitor::timerHandler, pollingPeriod);
osmeest 0:1324e7d9d471 33 }
osmeest 0:1324e7d9d471 34
osmeest 0:1324e7d9d471 35 void KeyboardMonitor::stop()
osmeest 0:1324e7d9d471 36 {
osmeest 0:1324e7d9d471 37 this->ticker.detach();
osmeest 0:1324e7d9d471 38 this->in.mode(OpenDrain);
osmeest 0:1324e7d9d471 39 }
osmeest 0:1324e7d9d471 40
osmeest 0:1324e7d9d471 41 void KeyboardMonitor::timerHandler()
osmeest 0:1324e7d9d471 42 {
osmeest 0:1324e7d9d471 43 DigitalOut out(this->outPins[this->scanRow]);
osmeest 0:1324e7d9d471 44 out.write(1);
osmeest 0:1324e7d9d471 45 wait_us(10);
osmeest 0:1324e7d9d471 46 int v = (this->in.read() >> this->inBitShift);
osmeest 0:1324e7d9d471 47 out.write(0);
osmeest 0:1324e7d9d471 48 this->currentState.setRowState(this->scanRow, v);
osmeest 0:1324e7d9d471 49 this->scanRow = (this->scanRow + 1) % this->currentState.getNumRows();
osmeest 0:1324e7d9d471 50 if (this->scanRow == 0) {
osmeest 0:1324e7d9d471 51 invokeHandler(this->currentState);
osmeest 0:1324e7d9d471 52 }
osmeest 0:1324e7d9d471 53 }
osmeest 0:1324e7d9d471 54
osmeest 0:1324e7d9d471 55 } // kbd_mgr