mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 09:21:12 +03:00
grove: remove deprecated classes and examples
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "grovebutton.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
// This example uses GPIO 0
|
||||
//! [Interesting]
|
||||
|
||||
// Create the button object using GPIO pin 0
|
||||
upm::GroveButton button(0);
|
||||
|
||||
// Read the input and print, waiting one second between readings
|
||||
while (1) {
|
||||
std::cout << button.name() << " value is " << button.value() << std::endl;
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
// Delete the button object
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "groveled.hpp"
|
||||
#include "upm_utilities.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(2);
|
||||
|
||||
// start the light show
|
||||
led.on();
|
||||
|
||||
// just upm_delay until interrupted
|
||||
while (shouldRun)
|
||||
upm_delay(1);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
led.off();
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "groveled.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
|
||||
// Create the Grove LED object using GPIO pin 2
|
||||
upm::GroveLed led(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();
|
||||
upm_delay(1);
|
||||
led.off();
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
// Delete the Grove LED object
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "grovelight.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
// Create the light sensor object using AIO pin 0
|
||||
upm::GroveLight light(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;
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
// Delete the light sensor object
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "groverelay.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
// This example uses GPIO 0
|
||||
//! [Interesting]
|
||||
|
||||
// Create the relay switch object using GPIO pin 0
|
||||
upm::GroveRelay relay(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;
|
||||
upm_delay(1);
|
||||
relay.off();
|
||||
if (relay.isOff())
|
||||
std::cout << relay.name() << " is off" << std::endl;
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
// Delete the relay switch object
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
#include "groverotary.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
//! [Interesting]
|
||||
// Instantiate a rotary sensor on analog pin A0
|
||||
upm::GroveRotary knob(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);
|
||||
|
||||
upm_delay_us(2500000); // Sleep for 2.5s
|
||||
}
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
#include "groveslide.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::GroveSlide slide(0);
|
||||
|
||||
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);
|
||||
|
||||
upm_delay_us(2500000); // Sleep for 2.5s
|
||||
}
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
#include "grovetemp.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
|
||||
// Create the temperature sensor object using AIO pin 0
|
||||
upm::GroveTemp temp(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);
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
// Delete the temperature sensor object
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* 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 <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(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;
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "groveehr.hpp"
|
||||
#include "upm_utilities.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 Ear-clip Heart Rate sensor on digital pin D2
|
||||
upm::GroveEHR heart(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;
|
||||
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
heart.stopBeatCounter();
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
/*
|
||||
* 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 <signal.h>
|
||||
|
||||
#include "groveeldriver.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
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(2);
|
||||
|
||||
bool lightState = true;
|
||||
|
||||
while (shouldRun) {
|
||||
if (lightState)
|
||||
eldriver.on();
|
||||
else
|
||||
eldriver.off();
|
||||
lightState = !lightState;
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
eldriver.off();
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
/*
|
||||
* 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 <signal.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.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(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;
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
/*
|
||||
* 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 <signal.h>
|
||||
|
||||
#include "groveemg.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
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(0);
|
||||
cout << "Calibrating...." << endl;
|
||||
emg.calibrate();
|
||||
|
||||
while (shouldRun) {
|
||||
cout << emg.value() << endl;
|
||||
upm_delay_us(100000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
cout << "Exiting" << endl;
|
||||
return 0;
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
|
||||
#include "grovegprs.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
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(0);
|
||||
|
||||
// Set the baud rate, 19200 baud is the default.
|
||||
if (sensor.setBaudRate(19200) != 0) {
|
||||
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");
|
||||
|
||||
upm_delay(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]
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* 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 <signal.h>
|
||||
|
||||
#include "grovegsr.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
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(0);
|
||||
cout << "Calibrating...." << endl;
|
||||
gsr.calibrate();
|
||||
|
||||
while (shouldRun) {
|
||||
cout << gsr.value() << endl;
|
||||
upm_delay_us(500000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "grovelinefinder.hpp"
|
||||
#include "upm_utilities.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 Line Finder sensor on digital pin D2
|
||||
upm::GroveLineFinder finder(2);
|
||||
|
||||
// check every second for the presence of white detection
|
||||
while (shouldRun) {
|
||||
bool val = finder.whiteDetected();
|
||||
if (val)
|
||||
cout << "White detected." << endl;
|
||||
else
|
||||
cout << "Black detected." << endl;
|
||||
|
||||
upm_delay(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
|
||||
#include "grovemd.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
// Instantiate an I2C Grove Motor Driver on I2C bus 0
|
||||
|
||||
upm::GroveMD motors(GROVEMD_I2C_BUS, GROVEMD_DEFAULT_I2C_ADDR);
|
||||
|
||||
// This example demonstrates using the GroveMD to drive a stepper motor
|
||||
|
||||
// configure it, for this example, we'll assume 200 steps per rev
|
||||
motors.configStepper(200);
|
||||
|
||||
// set for half a rotation
|
||||
motors.setStepperSteps(100);
|
||||
|
||||
// let it go - clockwise rotation, 10 RPM speed
|
||||
motors.enableStepper(upm::GroveMD::STEP_DIR_CW, 10);
|
||||
|
||||
upm_delay(3);
|
||||
|
||||
// Now do it backwards...
|
||||
motors.setStepperSteps(100);
|
||||
motors.enableStepper(upm::GroveMD::STEP_DIR_CCW, 10);
|
||||
|
||||
// now disable
|
||||
motors.disableStepper();
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
|
||||
#include "grovemd.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
// Instantiate an I2C Grove Motor Driver on I2C bus 0
|
||||
|
||||
upm::GroveMD motors(GROVEMD_I2C_BUS, GROVEMD_DEFAULT_I2C_ADDR);
|
||||
|
||||
// set direction to CW and set speed to 50%
|
||||
cout << "Spin M1 and M2 at half speed for 3 seconds" << endl;
|
||||
motors.setMotorDirections(upm::GroveMD::DIR_CW, upm::GroveMD::DIR_CW);
|
||||
motors.setMotorSpeeds(127, 127);
|
||||
|
||||
upm_delay(3);
|
||||
// counter clockwise
|
||||
cout << "Reversing M1 and M2 for 3 seconds" << endl;
|
||||
motors.setMotorDirections(upm::GroveMD::DIR_CCW, upm::GroveMD::DIR_CCW);
|
||||
upm_delay(3);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Stopping motors" << endl;
|
||||
motors.setMotorSpeeds(0, 0);
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "grovemoisture.hpp"
|
||||
#include "upm_utilities.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 Moisture sensor on analog pin A0
|
||||
upm::GroveMoisture moisture(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;
|
||||
|
||||
upm_delay(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* 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 <signal.h>
|
||||
|
||||
#include "groveo2.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
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(0);
|
||||
while (shouldRun) {
|
||||
cout << "The output voltage is: " << O2.voltageValue() << "mV" << endl;
|
||||
upm_delay_us(100000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
cout << "Exiting" << endl;
|
||||
return 0;
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
|
||||
#include "grovescam.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a Grove Serial Camera on UART 0
|
||||
upm::GROVESCAM camera(0);
|
||||
|
||||
// make sure port is initialized properly. 115200 baud is the default.
|
||||
if (!camera.setupTty()) {
|
||||
cerr << "Failed to setup tty port parameters" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (camera.init())
|
||||
cout << "Initialized..." << endl;
|
||||
else
|
||||
cout << "init() failed" << endl;
|
||||
|
||||
if (camera.preCapture())
|
||||
cout << "preCapture succeeded..." << endl;
|
||||
else
|
||||
cout << "preCapture failed." << endl;
|
||||
|
||||
if (camera.doCapture())
|
||||
cout << "doCapture succeeded..." << endl;
|
||||
else
|
||||
cout << "doCapture failed." << endl;
|
||||
|
||||
cout << "Image size is " << camera.getImageSize() << " bytes" << endl;
|
||||
|
||||
if (camera.getImageSize() > 0) {
|
||||
cout << "Storing image.jpg..." << endl;
|
||||
if (camera.storeImage("image.jpg"))
|
||||
cout << "storeImage succeeded..." << endl;
|
||||
else
|
||||
cout << "storeImage failed." << endl;
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
|
||||
#include "grovespeaker.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
//! [Interesting]
|
||||
// Instantiate a Grove Speaker on digital pin D2
|
||||
upm::GroveSpeaker speaker(2);
|
||||
|
||||
// Play all 7 of the lowest notes
|
||||
speaker.playAll();
|
||||
|
||||
// Play a medium C-sharp
|
||||
speaker.playSound('c', true, "med");
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Author: Jun Kato <i@junkato.jp>
|
||||
* Copyright (c) 2015 Jun Kato.
|
||||
*
|
||||
* Thanks to Seeed Studio for a working arduino sketch
|
||||
*
|
||||
* 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 "groveultrasonic.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
bool running = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT) {
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
// upm::GroveUltraSonic *sonar = NULL;
|
||||
upm::GroveUltraSonic sonar(2);
|
||||
while (running) {
|
||||
int width = sonar.getDistance();
|
||||
printf("Echo width = %d\n", width);
|
||||
printf("Distance inches = %f.2\n\n", width / 148.0);
|
||||
upm_delay(3);
|
||||
}
|
||||
//! [Interesting]
|
||||
printf("exiting application\n");
|
||||
return 0;
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "grovevdiv.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
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(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;
|
||||
|
||||
upm_delay(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "grovewater.hpp"
|
||||
#include "upm_utilities.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 Water sensor on digital pin D2
|
||||
upm::GroveWater water(2);
|
||||
|
||||
while (shouldRun) {
|
||||
bool val = water.isWet();
|
||||
if (val)
|
||||
cout << "Sensor is wet." << endl;
|
||||
else
|
||||
cout << "Sensor is dry." << endl;
|
||||
|
||||
upm_delay(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "grovewfs.hpp"
|
||||
#include "upm_utilities.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 Water Flow Sensor on digital pin D2
|
||||
upm::GroveWFS flow(2);
|
||||
|
||||
// set the flow counter to 0 and start counting
|
||||
flow.clearFlowCounter();
|
||||
flow.startFlowCounter();
|
||||
|
||||
while (shouldRun) {
|
||||
// we grab these (,illis and flowCount) just for display
|
||||
// purposes in this example
|
||||
uint32_t millis = flow.getMillis();
|
||||
uint32_t flowCount = flow.flowCounter();
|
||||
|
||||
float fr = flow.flowRate();
|
||||
|
||||
// output milliseconds passed, flow count, and computed flow rate
|
||||
cout << "Millis: " << millis << " Flow Count: " << flowCount;
|
||||
cout << " Flow Rate: " << fr << " LPM" << endl;
|
||||
|
||||
// best to gather data for at least one second for reasonable
|
||||
// results.
|
||||
upm_delay(2);
|
||||
}
|
||||
|
||||
flow.stopFlowCounter();
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user