mirror of
https://github.com/eclipse/upm.git
synced 2025-03-24 01:10:22 +03:00
grove_mcfled: Add C++ and JS examples, utilizing existing GroveLed driver.
The module adds examples that utilize the existing GroveLed driver for the Grove Multi Color Flash LED. Signed-off-by: Jon Trulson <jtrulson@ics.com> Signed-off-by: Zion Orent <zorent@ics.com> Signed-off-by: John Van Drasek <john.r.van.drasek@intel.com>
This commit is contained in:
parent
a853733f61
commit
6135e932e4
@ -75,6 +75,7 @@ add_executable (grovespeaker-example grovespeaker.cxx)
|
|||||||
add_executable (rfr359f-example rfr359f.cxx)
|
add_executable (rfr359f-example rfr359f.cxx)
|
||||||
add_executable (biss0001-example biss0001.cxx)
|
add_executable (biss0001-example biss0001.cxx)
|
||||||
add_executable (my9221-example my9221.cxx)
|
add_executable (my9221-example my9221.cxx)
|
||||||
|
add_executable (grove_mcfled-example grove_mcfled.cxx)
|
||||||
|
|
||||||
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
|
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
|
||||||
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
|
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
|
||||||
@ -215,3 +216,4 @@ target_link_libraries (grovespeaker-example grovespeaker ${CMAKE_THREAD_LIBS_INI
|
|||||||
target_link_libraries (rfr359f-example rfr359f ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries (rfr359f-example rfr359f ${CMAKE_THREAD_LIBS_INIT})
|
||||||
target_link_libraries (biss0001-example biss0001 ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries (biss0001-example biss0001 ${CMAKE_THREAD_LIBS_INIT})
|
||||||
target_link_libraries (my9221-example my9221 ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries (my9221-example my9221 ${CMAKE_THREAD_LIBS_INIT})
|
||||||
|
target_link_libraries (grove_mcfled-example grove ${CMAKE_THREAD_LIBS_INIT})
|
||||||
|
68
examples/grove_mcfled.cxx
Normal file
68
examples/grove_mcfled.cxx
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2014-2015 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 <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
#include "grove.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
// Instantiate a grove LED on D2. Here we are controlling a Grove
|
||||||
|
// Multi-color flash LED. We just just need to turn it on - it will
|
||||||
|
// then cycle through various colors (red, green, blue, purple) on it's
|
||||||
|
// own until turned off.
|
||||||
|
upm::GroveLed* led = new upm::GroveLed(2);
|
||||||
|
|
||||||
|
// start the light show
|
||||||
|
led->on();
|
||||||
|
|
||||||
|
// just sleep until interrupted
|
||||||
|
while (shouldRun)
|
||||||
|
sleep(1);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
led->off();
|
||||||
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
|
delete led;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
46
examples/javascript/grove_mcfled.js
Normal file
46
examples/javascript/grove_mcfled.js
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||||
|
/*jshint unused:true */
|
||||||
|
/*
|
||||||
|
* Author: Zion Orent <zorent@ics.com>
|
||||||
|
* Copyright (c) 2015 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var upmled = require("jsupm_grove");
|
||||||
|
// Initialize on GPIO 2
|
||||||
|
var myled = new upmled.GroveLed(2);
|
||||||
|
myled.on();
|
||||||
|
|
||||||
|
// Dummy setInterval, just to keep program from quitting
|
||||||
|
// This way, the LED turns off when you quit the program
|
||||||
|
var myInterval = setInterval(function()
|
||||||
|
{
|
||||||
|
;
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
// When exiting: turn off LED, clear interval, and print message
|
||||||
|
process.on('SIGINT', function()
|
||||||
|
{
|
||||||
|
clearInterval(myInterval);
|
||||||
|
myled.off();
|
||||||
|
console.log("Exiting...");
|
||||||
|
process.exit(0);
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user