KeyboardManager: a class to manage the polling of a switch-matrix keyboard

Dependents:   KeyboardTest

SingleKeyPressMonitor.cpp

Committer:
osmeest
Date:
2011-02-03
Revision:
3:1310c57aca77
Parent:
2:eb4cc53ff33d

File content as of revision 3:1310c57aca77:

#include "kbd_mgr/SingleKeyPressMonitor.h"

namespace kbd_mgr {

void SingleKeyPressMonitor::handleState(const KeyboardState &newState)
{
    int key;
    if (newState.getKeyPressType(key) == KeyboardState::SingleKeyPress && this->lastReportedState.empty()) 
    {
        KeyEvent keyDown(key, KeyEvent::KeyDown);
        invokeHandler(keyDown);
        
        this->lastReportedState = newState;
        this->lastReportedKey = key;
    }
    else if (!this->lastReportedState.empty() &&
             (newState & this->lastReportedState).empty())
    {
        KeyEvent keyUp(this->lastReportedKey, KeyEvent::KeyUp);
        invokeHandler(keyUp);
                
        this->lastReportedState.clear();
        this->lastReportedKey = KeyEvent::NoKey;
    }

}

} // kbd_mgr