blink-io-cpp: example gpio using cpp wrappers.
Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com> Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
committed by
Brendan Le Foll
parent
0765a9454b
commit
1434f8f317
74
examples/c++/Blink-IO.cpp
Normal file
74
examples/c++/Blink-IO.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "gpio.hpp"
|
||||
|
||||
#define DEFAULT_IOPIN 8
|
||||
|
||||
static int iopin;
|
||||
int running = 0;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT) {
|
||||
printf("closing IO%d nicely\n", iopin);
|
||||
running = -1;
|
||||
}
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
if (argc < 2) {
|
||||
printf("Provide an int arg if you want to flash on something other than %d\n", DEFAULT_IOPIN);
|
||||
iopin = DEFAULT_IOPIN;
|
||||
} else {
|
||||
iopin = strtol(argv[1], NULL, 10);
|
||||
}
|
||||
maa::Gpio* gpio = new maa::Gpio(iopin);
|
||||
if (gpio == NULL) {
|
||||
return MAA_ERROR_UNSPECIFIED;
|
||||
}
|
||||
int response = gpio->dir(MAA_GPIO_OUT);
|
||||
if (response != MAA_SUCCESS)
|
||||
maa_result_print((maa_result_t) MAA_SUCCESS);
|
||||
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
while (running == 0) {
|
||||
response = gpio->write(1);
|
||||
sleep(1);
|
||||
response = gpio->write(0);
|
||||
sleep(1);
|
||||
}
|
||||
delete gpio;
|
||||
return response;
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
add_executable (AioA0 AioA0.cpp)
|
||||
add_executable (blink-io-cpp Blink-IO.cpp)
|
||||
|
||||
include_directories(${PROJECT_SOURCE_DIR}/api)
|
||||
|
||||
target_link_libraries (AioA0 maa stdc++)
|
||||
target_link_libraries (blink-io-cpp maa stdc++)
|
||||
|
||||
Reference in New Issue
Block a user