2014-07-19 16:29:41 +00:00
|
|
|
/*
|
|
|
|
* Author: Alexander Komarov <alexander.komarov@intel.com>
|
|
|
|
* Copyright (c) 2014 Intel Corporation.
|
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* This program and the accompanying materials are made available under the
|
|
|
|
* terms of the The MIT License which is available at
|
|
|
|
* https://opensource.org/licenses/MIT.
|
2014-07-19 16:29:41 +00:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2014-07-19 16:29:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <signal.h>
|
2017-08-30 15:00:29 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2016-04-25 14:27:51 -07:00
|
|
|
#include "joystick12.hpp"
|
2017-08-30 15:00:29 -07:00
|
|
|
#include "upm_utilities.h"
|
2014-07-19 16:29:41 +00:00
|
|
|
|
|
|
|
int is_running = 0;
|
|
|
|
|
|
|
|
void
|
|
|
|
sig_handler(int signo)
|
|
|
|
{
|
|
|
|
printf("got signal\n");
|
|
|
|
if (signo == SIGINT) {
|
|
|
|
is_running = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! [Interesting]
|
|
|
|
int
|
2017-08-30 15:00:29 -07:00
|
|
|
main(int argc, char** argv)
|
2014-07-19 16:29:41 +00:00
|
|
|
{
|
2015-01-15 16:46:36 -08:00
|
|
|
// Instantiate a joystick on analog pins A0 and A1
|
2017-08-30 15:00:29 -07:00
|
|
|
upm::Joystick12 sensor(0, 1);
|
2014-07-19 16:29:41 +00:00
|
|
|
signal(SIGINT, sig_handler);
|
|
|
|
|
2015-01-15 16:46:36 -08:00
|
|
|
// Print the X and Y input values every second
|
2014-07-19 16:29:41 +00:00
|
|
|
while (!is_running) {
|
2017-08-30 15:00:29 -07:00
|
|
|
float x = sensor.getXInput();
|
|
|
|
float y = sensor.getYInput();
|
2014-07-19 16:29:41 +00:00
|
|
|
std::cout << "Driving X:" << x << ": and Y:" << y << std::endl;
|
2017-08-30 15:00:29 -07:00
|
|
|
upm_delay(1);
|
2014-07-19 16:29:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "exiting application" << std::endl;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
//! [Interesting]
|