mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 01:11:10 +03:00
Grove: Reverted examples and Sources
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
@ -88,12 +88,19 @@ link_directories (${MRAA_LIBDIR})
|
||||
# grove* will use module grove
|
||||
add_example (hmc5883l)
|
||||
add_example (led)
|
||||
add_example (groveled)
|
||||
add_example (relay)
|
||||
add_example (groverelay)
|
||||
add_example (light)
|
||||
add_example (grovelight)
|
||||
add_example (temperature)
|
||||
add_example (grovetemp)
|
||||
add_example (button)
|
||||
add_example (grovebutton)
|
||||
add_example (rotary)
|
||||
add_example (groverotary)
|
||||
add_example (slide)
|
||||
add_example (groveslide)
|
||||
add_example (buzzer-sound)
|
||||
add_example (nrf24l01-transmitter)
|
||||
add_example (nrf24l01-receiver)
|
||||
@ -143,11 +150,15 @@ add_example (ds1307)
|
||||
add_example (a110x)
|
||||
add_example (gp2y0a)
|
||||
add_example (moisture)
|
||||
add_example (grovemoisture)
|
||||
add_example (ehr)
|
||||
add_example (groveehr)
|
||||
add_example (ta12200)
|
||||
add_example (grovelinefinder)
|
||||
add_example (vdiv)
|
||||
add_example (grovevdiv)
|
||||
add_example (water)
|
||||
add_example (grovewater)
|
||||
add_example (guvas12d)
|
||||
add_example (mpr121)
|
||||
add_example (yg1006)
|
||||
@ -155,6 +166,7 @@ add_example (wt5001)
|
||||
add_example (ppd42ns)
|
||||
add_example (mq303a)
|
||||
add_example (speaker)
|
||||
add_example (grovespeaker)
|
||||
add_example (rfr359f)
|
||||
add_example (biss0001)
|
||||
add_example (rotaryencoder)
|
||||
@ -168,10 +180,15 @@ add_example (hmtrp)
|
||||
add_example (nunchuck)
|
||||
add_example (otp538u)
|
||||
add_example (collision)
|
||||
add_example (grovecollision)
|
||||
add_example (electromagnet)
|
||||
add_example (groveelectromagnet)
|
||||
add_example (emg)
|
||||
add_example (groveemg)
|
||||
add_example (o2)
|
||||
add_example (groveo2)
|
||||
add_example (gsr)
|
||||
add_example (grovegsr)
|
||||
add_example (ina132)
|
||||
add_example (l298)
|
||||
add_example (l298-stepper)
|
||||
@ -180,6 +197,7 @@ add_example (grovemd)
|
||||
add_example (grovemd-stepper)
|
||||
add_example (pca9685)
|
||||
add_example (eldriver)
|
||||
add_example (groveeldriver)
|
||||
add_example (adafruitss)
|
||||
add_example (adafruitms1438)
|
||||
add_example (adafruitms1438-stepper)
|
||||
@ -215,6 +233,7 @@ add_example (mg811)
|
||||
add_example (wheelencoder)
|
||||
add_example (sm130)
|
||||
add_example (gprs)
|
||||
add_example (grovegprs)
|
||||
add_example (lm35)
|
||||
add_example (micsv89)
|
||||
add_example (xbee)
|
||||
|
49
examples/c++/grovebutton.cxx
Normal file
49
examples/c++/grovebutton.cxx
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Author: Sarah Knepper <sarah.knepper@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 <unistd.h>
|
||||
#include <iostream>
|
||||
#include "grove.hpp"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
// This example uses GPIO 0
|
||||
//! [Interesting]
|
||||
|
||||
// Create the button object using GPIO pin 0
|
||||
upm::GroveButton* button = new upm::GroveButton(0);
|
||||
|
||||
// Read the input and print, waiting one second between readings
|
||||
while( 1 ) {
|
||||
std::cout << button->name() << " value is " << button->value() << std::endl;
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// Delete the button object
|
||||
delete button;
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
69
examples/c++/grovecollision.cxx
Normal file
69
examples/c++/grovecollision.cxx
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include "grovecollision.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// The was tested with the Grove Collision Sensor
|
||||
// Instantiate a Grove Collision on digital pin D2
|
||||
upm::GroveCollision* collision = new upm::GroveCollision(2);
|
||||
|
||||
bool collisionState = false;
|
||||
cout << "No collision" << endl;
|
||||
while (shouldRun)
|
||||
{
|
||||
if (collision->isColliding() && !collisionState)
|
||||
{
|
||||
cout << "Collision!" << endl;
|
||||
collisionState = true;
|
||||
}
|
||||
else if (collisionState)
|
||||
{
|
||||
cout << "No collision" << endl;
|
||||
collisionState = false;
|
||||
}
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete collision;
|
||||
return 0;
|
||||
}
|
78
examples/c++/groveehr.cxx
Normal file
78
examples/c++/groveehr.cxx
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.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 <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "groveehr.hpp"
|
||||
|
||||
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 Ear-clip Heart Rate sensor on digital pin D2
|
||||
upm::GroveEHR* heart = new upm::GroveEHR(2);
|
||||
|
||||
// set the beat counter to 0, init the clock and start counting beats
|
||||
heart->clearBeatCounter();
|
||||
heart->initClock();
|
||||
heart->startBeatCounter();
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
// we grab these just for display purposes in this example
|
||||
uint32_t millis = heart->getMillis();
|
||||
uint32_t beats = heart->beatCounter();
|
||||
|
||||
// heartRate() requires that at least 5 seconds pass before
|
||||
// returning anything other than 0
|
||||
int hr = heart->heartRate();
|
||||
|
||||
// output milliseconds passed, beat count, and computed heart rate
|
||||
cout << "Millis: " << millis << " Beats: " << beats;
|
||||
cout << " Heart Rate: " << hr << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
heart->stopBeatCounter();
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete heart;
|
||||
return 0;
|
||||
}
|
66
examples/c++/groveeldriver.cxx
Normal file
66
examples/c++/groveeldriver.cxx
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include "groveeldriver.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// The was tested with the Grove El Driver Module
|
||||
// Instantiate a Grove El Driver on digital pin D2
|
||||
upm::GroveElDriver* eldriver = new upm::GroveElDriver(2);
|
||||
|
||||
bool lightState = true;
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
if (lightState)
|
||||
eldriver->on();
|
||||
else
|
||||
eldriver->off();
|
||||
lightState = !lightState;
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
eldriver->off();
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete eldriver;
|
||||
return 0;
|
||||
}
|
79
examples/c++/groveelectromagnet.cxx
Normal file
79
examples/c++/groveelectromagnet.cxx
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <time.h>
|
||||
#include <signal.h>
|
||||
#include "groveelectromagnet.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
float get_time()
|
||||
{
|
||||
return ((float)(clock()))/CLOCKS_PER_SEC;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// The was tested with the Grove Electromagnetic Module
|
||||
// Instantiate a Grove Electromagnet on digital pin D2
|
||||
upm::GroveElectromagnet* magnet = new upm::GroveElectromagnet(2);
|
||||
cout << "Starting up magnet...." << endl;
|
||||
magnet->off();
|
||||
|
||||
bool magnetState = false;
|
||||
float time_passed = get_time();
|
||||
|
||||
// Turn magnet on and off every 5 seconds
|
||||
while (shouldRun)
|
||||
{
|
||||
if ((get_time() - time_passed) > 5.0)
|
||||
{
|
||||
magnetState = !magnetState;
|
||||
if (magnetState)
|
||||
magnet->on();
|
||||
else
|
||||
magnet->off();
|
||||
cout << "Turning magnet " << ((magnetState) ? "on" : "off") << endl;
|
||||
time_passed = get_time();
|
||||
}
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
magnet->off();
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete magnet;
|
||||
return 0;
|
||||
}
|
60
examples/c++/groveemg.cxx
Normal file
60
examples/c++/groveemg.cxx
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "groveemg.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// The was tested with the GroveEMG Muscle Signal Reader Sensor Module
|
||||
// Instantiate a GroveEMG on analog pin A0
|
||||
upm::GroveEMG *emg = new upm::GroveEMG(0);
|
||||
cout << "Calibrating...." << endl;
|
||||
emg->calibrate();
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
cout << emg->value() << endl;
|
||||
usleep(100000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
cout << "Exiting" << endl;
|
||||
delete emg;
|
||||
return 0;
|
||||
}
|
111
examples/c++/grovegprs.cxx
Normal file
111
examples/c++/grovegprs.cxx
Normal file
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@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.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include "grovegprs.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
|
||||
void printUsage(char *progname)
|
||||
{
|
||||
cout << "Usage: " << progname << " [AT command]" << endl;
|
||||
cout << endl;
|
||||
|
||||
cout << "If an argument is supplied on the command line, that argument is"
|
||||
<< endl;
|
||||
cout << "sent to the module and the response is printed out." << endl;
|
||||
cout << endl;
|
||||
cout << "If no argument is used, then the manufacturer and the current"
|
||||
<< endl;
|
||||
cout << "saved profiles are queried and the results printed out." << endl;
|
||||
cout << endl;
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
// simple helper function to send a command and wait for a response
|
||||
void sendCommand(upm::GroveGPRS* sensor, string cmd)
|
||||
{
|
||||
// commands need to be terminated with a carriage return
|
||||
cmd += "\r";
|
||||
|
||||
sensor->writeDataStr(cmd);
|
||||
|
||||
// wait up to 1 second
|
||||
if (sensor->dataAvailable(1000))
|
||||
{
|
||||
cout << "Returned: " << sensor->readDataStr(1024) << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "Timed out waiting for response" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a GroveGPRS Module on UART 0
|
||||
upm::GroveGPRS* sensor = new upm::GroveGPRS(0);
|
||||
|
||||
// Set the baud rate, 19200 baud is the default.
|
||||
if (sensor->setBaudRate(19200) != mraa::SUCCESS)
|
||||
{
|
||||
cerr << "Failed to set tty baud rate" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
printUsage(argv[0]);
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
cout << "Sending command line argument (" << argv[1] << ")..." << endl;
|
||||
sendCommand(sensor, argv[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// query the module manufacturer
|
||||
cout << "Querying module manufacturer (AT+CGMI)..." << endl;
|
||||
sendCommand(sensor, "AT+CGMI");
|
||||
|
||||
sleep(1);
|
||||
|
||||
// query the saved profiles
|
||||
cout << "Querying the saved profiles (AT&V)..." << endl;
|
||||
sendCommand(sensor, "AT&V");
|
||||
|
||||
// A comprehensive list is available from the datasheet at:
|
||||
// http://www.seeedstudio.com/wiki/images/7/72/AT_Commands_v1.11.pdf
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
delete sensor;
|
||||
return 0;
|
||||
}
|
63
examples/c++/grovegsr.cxx
Normal file
63
examples/c++/grovegsr.cxx
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "grovegsr.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// The was tested with the GroveGSR Galvanic Skin Response Sensor module.
|
||||
|
||||
// Instantiate a GroveGSR on analog pin A0
|
||||
upm::GroveGSR *gsr = new upm::GroveGSR(0);
|
||||
cout << "Calibrating...." << endl;
|
||||
gsr->calibrate();
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
cout << gsr->value() << endl;
|
||||
usleep(500000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete gsr;
|
||||
return 0;
|
||||
}
|
55
examples/c++/groveled.cxx
Normal file
55
examples/c++/groveled.cxx
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Contributions: Sarah Knepper <sarah.knepper@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 <unistd.h>
|
||||
#include <iostream>
|
||||
#include "grove.hpp"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
|
||||
// Create the Grove LED object using GPIO pin 2
|
||||
upm::GroveLed* led = new upm::GroveLed(2);
|
||||
|
||||
// Print the name
|
||||
std::cout << led->name() << std::endl;
|
||||
|
||||
// Turn the LED on and off 10 times, pausing one second
|
||||
// between transitions
|
||||
for (int i=0; i < 10; i++) {
|
||||
led->on();
|
||||
sleep(1);
|
||||
led->off();
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// Delete the Grove LED object
|
||||
delete led;
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
49
examples/c++/grovelight.cxx
Normal file
49
examples/c++/grovelight.cxx
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Contributions: Sarah Knepper <sarah.knepper@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 <unistd.h>
|
||||
#include <iostream>
|
||||
#include "grove.hpp"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
// Create the light sensor object using AIO pin 0
|
||||
upm::GroveLight* light = new upm::GroveLight(0);
|
||||
|
||||
// Read the input and print both the raw value and a rough lux value,
|
||||
// waiting one second between readings
|
||||
while( 1 ) {
|
||||
std::cout << light->name() << " raw value is " << light->raw_value() <<
|
||||
", which is roughly " << light->value() << " lux" << std::endl;
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// Delete the light sensor object
|
||||
delete light;
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
75
examples/c++/grovemoisture.cxx
Normal file
75
examples/c++/grovemoisture.cxx
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.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 <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "grovemoisture.hpp"
|
||||
|
||||
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 Moisture sensor on analog pin A0
|
||||
upm::GroveMoisture* moisture = new upm::GroveMoisture(0);
|
||||
|
||||
// Values (approximate):
|
||||
// 0-300, sensor in air or dry soil
|
||||
// 300-600, sensor in humid soil
|
||||
// 600+, sensor in wet soil or submerged in water.
|
||||
// Read the value every second and print the corresponding moisture level
|
||||
while (shouldRun)
|
||||
{
|
||||
int val = moisture->value();
|
||||
cout << "Moisture value: " << val << ", ";
|
||||
if (val >= 0 && val < 300)
|
||||
cout << "dry";
|
||||
else if (val >= 300 && val < 600)
|
||||
cout << "moist";
|
||||
else
|
||||
cout << "wet";
|
||||
|
||||
cout << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete moisture;
|
||||
return 0;
|
||||
}
|
57
examples/c++/groveo2.cxx
Normal file
57
examples/c++/groveo2.cxx
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "groveo2.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// The was tested with the O2 Oxygen Concentration Sensor Module
|
||||
// Instantiate a GroveO2 on analog pin A0
|
||||
upm::GroveO2 *O2 = new upm::GroveO2(0);
|
||||
while (shouldRun)
|
||||
{
|
||||
cout << "The output voltage is: " << O2->voltageValue() << "mV" << endl;
|
||||
usleep(100000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
cout << "Exiting" << endl;
|
||||
delete O2;
|
||||
return 0;
|
||||
}
|
58
examples/c++/groverelay.cxx
Normal file
58
examples/c++/groverelay.cxx
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Author: Sarah Knepper <sarah.knepper@intel.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.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "grove.hpp"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
// This example uses GPIO 0
|
||||
//! [Interesting]
|
||||
|
||||
// Create the relay switch object using GPIO pin 0
|
||||
upm::GroveRelay* relay = new upm::GroveRelay(0);
|
||||
|
||||
// Close and then open the relay switch 3 times,
|
||||
// waiting one second each time. The LED on the relay switch
|
||||
// will light up when the switch is on (closed).
|
||||
// The switch will also make a noise between transitions.
|
||||
for ( int i = 0; i < 3; i++ ) {
|
||||
relay->on();
|
||||
if ( relay->isOn() )
|
||||
std::cout << relay->name() << " is on" << std::endl;
|
||||
sleep(1);
|
||||
relay->off();
|
||||
if ( relay->isOff() )
|
||||
std::cout << relay->name() << " is off" << std::endl;
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// Delete the relay switch object
|
||||
delete relay;
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
57
examples/c++/groverotary.cxx
Normal file
57
examples/c++/groverotary.cxx
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Author: Mihai Tudor Panu <mihai.tudor.panu@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 <unistd.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include "grove.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main ()
|
||||
{
|
||||
//! [Interesting]
|
||||
// Instantiate a rotary sensor on analog pin A0
|
||||
upm::GroveRotary* knob = new upm::GroveRotary(0);
|
||||
|
||||
// Print sensor name to confirm it initialized properly
|
||||
cout << knob->name() << endl;
|
||||
|
||||
while(true) {
|
||||
float abs_value = knob->abs_value(); // Absolute raw value
|
||||
float abs_deg = knob->abs_deg(); // Absolute degrees
|
||||
float abs_rad = knob->abs_rad(); // Absolute radians
|
||||
float rel_value = knob->rel_value(); // Relative raw value
|
||||
float rel_deg = knob->rel_deg(); // Relative degrees
|
||||
float rel_rad = knob->rel_rad(); // Relative radians
|
||||
|
||||
fprintf(stdout, "Absolute: %4d raw %5.2f deg = %3.2f rad Relative: %4d raw %5.2f deg %3.2f rad\n",
|
||||
(int16_t)abs_value, abs_deg, abs_rad, (int16_t)rel_value, rel_deg, rel_rad);
|
||||
|
||||
usleep(2500000); // Sleep for 2.5s
|
||||
}
|
||||
//! [Interesting]
|
||||
delete knob;
|
||||
return 0;
|
||||
}
|
50
examples/c++/groveslide.cxx
Normal file
50
examples/c++/groveslide.cxx
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Author: Mihai Tudor Panu <mihai.tudor.panu@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 <unistd.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include "grove.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main ()
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::GroveSlide* slide = new upm::GroveSlide(0); // Instantiate new grove slide potentiometer on analog pin A0
|
||||
|
||||
cout << slide->name() << endl;
|
||||
|
||||
while(true) {
|
||||
float adc_value = slide->raw_value(); // Read raw value
|
||||
float volts = slide->voltage_value(); // Read voltage, board reference set at 5.0V
|
||||
fprintf(stdout, "%4d = %.2f V\n", (uint16_t)adc_value, volts);
|
||||
|
||||
usleep(2500000); // Sleep for 2.5s
|
||||
}
|
||||
//! [Interesting]
|
||||
delete slide;
|
||||
return 0;
|
||||
}
|
49
examples/c++/grovespeaker.cxx
Normal file
49
examples/c++/grovespeaker.cxx
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.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 <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "grovespeaker.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main ()
|
||||
{
|
||||
//! [Interesting]
|
||||
// Instantiate a Grove Speaker on digital pin D2
|
||||
upm::GroveSpeaker* speaker = new upm::GroveSpeaker(2);
|
||||
|
||||
// Play all 7 of the lowest notes
|
||||
speaker->playAll();
|
||||
|
||||
// Play a medium C-sharp
|
||||
speaker->playSound('c', true, "med");
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete speaker;
|
||||
return 0;
|
||||
}
|
55
examples/c++/grovetemp.cxx
Normal file
55
examples/c++/grovetemp.cxx
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Contributions: Sarah Knepper <sarah.knepper@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 <unistd.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include "grove.hpp"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
|
||||
// Create the temperature sensor object using AIO pin 0
|
||||
upm::GroveTemp* temp = new upm::GroveTemp(0);
|
||||
std::cout << temp->name() << std::endl;
|
||||
|
||||
// Read the temperature ten times, printing both the Celsius and
|
||||
// equivalent Fahrenheit temperature, waiting one second between readings
|
||||
for (int i=0; i < 10; i++) {
|
||||
int celsius = temp->value();
|
||||
int fahrenheit = (int) (celsius * 9.0/5.0 + 32.0);
|
||||
printf("%d degrees Celsius, or %d degrees Fahrenheit\n",
|
||||
celsius, fahrenheit);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// Delete the temperature sensor object
|
||||
delete temp;
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
67
examples/c++/grovevdiv.cxx
Normal file
67
examples/c++/grovevdiv.cxx
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.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 <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "grovevdiv.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main ()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// Instantiate a Grove Voltage Divider sensor on analog pin A0
|
||||
upm::GroveVDiv* vDiv = new upm::GroveVDiv(0);
|
||||
|
||||
// collect data and output measured voltage according to the setting
|
||||
// of the scaling switch (3 or 10)
|
||||
while (shouldRun)
|
||||
{
|
||||
unsigned int val = vDiv->value(100);
|
||||
float gain3val = vDiv->computedValue(3, val);
|
||||
float gain10val = vDiv->computedValue(10, val);
|
||||
cout << "ADC value: " << val << " Gain 3: " << gain3val
|
||||
<< "v Gain 10: " << gain10val << "v" << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete vDiv;
|
||||
return 0;
|
||||
}
|
65
examples/c++/grovewater.cxx
Normal file
65
examples/c++/grovewater.cxx
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.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 <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "grovewater.hpp"
|
||||
|
||||
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 Water sensor on digital pin D2
|
||||
upm::GroveWater* water = new upm::GroveWater(2);
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
bool val = water->isWet();
|
||||
if (val)
|
||||
cout << "Sensor is wet." << endl;
|
||||
else
|
||||
cout << "Sensor is dry." << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete water;
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user