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: 4DGL-uLCD-SE LSM9DS1_Library SDFileSystem mbed-rtos mbed wave_player
InputHandler.cpp
- Committer:
- Dogstopper
- Date:
- 2016-03-10
- Revision:
- 1:61b8141da36e
- Parent:
- 0:6a49493943be
File content as of revision 1:61b8141da36e:
#include "InputHandler.h"
#define START_THREAD 1
InputHandler::InputHandler(PinName sda, PinName scl, uint8_t xgAddr, uint8_t mAddr, PinName digitalIn)
:imu(sda, scl, xgAddr, mAddr),
pushButton(digitalIn, PullUp)
{
imu.begin();
imu.calibrate(1);
}
void InputHandler::start() {
Thread thread(&InputHandler::threadStarter, this, osPriorityNormal,1024);
}
float InputHandler::getXAccel() {
stdio_mutex.lock();
float temp = xAccel;
stdio_mutex.unlock();
return temp;
}
float InputHandler::getYAccel() {
stdio_mutex.lock();
float temp = (yAccel);// + 1.0) / 2.0;
stdio_mutex.unlock();
return temp;
}
float InputHandler::getZAccel() {
stdio_mutex.lock();
float temp = (zAccel);// + 1.0) / 2.0;
stdio_mutex.unlock();
return temp;
}
bool InputHandler::getPushed() {
stdio_mutex.lock();
float temp = isPushed;
stdio_mutex.unlock();
return temp;
}
void InputHandler::threadStarter(void const *p) {
InputHandler *instance = (InputHandler*)p;
instance->retrieveInputs();
}
void InputHandler::retrieveInputs() {
while(true) {
imu.readAccel();
stdio_mutex.lock();
xAccel = -imu.calcAccel(imu.ax);
yAccel = -imu.calcAccel(imu.ay);
zAccel = -imu.calcAccel(imu.az);
isPushed = pushButton.read() == 0;
//printf("xAccel: %.6f\n\ryAccel: %.6f\n\risPushed: %s", xAccel, yAccel, isPushed ? "true" : "false");
stdio_mutex.unlock();
Thread::wait(20); // ~60Hz
}
}