mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 09:21:12 +03:00
examples: moved examples to new c++ subfolder
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
42
examples/c++/4digitdisplay.cxx
Normal file
42
examples/c++/4digitdisplay.cxx
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 "tm1637.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::TM1637 *display = new upm::TM1637(8, 9); // di - 8, dcki - 9
|
||||
display->write ("1337");
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete display;
|
||||
|
||||
return 0;
|
||||
}
|
250
examples/c++/CMakeLists.txt
Normal file
250
examples/c++/CMakeLists.txt
Normal file
@ -0,0 +1,250 @@
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples)
|
||||
|
||||
add_executable (hmc5883l-example hmc5883l.cxx)
|
||||
add_executable (groveled-example groveled.cxx)
|
||||
add_executable (groverelay-example groverelay.cxx)
|
||||
add_executable (grovelight-example grovelight.cxx)
|
||||
add_executable (grovetemp-example grovetemp.cxx)
|
||||
add_executable (grovebutton-example grovebutton.cxx)
|
||||
add_executable (groverotary-example groverotary.cxx)
|
||||
add_executable (groveslide-example groveslide.cxx)
|
||||
add_executable (lcm-lcd-example lcm-lcd.cxx)
|
||||
add_executable (rgb-lcd-example rgb-lcd.cxx)
|
||||
add_executable (buzzer-sound-example buzzer-sound.cxx)
|
||||
add_executable (led-bar-example led-bar.cxx)
|
||||
add_executable (seg-lcd-example 4digitdisplay.cxx)
|
||||
add_executable (nrf_transmitter-example nrf_transmitter.cxx)
|
||||
add_executable (nrf_receiver-example nrf_receiver.cxx)
|
||||
add_executable (es08a-example es08a.cxx)
|
||||
add_executable (son-hcsr04-example hcsr04.cxx)
|
||||
add_executable (oled-1308-example oled-1308.cxx)
|
||||
add_executable (oled-1327-example oled-1327.cxx)
|
||||
add_executable (max44000-example max44000.cxx)
|
||||
add_executable (mma7455-example mma7455.cxx)
|
||||
add_executable (st7735-example st7735.cxx)
|
||||
add_executable (max31855-example max31855.cxx)
|
||||
add_executable (gy65-example gy65.cxx)
|
||||
add_executable (stepmotor-example stepmotor.cxx)
|
||||
add_executable (pulsensor-example pulsensor.cxx)
|
||||
add_executable (mic-example mic.cxx)
|
||||
add_executable (mpu9150-example mpu9150.cxx)
|
||||
add_executable (maxds3231m-example maxds3231m.cxx)
|
||||
add_executable (max31723-example max31723.cxx)
|
||||
add_executable (max5487-example max5487.cxx)
|
||||
add_executable (nrf8001-broadcast-example nrf8001_broadcast.cxx)
|
||||
add_executable (nrf8001-helloworld-example nrf8001_helloworld.cxx)
|
||||
add_executable (lpd8806-example lpd8806.cxx)
|
||||
add_executable (mlx90614-example mlx90614.cxx)
|
||||
add_executable (ecs1030-example ecs1030.cxx)
|
||||
add_executable (mq2-example mq2.cxx)
|
||||
add_executable (mq3-example mq3.cxx)
|
||||
add_executable (mq5-example mq5.cxx)
|
||||
add_executable (mq9-example mq9.cxx)
|
||||
add_executable (tp401-example tp401.cxx)
|
||||
add_executable (tcs3414cs-example tcs3414cs.cxx)
|
||||
add_executable (th02-example th02.cxx)
|
||||
add_executable (ttp223-example ttp223.cxx)
|
||||
add_executable (lsm303-example lsm303.cxx)
|
||||
add_executable (joystick12-example joystick12-example.cxx)
|
||||
add_executable (lol-example lol-example.cxx)
|
||||
add_executable (nrf_ble_broadcast-example ble_broadcast.cxx)
|
||||
add_executable (tsl2561-example tsl2561.cxx)
|
||||
add_executable (htu21d-example htu21d.cxx)
|
||||
add_executable (mpl3115a2-example mpl3115a2.cxx)
|
||||
add_executable (ldt0028-example ldt0028.cxx)
|
||||
add_executable (am2315-example am2315.cxx)
|
||||
add_executable (itg3200-example itg3200.cxx)
|
||||
add_executable (enc03r-example enc03r.cxx)
|
||||
add_executable (adc121c021-example adc121c021.cxx)
|
||||
add_executable (ds1307-example ds1307.cxx)
|
||||
add_executable (a110x-example a110x.cxx)
|
||||
add_executable (gp2y0a21yk-example gp2y0a21yk.cxx)
|
||||
add_executable (grovemoisture-example grovemoisture.cxx)
|
||||
add_executable (groveehr-example groveehr.cxx)
|
||||
add_executable (ta12200-example ta12200.cxx)
|
||||
add_executable (grovelinefinder-example grovelinefinder.cxx)
|
||||
add_executable (grovevdiv-example grovevdiv.cxx)
|
||||
add_executable (grovewater-example grovewater.cxx)
|
||||
add_executable (guvas12d-example guvas12d.cxx)
|
||||
add_executable (groveloudness-example groveloudness.cxx)
|
||||
add_executable (mpr121-example mpr121.cxx)
|
||||
add_executable (ublox6-example ublox6.cxx)
|
||||
add_executable (yg1006-example yg1006.cxx)
|
||||
add_executable (wt5001-example wt5001.cxx)
|
||||
add_executable (ppd42ns-example ppd42ns.cxx)
|
||||
add_executable (mq303a-example mq303a.cxx)
|
||||
add_executable (grovespeaker-example grovespeaker.cxx)
|
||||
add_executable (rfr359f-example rfr359f.cxx)
|
||||
add_executable (biss0001-example biss0001.cxx)
|
||||
add_executable (my9221-example my9221.cxx)
|
||||
add_executable (grove_mcfled-example grove_mcfled.cxx)
|
||||
add_executable (rotaryencoder-example rotaryencoder.cxx)
|
||||
add_executable (adxl345-example adxl345.cxx)
|
||||
add_executable (rpr220-example rpr220.cxx)
|
||||
add_executable (rpr220-intr-example rpr220-intr.cxx)
|
||||
add_executable (mma7660-example mma7660.cxx)
|
||||
add_executable (cjq4435-example cjq4435.cxx)
|
||||
add_executable (adxl335-example adxl335.cxx)
|
||||
add_executable (hmtrp-example hmtrp.cxx)
|
||||
add_executable (nunchuck-example nunchuck.cxx)
|
||||
add_executable (otp538u-example otp538u.cxx)
|
||||
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/lcd)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/buzzer)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/my9221)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/tm1637)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/nrf24l01)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/servo)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/hcsr04)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/max44000)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/mma7455)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/st7735)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/max31855)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/gy65)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/stepmotor)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/pulsensor)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/mic)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/mpu9150)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/maxds3231m)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/max31723)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/max5487)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/nrf8001)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/lpd8806)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/mlx90614)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/ecs1030)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/gas)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/tcs3414cs)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/th02)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/ttp223)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/lsm303)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/joystick12)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/lol)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/tsl2561)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/htu21d)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/mpl3115a2)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/ldt0028)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/am2315)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/itg3200)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/enc03r)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/adc121c021)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/ds1307)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/a110x)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/gp2y0a21yk)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/grovemoisture)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/groveehr)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/ta12200)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/grovelinefinder)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/grovevdiv)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/grovewater)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/guvas12d)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/groveloudness)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/mpr121)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/ublox6)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/yg1006)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/wt5001)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/ppd42ns)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/mq303a)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/grovespeaker)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/rfr359f)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/biss0001)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/my9221)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/rotaryencoder)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/adxl345)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/rpr220)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/mma7660)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/cjq4435)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/adxl335)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/hmtrp)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/nunchuck)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/otp538u)
|
||||
|
||||
target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (groverelay-example grove ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (grovelight-example grove ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (grovetemp-example grove ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (grovebutton-example grove ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (groverotary-example grove ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (groveslide-example grove ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (lcm-lcd-example i2clcd ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (rgb-lcd-example i2clcd ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (buzzer-sound-example buzzer ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (led-bar-example my9221 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (seg-lcd-example tm1637 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (nrf_transmitter-example nrf24l01 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (nrf_receiver-example nrf24l01 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (es08a-example servo ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (son-hcsr04-example hcsr04 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (oled-1308-example i2clcd ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (oled-1327-example i2clcd ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (max44000-example max44000 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (mma7455-example mma7455 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (st7735-example st7735 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (max31855-example max31855 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (gy65-example gy65 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (stepmotor-example stepmotor ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (pulsensor-example pulsensor ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (mic-example mic ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (mpu9150-example mpu9150 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (maxds3231m-example maxds3231m ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (max31723-example max31723 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (max5487-example max5487 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (nrf8001-broadcast-example nrf8001 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (nrf8001-helloworld-example nrf8001 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (lpd8806-example lpd8806 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (mlx90614-example mlx90614 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (ecs1030-example ecs1030 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (mq2-example gas ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (mq3-example gas ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (mq5-example gas ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (mq9-example gas ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (tp401-example gas ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (tcs3414cs-example tcs3414cs ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (th02-example th02 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (ttp223-example ttp223 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (lsm303-example lsm303 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (joystick12-example joystick12 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (lol-example lol ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (nrf_ble_broadcast-example nrf24l01 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (tsl2561-example tsl2561 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (htu21d-example htu21d ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (mpl3115a2-example mpl3115a2 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (ldt0028-example ldt0028 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (am2315-example am2315 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (itg3200-example itg3200 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (enc03r-example enc03r ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (adc121c021-example adc121c021 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (ds1307-example ds1307 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (a110x-example a110x ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (gp2y0a21yk-example gp2y0a21yk ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (grovemoisture-example grovemoisture ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (groveehr-example groveehr ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (ta12200-example ta12200 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (grovelinefinder-example grovelinefinder ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (grovevdiv-example grovevdiv ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (grovewater-example grovewater ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (guvas12d-example guvas12d ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (groveloudness-example groveloudness ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (mpr121-example mpr121 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (ublox6-example ublox6 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (yg1006-example yg1006 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (wt5001-example wt5001 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (ppd42ns-example ppd42ns ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (mq303a-example mq303a ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (grovespeaker-example grovespeaker ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (rfr359f-example rfr359f ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (biss0001-example biss0001 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (my9221-example my9221 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (grove_mcfled-example grove ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (rotaryencoder-example rotaryencoder ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (adxl345-example adxl345 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (rpr220-example rpr220 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (rpr220-intr-example rpr220 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (mma7660-example mma7660 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (cjq4435-example cjq4435 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (adxl335-example adxl335 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (hmtrp-example hmtrp ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (nunchuck-example nunchuck ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (otp538u-example otp538u ${CMAKE_THREAD_LIBS_INIT})
|
67
examples/c++/a110x.cxx
Normal file
67
examples/c++/a110x.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 "a110x.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 an A110X sensor on digital pin D2
|
||||
upm::A110X* hall = new upm::A110X(2);
|
||||
|
||||
// check every second for the presence of a magnetic field (south
|
||||
// polarity)
|
||||
while (shouldRun)
|
||||
{
|
||||
bool val = hall->magnetDetected();
|
||||
if (val)
|
||||
cout << "Magnet (south polarity) detected." << endl;
|
||||
else
|
||||
cout << "No magnet detected." << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete hall;
|
||||
return 0;
|
||||
}
|
66
examples/c++/adc121c021.cxx
Normal file
66
examples/c++/adc121c021.cxx
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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 <signal.h>
|
||||
#include <iostream>
|
||||
#include "adc121c021.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]
|
||||
// Instantiate an ADC121C021 on I2C bus 0
|
||||
|
||||
upm::ADC121C021 *adc = new upm::ADC121C021(ADC121C021_I2C_BUS,
|
||||
ADC121C021_DEFAULT_I2C_ADDR);
|
||||
|
||||
// An analog sensor, such as a Grove light sensor,
|
||||
// must be attached to the adc
|
||||
// Prints the value and corresponding voltage every 50 milliseconds
|
||||
while (shouldRun)
|
||||
{
|
||||
uint16_t val = adc->value();
|
||||
cout << "ADC value: " << val << " Volts = "
|
||||
<< adc->valueToVolts(val) << endl;
|
||||
usleep(50000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete adc;
|
||||
return 0;
|
||||
}
|
78
examples/c++/adxl335.cxx
Normal file
78
examples/c++/adxl335.cxx
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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 "adxl335.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 an ADXL335 accelerometer on analog pins A0, A1, and A2
|
||||
upm::ADXL335* accel = new upm::ADXL335(0, 1, 2);
|
||||
|
||||
cout << "Please make sure the sensor is completely still. Sleeping for"
|
||||
<< " 2 seconds." << endl;
|
||||
sleep(2);
|
||||
cout << "Calibrating..." << endl;
|
||||
|
||||
accel->calibrate();
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
int x, y, z;
|
||||
float aX, aY, aZ;
|
||||
|
||||
accel->values(&x, &y, &z);
|
||||
cout << "Raw Values: X: " << x << " Y: " << y << " Z: " << z << endl;
|
||||
|
||||
accel->acceleration(&aX, &aY, &aZ);
|
||||
cout << "Acceleration: X: " << aX << "g" << endl;
|
||||
cout << "Acceleration: Y: " << aY << "g" << endl;
|
||||
cout << "Acceleration: Z: " << aZ << "g" << endl;
|
||||
cout << endl;
|
||||
|
||||
usleep(200000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete accel;
|
||||
return 0;
|
||||
}
|
51
examples/c++/adxl345.cxx
Normal file
51
examples/c++/adxl345.cxx
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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 "adxl345.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
int16_t *raw;
|
||||
float *acc;
|
||||
|
||||
// Note: Sensor only works at 3.3V on the Intel Edison with Arduino breakout
|
||||
upm::Adxl345* accel = new upm::Adxl345(0);
|
||||
|
||||
while(true){
|
||||
accel->update(); // Update the data
|
||||
raw = accel->getRawValues(); // Read raw sensor data
|
||||
acc = accel->getAcceleration(); // Read acceleration (g)
|
||||
fprintf(stdout, "Current scale: 0x%2xg\n", accel->getScale());
|
||||
fprintf(stdout, "Raw: %6d %6d %6d\n", raw[0], raw[1], raw[2]);
|
||||
fprintf(stdout, "AccX: %5.2f g\n", acc[0]);
|
||||
fprintf(stdout, "AccY: %5.2f g\n", acc[1]);
|
||||
fprintf(stdout, "AccZ: %5.2f g\n", acc[2]);
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
75
examples/c++/am2315.cxx
Normal file
75
examples/c++/am2315.cxx
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Author: William Penner <william.penner@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 <signal.h>
|
||||
|
||||
#include "am2315.h"
|
||||
|
||||
volatile int doWork = 0;
|
||||
|
||||
upm::AM2315 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT) {
|
||||
printf("\nCtrl-C received.\n");
|
||||
doWork = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
// Register signal handler
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
float humidity = 0.0;
|
||||
float temperature = 0.0;
|
||||
|
||||
sensor = new upm::AM2315(0, AM2315_I2C_ADDRESS);
|
||||
|
||||
sensor->testSensor();
|
||||
|
||||
while (!doWork) {
|
||||
humidity = sensor->getHumidity();
|
||||
temperature = sensor->getTemperature();
|
||||
|
||||
std::cout << "humidity value = " <<
|
||||
humidity <<
|
||||
", temperature value = " <<
|
||||
temperature << std::endl;
|
||||
usleep (500000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
68
examples/c++/biss0001.cxx
Normal file
68
examples/c++/biss0001.cxx
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Author: Zion Orent <zorent@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 "biss0001.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 Motion sensor on GPIO pin D2
|
||||
upm::BISS0001* motion = new upm::BISS0001(2);
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
bool val = motion->value();
|
||||
|
||||
if (val)
|
||||
cout << "Detecting moving object";
|
||||
else
|
||||
cout << "No moving objects detected";
|
||||
|
||||
cout << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete motion;
|
||||
return 0;
|
||||
}
|
81
examples/c++/ble_broadcast.cxx
Normal file
81
examples/c++/ble_broadcast.cxx
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 <string.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "nrf24l01.h"
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
|
||||
int running = 0;
|
||||
upm::NRF24L01 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
running = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void nrf_handler () {
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
sensor = new upm::NRF24L01(7, 8);
|
||||
sensor->setBeaconingMode ();
|
||||
|
||||
std::vector<std::string> msgs;
|
||||
|
||||
msgs.push_back ("Hello World 1!!!");
|
||||
msgs.push_back ("Hello World 2!!!");
|
||||
msgs.push_back ("Hello World 3!!!");
|
||||
msgs.push_back ("Hello World 4!!!");
|
||||
msgs.push_back ("Hello World 5!!!");
|
||||
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
while (!running) {
|
||||
for (std::vector<std::string>::iterator item = msgs.begin(); item != msgs.end(); ++item) {
|
||||
std::cout << "BROADCASTING " << (*item).c_str() << std::endl;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
sensor->sendBeaconingMsg ((uint8_t*) (*item).c_str());
|
||||
usleep (1000000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
msgs.clear();
|
||||
delete sensor;
|
||||
return 0;
|
||||
}
|
54
examples/c++/buzzer-sound.cxx
Normal file
54
examples/c++/buzzer-sound.cxx
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 <signal.h>
|
||||
#include "buzzer.h"
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv) {
|
||||
//! [Interesting]
|
||||
int chord[] = { DO, RE, MI, FA, SOL, LA, SI, DO, SI };
|
||||
|
||||
// create Buzzer instance
|
||||
upm::Buzzer* sound = new upm::Buzzer(5);
|
||||
// print sensor name
|
||||
std::cout << sound->name() << std::endl;
|
||||
|
||||
// play sound (DO, RE, MI, etc...), pausing for 0.1 seconds between notes
|
||||
for (int chord_ind = 0; chord_ind < 7; chord_ind++) {
|
||||
// play each note for one second
|
||||
std::cout << sound->playSound(chord[chord_ind], 1000000) << std::endl;
|
||||
usleep(100000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sound;
|
||||
|
||||
return 0;
|
||||
}
|
77
examples/c++/cjq4435.cxx
Normal file
77
examples/c++/cjq4435.cxx
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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 "cjq4435.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 CJQ4435 MOSFET on a PWM capable digital pin D3
|
||||
upm::CJQ4435* mosfet = new upm::CJQ4435(3);
|
||||
|
||||
mosfet->setPeriodMS(10);
|
||||
mosfet->enable(true);
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
// start with a duty cycle of 0.0 (off) and increment to 1.0 (on)
|
||||
for (float i=0.0; i <= 1.0; i+=0.1)
|
||||
{
|
||||
mosfet->setDutyCycle(i);
|
||||
usleep(100000);
|
||||
}
|
||||
sleep(1);
|
||||
// Now take it back down
|
||||
// start with a duty cycle of 1.0 (on) and decrement to 0.0 (off)
|
||||
for (float i=1.0; i >= 0.0; i-=0.1)
|
||||
{
|
||||
mosfet->setDutyCycle(i);
|
||||
usleep(100000);
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete mosfet;
|
||||
return 0;
|
||||
}
|
77
examples/c++/ds1307.cxx
Normal file
77
examples/c++/ds1307.cxx
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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 "ds1307.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void printTime(upm::DS1307 *rtc)
|
||||
{
|
||||
cout << "The time is: " <<
|
||||
rtc->month << "/" << rtc->dayOfMonth << "/" << rtc->year << " "
|
||||
<< rtc->hours << ":" << rtc->minutes << ":" << rtc->seconds;
|
||||
|
||||
if (rtc->amPmMode)
|
||||
cout << (rtc->pm) ? " PM " : " AM ";
|
||||
|
||||
cout << endl;
|
||||
|
||||
cout << "Clock is in " << ((rtc->amPmMode) ? "AM/PM mode" : "24hr mode")
|
||||
<< endl;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
// Instantiate a DS1037 on I2C bus 0
|
||||
upm::DS1307 *rtc = new upm::DS1307(0);
|
||||
|
||||
// always do this first
|
||||
cout << "Loading the current time... " << endl;
|
||||
if (!rtc->loadTime())
|
||||
{
|
||||
cerr << "rtc->loadTime() failed." << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
printTime(rtc);
|
||||
|
||||
// set the year as an example
|
||||
cout << "setting the year to 50" << endl;
|
||||
rtc->year = 50;
|
||||
|
||||
rtc->setTime();
|
||||
|
||||
// reload the time and print it
|
||||
rtc->loadTime();
|
||||
printTime(rtc);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
delete rtc;
|
||||
return 0;
|
||||
}
|
61
examples/c++/ecs1030.cxx
Normal file
61
examples/c++/ecs1030.cxx
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include "ecs1030.h"
|
||||
|
||||
int is_running = 0;
|
||||
upm::ECS1030 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
is_running = 1;
|
||||
}
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
sensor = new upm::ECS1030(0);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
while (!is_running) {
|
||||
std::cout << "I = " << sensor->getCurrency_A () << ", Power = " << sensor->getPower_A () << std::endl;
|
||||
std::cout << "I = " << sensor->getCurrency_B () << ", Power = " << sensor->getPower_B () << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
79
examples/c++/enc03r.cxx
Normal file
79
examples/c++/enc03r.cxx
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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 "enc03r.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
// analog voltage, usually 3.3 or 5.0
|
||||
#define CALIBRATION_SAMPLES 1000
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a ENC03R on analog pin A0
|
||||
upm::ENC03R *gyro = new upm::ENC03R(0);
|
||||
|
||||
// The first thing we need to do is calibrate the sensor.
|
||||
cout << "Please place the sensor in a stable location, and do not" << endl;
|
||||
cout << "move it while calibration takes place." << endl;
|
||||
cout << "This may take a couple of minutes." << endl;
|
||||
|
||||
gyro->calibrate(CALIBRATION_SAMPLES);
|
||||
cout << "Calibration complete. Reference value: "
|
||||
<< gyro->calibrationValue() << endl;
|
||||
|
||||
// Read the input and print both the raw value and the angular velocity,
|
||||
// waiting 0.1 seconds between readings
|
||||
while (shouldRun)
|
||||
{
|
||||
unsigned int val = gyro->value();
|
||||
double av = gyro->angularVelocity(val);
|
||||
|
||||
cout << "Raw value: " << val << ", "
|
||||
<< "angular velocity: " << av << " deg/s" << endl;
|
||||
|
||||
usleep(100000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete gyro;
|
||||
return 0;
|
||||
}
|
61
examples/c++/es08a.cxx
Normal file
61
examples/c++/es08a.cxx
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 "es08a.h"
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::ES08A *servo = new upm::ES08A(5);
|
||||
|
||||
// Sets the shaft to 180, then to 90, then to 0,
|
||||
// then back to 90, and finally back to 180,
|
||||
// pausing for a second in between each angle
|
||||
servo->setAngle (180);
|
||||
std::cout << "Set angle to 180" << std::endl;
|
||||
sleep(1);
|
||||
servo->setAngle (90);
|
||||
std::cout << "Set angle to 90" << std::endl;
|
||||
sleep(1);
|
||||
servo->setAngle (0);
|
||||
std::cout << "Set angle to 0" << std::endl;
|
||||
sleep(1);
|
||||
servo->setAngle (90);
|
||||
std::cout << "Set angle to 90" << std::endl;
|
||||
sleep(1);
|
||||
servo->setAngle (180);
|
||||
std::cout << "Set angle to 180" << std::endl;
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete servo;
|
||||
|
||||
return 0;
|
||||
}
|
73
examples/c++/gp2y0a21yk.cxx
Normal file
73
examples/c++/gp2y0a21yk.cxx
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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 "gp2y0a21yk.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
// analog voltage, usually 3.3 or 5.0
|
||||
#define GP2Y0A21YK_AREF 5.0
|
||||
#define SAMPLES_PER_QUERY 20
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// Note, for the Grove version of this sensor, due to the way it is wired,
|
||||
// you need to plug this into the A0 port, where it will use the available
|
||||
// A1 pin for data.
|
||||
|
||||
// Instantiate a GP2Y0A21YK on analog pin A1
|
||||
upm::GP2Y0A21YK *volts = new upm::GP2Y0A21YK(1);
|
||||
|
||||
// The higher the voltage (closer to AREF) the closer the object is. NOTE:
|
||||
// the measured voltage will probably not exceed 3.3 volts.
|
||||
// Every second, print the averaged voltage value (averaged over 20 samples).
|
||||
while (shouldRun)
|
||||
{
|
||||
cout << "AREF: " << GP2Y0A21YK_AREF
|
||||
<< ", Voltage value (higher means closer): "
|
||||
<< volts->value(GP2Y0A21YK_AREF, SAMPLES_PER_QUERY) << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete volts;
|
||||
return 0;
|
||||
}
|
68
examples/c++/grove_mcfled.cxx
Normal file
68
examples/c++/grove_mcfled.cxx
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2014-2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "grove.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a grove LED on D2. Here we are controlling a Grove
|
||||
// Multi-color flash LED. We just just need to turn it on - it will
|
||||
// then cycle through various colors (red, green, blue, purple) on it's
|
||||
// own until turned off.
|
||||
upm::GroveLed* led = new upm::GroveLed(2);
|
||||
|
||||
// start the light show
|
||||
led->on();
|
||||
|
||||
// just sleep until interrupted
|
||||
while (shouldRun)
|
||||
sleep(1);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
led->off();
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete led;
|
||||
|
||||
return 0;
|
||||
}
|
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.h"
|
||||
|
||||
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;
|
||||
}
|
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.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 = 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;
|
||||
}
|
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.h"
|
||||
|
||||
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.h"
|
||||
|
||||
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;
|
||||
}
|
66
examples/c++/grovelinefinder.cxx
Normal file
66
examples/c++/grovelinefinder.cxx
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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 "grovelinefinder.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 = new upm::GroveLineFinder(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;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete finder;
|
||||
return 0;
|
||||
}
|
63
examples/c++/groveloudness.cxx
Normal file
63
examples/c++/groveloudness.cxx
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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 "groveloudness.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 Loudness sensor on analog pin A0
|
||||
upm::GroveLoudness* loudness = new upm::GroveLoudness(0);
|
||||
|
||||
// Print the loudness value every 0.1 seconds
|
||||
while (shouldRun)
|
||||
{
|
||||
int val = loudness->value();
|
||||
cout << "Loudness value (higher is louder): " << val << endl;
|
||||
|
||||
usleep(100000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete loudness;
|
||||
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.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 = 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;
|
||||
}
|
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.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 = 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.h"
|
||||
|
||||
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.h"
|
||||
|
||||
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.h"
|
||||
|
||||
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.h"
|
||||
|
||||
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.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 = 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.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 = 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;
|
||||
}
|
72
examples/c++/guvas12d.cxx
Normal file
72
examples/c++/guvas12d.cxx
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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 "guvas12d.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
// analog voltage, usually 3.3 or 5.0
|
||||
#define GUVAS12D_AREF 5.0
|
||||
#define SAMPLES_PER_QUERY 1024
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// The was tested with the Grove UV Sensor module.
|
||||
// It has a sensing range from between 200-400nm. It's strongest
|
||||
// response is around 320-360nm.
|
||||
|
||||
// Instantiate a GUVAS12D on analog pin A0
|
||||
upm::GUVAS12D *volts = new upm::GUVAS12D(0);
|
||||
|
||||
// The higher the voltage the more intense the UV radiation.
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
cout << "AREF: " << GUVAS12D_AREF
|
||||
<< ", Voltage value (higher means more UV): "
|
||||
<< volts->value(GUVAS12D_AREF, SAMPLES_PER_QUERY) << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete volts;
|
||||
return 0;
|
||||
}
|
80
examples/c++/gy65.cxx
Normal file
80
examples/c++/gy65.cxx
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 "gy65.h"
|
||||
#include <signal.h>
|
||||
|
||||
int doWork = 0;
|
||||
upm::GY65 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
doWork = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
uint32_t presure = 0;
|
||||
float temperature = 0;
|
||||
float altitude = 0;
|
||||
uint32_t sealevel = 0;
|
||||
|
||||
// Instantiate a GY65 sensor on I2C
|
||||
sensor = new upm::GY65(0, ADDR);
|
||||
|
||||
// Print the pressure, altitude, sea level, and
|
||||
// temperature values every 0.1 seconds
|
||||
while (!doWork) {
|
||||
presure = sensor->getPressure ();
|
||||
temperature = sensor->getTemperature ();
|
||||
altitude = sensor->getAltitude ();
|
||||
sealevel = sensor->getSealevelPressure ();
|
||||
|
||||
std::cout << "pressure value = " <<
|
||||
presure <<
|
||||
", altitude value = " <<
|
||||
altitude <<
|
||||
", sealevel value = " <<
|
||||
sealevel <<
|
||||
", temperature = " <<
|
||||
temperature << std::endl;
|
||||
usleep (100000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
63
examples/c++/hcsr04.cxx
Normal file
63
examples/c++/hcsr04.cxx
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 "hcsr04.h"
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
upm::HCSR04 *sonar = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
sonar->m_doWork = 1;
|
||||
}
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
void
|
||||
interrupt (void * args) {
|
||||
sonar->ackEdgeDetected ();
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
sonar = new upm::HCSR04(5, 7, &interrupt);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
printf ("width = %d\n", sonar->getDistance());
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sonar;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
50
examples/c++/hmc5883l.cxx
Normal file
50
examples/c++/hmc5883l.cxx
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Contributions: 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 "hmc5883l.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
// Instantiate on I2C
|
||||
upm::Hmc5883l* compass = new upm::Hmc5883l(0);
|
||||
int16_t *pos;
|
||||
|
||||
compass->set_declination(0.2749); // Set your declination from true north in radians
|
||||
|
||||
// Print out the coordinates, heading, and direction every second
|
||||
while(true){
|
||||
compass->update(); // Update the coordinates
|
||||
pos = compass->coordinates();
|
||||
fprintf(stdout, "coor: %5d %5d %5d ", pos[0], pos[1], pos[2]);
|
||||
fprintf(stdout, "heading: %5.2f direction: %3.2f\n", compass->heading(), compass->direction());
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
164
examples/c++/hmtrp.cxx
Normal file
164
examples/c++/hmtrp.cxx
Normal file
@ -0,0 +1,164 @@
|
||||
/*
|
||||
* 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 "hmtrp.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
void printUsage()
|
||||
{
|
||||
cout << "Usage:" << endl;
|
||||
cout << "Pass a commandline argument (any argument) to this program"
|
||||
<< endl;
|
||||
cout << "to query the radio configuration and output it. NOTE: the"
|
||||
<< endl;
|
||||
cout << "radio must be in CONFIG mode for this to work."
|
||||
<< endl;
|
||||
cout << endl;
|
||||
cout << "Running this program without arguments will simply transmit"
|
||||
<< endl;
|
||||
cout << "'Hello World!' every second, and output any data received from"
|
||||
<< endl;
|
||||
cout << "another radio."
|
||||
<< endl;
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
const size_t bufferLength = 256;
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// Instantiate a HMTRP radio device on uart 0
|
||||
|
||||
upm::HMTRP* radio = new upm::HMTRP(0);
|
||||
|
||||
// make sure port is initialized properly. 9600 baud is the default.
|
||||
if (!radio->setupTty(B9600))
|
||||
{
|
||||
cerr << "Failed to setup tty port parameters" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
printUsage();
|
||||
|
||||
// By default, this radio simply transmits data sent via writeData()
|
||||
// and reads any available data via readData().
|
||||
|
||||
// It can be placed into a configuration mode by grounding the
|
||||
// CONFIG pin on the module. When this is done, the various
|
||||
// configuration query and config methods can be used. In this
|
||||
// example, by default, we just read any data available fom the
|
||||
// device, and periodically transmit "Hello World".
|
||||
|
||||
// If any argument was specified on the command line, do a simple
|
||||
// configuration query and output the results. The radio must be in
|
||||
// CONFIG mode for this to work.
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
// config mode
|
||||
uint32_t freq;
|
||||
uint32_t dataRate;
|
||||
uint16_t rxBandwidth;
|
||||
uint8_t modulation;
|
||||
uint8_t txPower;
|
||||
uint32_t uartBaud;
|
||||
|
||||
if (radio->getConfig(&freq, &dataRate, &rxBandwidth, &modulation,
|
||||
&txPower, &uartBaud))
|
||||
{
|
||||
cout << "Radio configuration:" << endl;
|
||||
cout << "freq: " << freq << " dataRate: " << dataRate
|
||||
<< " rxBandwidth: " << rxBandwidth << "Khz" << endl;
|
||||
|
||||
cout << "modulation: " << int(modulation) << "Khz txPower: "
|
||||
<< int(txPower) << " uartBaud: " << uartBaud << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "getConfig() failed. Make sure the radio is in "
|
||||
<< "CONFIG mode." << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// normal read/write mode
|
||||
char radioBuffer[bufferLength];
|
||||
int counter = 0;
|
||||
cout << "Running in normal read/write mode." << endl;
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
// we don't want the read to block in this example, so always
|
||||
// check to see if data is available first.
|
||||
if (radio->dataAvailable())
|
||||
{
|
||||
int rv = radio->readData(radioBuffer, bufferLength);
|
||||
|
||||
if (rv > 0)
|
||||
cout << "Received: " << radioBuffer << endl;
|
||||
|
||||
if (rv < 0) // some sort of read error occured
|
||||
{
|
||||
cerr << "Port read error." << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
usleep(100000); // 100ms
|
||||
counter++;
|
||||
// every second, transmit "Hello World"
|
||||
if (counter > 10)
|
||||
{
|
||||
static const char *hello = "Hello World!";
|
||||
cout << "Transmitting hello world..." << endl;
|
||||
radio->writeData((char *)hello, strlen(hello) + 1);
|
||||
counter = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete radio;
|
||||
return 0;
|
||||
}
|
79
examples/c++/htu21d.cxx
Normal file
79
examples/c++/htu21d.cxx
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Author: William Penner <william.penner@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 <signal.h>
|
||||
|
||||
#include "htu21d.h"
|
||||
|
||||
volatile int doWork = 0;
|
||||
|
||||
upm::HTU21D *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT) {
|
||||
printf("\nCtrl-C received.\n");
|
||||
doWork = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
// Register signal handler
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
float humidity = 0.0;
|
||||
float temperature = 0.0;
|
||||
float compRH = 0.0;
|
||||
|
||||
sensor = new upm::HTU21D(0, HTU21D_I2C_ADDRESS);
|
||||
|
||||
sensor->testSensor();
|
||||
|
||||
while (!doWork) {
|
||||
compRH = sensor->getCompRH(true);
|
||||
humidity = sensor->getHumidity(false);
|
||||
temperature = sensor->getTemperature(false);
|
||||
|
||||
std::cout << "humidity value = " <<
|
||||
humidity <<
|
||||
", temperature value = " <<
|
||||
temperature <<
|
||||
", compensated RH value = " <<
|
||||
compRH << std::endl;
|
||||
usleep (500000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
51
examples/c++/itg3200.cxx
Normal file
51
examples/c++/itg3200.cxx
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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 "itg3200.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
int16_t *rot;
|
||||
float *ang;
|
||||
|
||||
// Note: Sensor not supported on Intel Edison with Arduino breakout
|
||||
upm::Itg3200* gyro = new upm::Itg3200(0);
|
||||
|
||||
while(true){
|
||||
gyro->update(); // Update the data
|
||||
rot = gyro->getRawValues(); // Read raw sensor data
|
||||
ang = gyro->getRotation(); // Read rotational speed (deg/sec)
|
||||
fprintf(stdout, "Raw: %6d %6d %6d\n", rot[0], rot[1], rot[2]);
|
||||
fprintf(stdout, "AngX: %5.2f\n", ang[0]);
|
||||
fprintf(stdout, "AngY: %5.2f\n", ang[1]);
|
||||
fprintf(stdout, "AngZ: %5.2f\n", ang[2]);
|
||||
fprintf(stdout, "Temp: %5.2f Raw: %6d\n", gyro->getTemperature(), gyro->getRawTemp());
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
66
examples/c++/joystick12-example.cxx
Normal file
66
examples/c++/joystick12-example.cxx
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Author: Alexander Komarov <alexander.komarov@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 <signal.h>
|
||||
#include "joystick12.h"
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
int is_running = 0;
|
||||
upm::Joystick12 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
is_running = 1;
|
||||
}
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
// Instantiate a joystick on analog pins A0 and A1
|
||||
sensor = new upm::Joystick12(0,1);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
// Print the X and Y input values every second
|
||||
while (!is_running) {
|
||||
float x = sensor->getXInput();
|
||||
float y = sensor->getYInput();
|
||||
std::cout << "Driving X:" << x << ": and Y:" << y << std::endl;
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
42
examples/c++/lcm-lcd.cxx
Normal file
42
examples/c++/lcm-lcd.cxx
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "lcm1602.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::Lcm1602* lcd = new upm::Lcm1602(0, 0x27);
|
||||
lcd->setCursor(0,0);
|
||||
lcd->write("Hello World");
|
||||
//! [Interesting]
|
||||
lcd->setCursor(1,2);
|
||||
lcd->write("Hello World");
|
||||
lcd->setCursor(2,4);
|
||||
lcd->write("Hello World");
|
||||
lcd->setCursor(3,6);
|
||||
lcd->write("Hello World");
|
||||
lcd->close();
|
||||
}
|
90
examples/c++/ldt0028.cxx
Normal file
90
examples/c++/ldt0028.cxx
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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 <iomanip>
|
||||
#include <cmath>
|
||||
#include "ldt0028.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
const int NUMBER_OF_SECONDS = 10;
|
||||
const int MICROSECONDS_PER_SECOND = 1000000;
|
||||
const int SAMPLES_PER_SECOND = 50;
|
||||
const int THRESHOLD = 100;
|
||||
|
||||
// Create the LDT0-028 Piezo Vibration Sensor object using AIO pin 0
|
||||
upm::LDT0028* sensor = new upm::LDT0028(0);
|
||||
|
||||
// Read the signal every 20 milliseconds for 10 seconds
|
||||
std::cout << "For the next " << NUMBER_OF_SECONDS << " seconds, "
|
||||
<< SAMPLES_PER_SECOND << " samples will be taken every second."
|
||||
<< std::endl << std::endl;
|
||||
uint16_t* buffer = new uint16_t[NUMBER_OF_SECONDS * SAMPLES_PER_SECOND];
|
||||
for (int i=0; i < NUMBER_OF_SECONDS * SAMPLES_PER_SECOND; i++) {
|
||||
buffer[i] = (uint16_t) sensor->getSample();
|
||||
usleep(MICROSECONDS_PER_SECOND / SAMPLES_PER_SECOND);
|
||||
}
|
||||
|
||||
// Print the number of times the reading was greater than the threshold
|
||||
int count = 0;
|
||||
for (int i=0; i < NUMBER_OF_SECONDS * SAMPLES_PER_SECOND; i++) {
|
||||
if (buffer[i] > THRESHOLD) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
std::cout << sensor->name() << " exceeded the threshold value of " <<
|
||||
THRESHOLD << " a total of " << count << " times," << std::endl
|
||||
<< "out of a total of " << NUMBER_OF_SECONDS*SAMPLES_PER_SECOND
|
||||
<< " readings." << std::endl << std::endl;
|
||||
|
||||
// Print a graphical representation of the average value sampled
|
||||
// each second for the past 10 seconds, using a scale factor of 15
|
||||
std::cout << "Now printing a graphical representation of the average reading "
|
||||
<< std::endl << "each second for the last "
|
||||
<< NUMBER_OF_SECONDS << " seconds." << std::endl;
|
||||
const int SCALE_FACTOR = 15;
|
||||
for (int i=0; i < NUMBER_OF_SECONDS; i++) {
|
||||
long sum = 0;
|
||||
for (int j=0; j < SAMPLES_PER_SECOND; j++) {
|
||||
sum += buffer[i*SAMPLES_PER_SECOND + j];
|
||||
}
|
||||
double average = (double) sum / (double) SAMPLES_PER_SECOND;
|
||||
int stars_to_print = (int) round(average / SCALE_FACTOR);
|
||||
std::cout << "(" << std::setw(4) << (int) round(average) << ") | ";
|
||||
for (int j=0; j<stars_to_print; j++) {
|
||||
std::cout << "*";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// Delete the sensor object
|
||||
delete sensor;
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
63
examples/c++/led-bar.cxx
Normal file
63
examples/c++/led-bar.cxx
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 "my9221.h"
|
||||
#include <signal.h>
|
||||
|
||||
int running = 0;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
running = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::MY9221 *bar = new upm::MY9221(8, 9);
|
||||
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
while (!running) {
|
||||
for (int idx = 1; idx < 11; idx++) {
|
||||
bar->setBarLevel (idx);
|
||||
usleep(1000);
|
||||
}
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete bar;
|
||||
|
||||
return 0;
|
||||
}
|
67
examples/c++/lol-example.cxx
Normal file
67
examples/c++/lol-example.cxx
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Author: Alexander Komarov <alexander.komarov@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 <signal.h>
|
||||
#include "lol.h"
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
int is_running = 0;
|
||||
upm::LoL *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
is_running = 1;
|
||||
}
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
sensor = new upm::LoL();
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
unsigned char *buffer;
|
||||
//buffer = sensor->getFramebuffer();
|
||||
int x = 0, y = 0;
|
||||
while (!is_running) {
|
||||
sensor->setPixel(x, y, !(sensor->getPixel(x, y)));
|
||||
if (++x == 13) { x = 0; y++; }
|
||||
if (y == 9) y = 0;
|
||||
usleep(10000);
|
||||
}
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
104
examples/c++/lpd8806.cxx
Normal file
104
examples/c++/lpd8806.cxx
Normal file
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 "lpd8806.h"
|
||||
#include <signal.h>
|
||||
|
||||
void scanner(uint8_t r, uint8_t g, uint8_t b, uint8_t wait);
|
||||
|
||||
int doWork = 0;
|
||||
upm::LPD8806 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
doWork = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
sensor = new upm::LPD8806(10, 7);
|
||||
usleep (1000000);
|
||||
|
||||
sensor->show ();
|
||||
|
||||
while (!doWork) {
|
||||
// Back-and-forth lights
|
||||
scanner(127, 0, 0, 30); // red, slow
|
||||
scanner(0, 0, 127, 15); // blue, fast
|
||||
usleep (1000000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void scanner(uint8_t r, uint8_t g, uint8_t b, uint8_t wait) {
|
||||
int i, j, pos, dir;
|
||||
|
||||
pos = 0;
|
||||
dir = 1;
|
||||
|
||||
for(i=0; i < ((sensor->getStripLength() - 1) * 8); i++) {
|
||||
// Draw 5 pixels centered on pos. setPixelColor() will clip
|
||||
// any pixels off the ends of the strip, no worries there.
|
||||
// we'll make the colors dimmer at the edges for a nice pulse
|
||||
// look
|
||||
sensor->setPixelColor(pos - 2, r/4, g/4, b/4);
|
||||
sensor->setPixelColor(pos - 1, r/2, g/2, b/2);
|
||||
sensor->setPixelColor(pos, r, g, b);
|
||||
sensor->setPixelColor(pos + 1, r/2, g/2, b/2);
|
||||
sensor->setPixelColor(pos + 2, r/4, g/4, b/4);
|
||||
|
||||
sensor->show();
|
||||
usleep (wait * 1000);
|
||||
// If we wanted to be sneaky we could erase just the tail end
|
||||
// pixel, but it's much easier just to erase the whole thing
|
||||
// and draw a new one next time.
|
||||
for(j=-2; j<= 2; j++) {
|
||||
sensor->setPixelColor(pos+j, 0,0,0);
|
||||
}
|
||||
// Bounce off ends of strip
|
||||
pos += dir;
|
||||
if(pos < 0) {
|
||||
pos = 1;
|
||||
dir = -dir;
|
||||
} else if (pos >= sensor->getStripLength()) {
|
||||
pos = sensor->getStripLength() - 2;
|
||||
dir = -dir;
|
||||
}
|
||||
}
|
||||
}
|
71
examples/c++/lsm303.cxx
Normal file
71
examples/c++/lsm303.cxx
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@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>
|
||||
|
||||
//! [Interesting]
|
||||
#include "lsm303.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
// Instantiate LSM303 compass on I2C
|
||||
upm::LSM303 *sensor = new upm::LSM303(0);
|
||||
|
||||
// Get the coordinate data
|
||||
sensor->getCoordinates();
|
||||
int16_t* coor = sensor->getRawCoorData(); // in XYZ order.
|
||||
// The sensor returns XZY, but the driver compensates and makes it XYZ
|
||||
|
||||
// Print out the X, Y, and Z coordinate data using two different methods
|
||||
std::cout << "coor: rX " << (int)coor[0]
|
||||
<< " - rY " << (int)coor[1]
|
||||
<< " - rZ " << (int)coor[2]
|
||||
<< std::endl;
|
||||
std::cout << "coor: gX " << sensor->getCoorX()
|
||||
<< " - gY " << sensor->getCoorY()
|
||||
<< " - gZ " << sensor->getCoorZ()
|
||||
<< std::endl;
|
||||
|
||||
// Get and print out the heading
|
||||
std::cout << "heading: "
|
||||
<< sensor->getHeading()
|
||||
<< std::endl;
|
||||
|
||||
// Get the acceleration
|
||||
sensor->getAcceleration();
|
||||
int16_t* accel = sensor->getRawAccelData();
|
||||
// Print out the X, Y, and Z acceleration data using two different methods
|
||||
std::cout << "acc: rX " << (int)accel[0]
|
||||
<< " - rY " << (int)accel[1]
|
||||
<< " - Z " << (int)accel[2]
|
||||
<< std::endl;
|
||||
std::cout << "acc: gX " << sensor->getAccelX()
|
||||
<< " - gY " << sensor->getAccelY()
|
||||
<< " - gZ " << sensor->getAccelZ()
|
||||
<< std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
61
examples/c++/max31723.cxx
Normal file
61
examples/c++/max31723.cxx
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 "max31723.h"
|
||||
#include <signal.h>
|
||||
|
||||
int doWork = 0;
|
||||
upm::MAX31723 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
doWork = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
sensor = new upm::MAX31723(7);
|
||||
usleep (1000000);
|
||||
|
||||
while (!doWork) {
|
||||
std::cout << "Temperature " << sensor->getTemperature() << std::endl;
|
||||
usleep (1000000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
41
examples/c++/max31855.cxx
Normal file
41
examples/c++/max31855.cxx
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@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 <signal.h>
|
||||
|
||||
//! [Interesting]
|
||||
#include "max31855.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
upm::MAX31855 *temp = new upm::MAX31855(0, 8);
|
||||
|
||||
std::cout << temp->getTemp() << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
42
examples/c++/max44000.cxx
Normal file
42
examples/c++/max44000.cxx
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 "max44000.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::MAX44000 *sensor = new upm::MAX44000(0, ADDR);
|
||||
std::cout << "proximity value = " << sensor->getAmbient () << std::endl;
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
66
examples/c++/max5487.cxx
Normal file
66
examples/c++/max5487.cxx
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 "max5487.h"
|
||||
#include <signal.h>
|
||||
|
||||
upm::MAX5487 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
sensor = new upm::MAX5487(7);
|
||||
|
||||
// Power LED UP
|
||||
for (int i = 0; i < 255; i++) {
|
||||
sensor->setWiperA(i);
|
||||
usleep (5000);
|
||||
}
|
||||
|
||||
// Power LED DOWN
|
||||
for (int i = 0; i < 255; i++) {
|
||||
sensor->setWiperA(255 - i);
|
||||
usleep (5000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
75
examples/c++/maxds3231m.cxx
Normal file
75
examples/c++/maxds3231m.cxx
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 "maxds3231m.h"
|
||||
#include <signal.h>
|
||||
|
||||
int doWork = 0;
|
||||
upm::MAXDS3231M *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
doWork = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::Time3231 t;
|
||||
sensor = new upm::MAXDS3231M(0, ADDR);
|
||||
|
||||
t.second = 1;
|
||||
t.minute = 3;
|
||||
t.hour = 3;
|
||||
t.day = 3;
|
||||
t.month = 3;
|
||||
t.year = 3;
|
||||
t.weekDay = 3;
|
||||
sensor->setDate (t); // Note, second should be set to 1.
|
||||
|
||||
usleep (500000);
|
||||
|
||||
while (!doWork) {
|
||||
if (sensor->getDate (t)) {
|
||||
std::cout << (int)t.hour << ":" << (int)t.minute << ":" << (int)t.second << std::endl;
|
||||
}
|
||||
std::cout << "Temperature " << sensor->getTemperature() << std::endl;
|
||||
usleep (1000000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
79
examples/c++/mic.cxx
Normal file
79
examples/c++/mic.cxx
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 "mic.h"
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
int is_running = 0;
|
||||
uint16_t buffer [128];
|
||||
upm::Microphone *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
is_running = 1;
|
||||
}
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
// Attach microphone to analog port A0
|
||||
sensor = new upm::Microphone(0);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
thresholdContext ctx;
|
||||
ctx.averageReading = 0;
|
||||
ctx.runningAverage = 0;
|
||||
ctx.averagedOver = 2;
|
||||
|
||||
// Infinite loop, ends when script is cancelled
|
||||
// Repeatedly, take a sample every 2 microseconds;
|
||||
// find the average of 128 samples; and
|
||||
// print a running graph of the averages
|
||||
while (!is_running) {
|
||||
int len = sensor->getSampledWindow (2, 128, buffer);
|
||||
if (len) {
|
||||
int thresh = sensor->findThreshold (&ctx, 30, buffer, len);
|
||||
sensor->printGraph(&ctx);
|
||||
if (thresh) {
|
||||
// do something ....
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
60
examples/c++/mlx90614.cxx
Normal file
60
examples/c++/mlx90614.cxx
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 "mlx90614.h"
|
||||
#include <signal.h>
|
||||
|
||||
int doWork = 0;
|
||||
upm::MLX90614 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
doWork = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
sensor = new upm::MLX90614(0, DEVICE_ADDR);
|
||||
|
||||
while (!doWork) {
|
||||
std::cout << "Object Temperature (" << sensor->readObjectTempC() << ") Ambient Temperature (" << sensor->readAmbientTempC() << ")" << std::endl;
|
||||
usleep (1000000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
64
examples/c++/mma7455.cxx
Normal file
64
examples/c++/mma7455.cxx
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 "mma7455.h"
|
||||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
|
||||
int doWork = 0;
|
||||
upm::MMA7455 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
doWork = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
sensor = new upm::MMA7455(0, ADDR);
|
||||
|
||||
short x, y, z;
|
||||
while (!doWork) {
|
||||
sensor->readData(&x, &y, &z);
|
||||
std::cout << "Accelerometer X(" << x << ") Y(" << y << ") Z(" << z << ")" << std::endl;
|
||||
usleep (100000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
86
examples/c++/mma7660.cxx
Normal file
86
examples/c++/mma7660.cxx
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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 <signal.h>
|
||||
#include <iostream>
|
||||
#include "mma7660.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]
|
||||
// Instantiate an MMA7660 on I2C bus 0
|
||||
|
||||
upm::MMA7660 *accel = new upm::MMA7660(MMA7660_I2C_BUS,
|
||||
MMA7660_DEFAULT_I2C_ADDR);
|
||||
|
||||
// place device in standby mode so we can write registers
|
||||
accel->setModeStandby();
|
||||
|
||||
// enable 64 samples per second
|
||||
accel->setSampleRate(upm::MMA7660::AUTOSLEEP_64);
|
||||
|
||||
// place device into active mode
|
||||
accel->setModeActive();
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
int x, y, z;
|
||||
|
||||
accel->getRawValues(&x, &y, &z);
|
||||
cout << "Raw values: x = " << x
|
||||
<< " y = " << y
|
||||
<< " z = " << z
|
||||
<< endl;
|
||||
|
||||
float ax, ay, az;
|
||||
|
||||
accel->getAcceleration(&ax, &ay, &az);
|
||||
cout << "Acceleration: x = " << ax
|
||||
<< "g y = " << ay
|
||||
<< "g z = " << az
|
||||
<< "g" << endl;
|
||||
|
||||
usleep(500000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete accel;
|
||||
return 0;
|
||||
}
|
83
examples/c++/mpl3115a2.cxx
Normal file
83
examples/c++/mpl3115a2.cxx
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Author: William Penner <william.penner@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 <signal.h>
|
||||
|
||||
#include "mpl3115a2.h"
|
||||
|
||||
volatile int doWork = 0;
|
||||
|
||||
upm::MPL3115A2 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT) {
|
||||
printf("\nCtrl-C received.\n");
|
||||
doWork = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
// Register signal handler
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
float pressure = 0.0;
|
||||
float temperature = 0.0;
|
||||
float altitude = 0.0;
|
||||
float sealevel = 0.0;
|
||||
|
||||
sensor = new upm::MPL3115A2(0, MPL3115A2_I2C_ADDRESS);
|
||||
|
||||
sensor->testSensor();
|
||||
|
||||
while (!doWork) {
|
||||
temperature = sensor->getTemperature(true);
|
||||
pressure = sensor->getPressure(false);
|
||||
altitude = sensor->getAltitude();
|
||||
sealevel = sensor->getSealevelPressure();
|
||||
|
||||
std::cout << "pressure value = " <<
|
||||
pressure <<
|
||||
", altitude value = " <<
|
||||
altitude <<
|
||||
", sealevel value = " <<
|
||||
sealevel <<
|
||||
", temperature = " <<
|
||||
temperature << std::endl;
|
||||
usleep (500000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
88
examples/c++/mpr121.cxx
Normal file
88
examples/c++/mpr121.cxx
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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 <signal.h>
|
||||
#include <iostream>
|
||||
#include "mpr121.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
void printButtons(upm::MPR121 *touch)
|
||||
{
|
||||
bool buttonPressed = false;
|
||||
|
||||
cout << "Buttons Pressed: ";
|
||||
for (int i=0; i<12; i++)
|
||||
{
|
||||
if (touch->m_buttonStates & (1 << i))
|
||||
{
|
||||
cout << i << " ";
|
||||
buttonPressed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!buttonPressed)
|
||||
cout << "None";
|
||||
|
||||
if (touch->m_overCurrentFault)
|
||||
cout << "Over Current Fault detected!" << endl;
|
||||
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// Instantiate an MPR121 on I2C bus 0
|
||||
|
||||
upm::MPR121 *touch = new upm::MPR121(MPR121_I2C_BUS, MPR121_DEFAULT_I2C_ADDR);
|
||||
|
||||
// init according to AN3944 defaults
|
||||
touch->configAN3944();
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
touch->readButtons();
|
||||
printButtons(touch);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete touch;
|
||||
return 0;
|
||||
}
|
59
examples/c++/mpu9150.cxx
Normal file
59
examples/c++/mpu9150.cxx
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 "mpu9150.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::Vector3D data;
|
||||
upm::MPU9150 *sensor = new upm::MPU9150(0, ADDR);
|
||||
sensor->getData ();
|
||||
sensor->getAcceleromter (&data);
|
||||
std::cout << "*************************************************" << std::endl;
|
||||
std::cout << "DEVICE ID (" << (int) sensor->getDeviceID () << ")" << std::endl;
|
||||
std::cout << "*************************************************" << std::endl;
|
||||
std::cout << "ACCELEROMETER :: X (" << data.axisX << ")" << " Y (" << data.axisY << ")"
|
||||
<< " Z (" << data.axisZ << ")" << std::endl;
|
||||
|
||||
sensor->getGyro (&data);
|
||||
std::cout << "GYRO :: X (" << data.axisX << ")" << " Y (" << data.axisY << ")"
|
||||
<< " Z (" << data.axisZ << ")" << std::endl;
|
||||
|
||||
sensor->getMagnometer (&data);
|
||||
std::cout << "MAGNOMETER :: X (" << data.axisX << ")" << " Y (" << data.axisY << ")"
|
||||
<< " Z (" << data.axisZ << ")" << std::endl;
|
||||
std::cout << "TEMPERATURE (" << sensor->getTemperature () << ")" << std::endl;
|
||||
std::cout << "*************************************************" << std::endl;
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
79
examples/c++/mq2.cxx
Normal file
79
examples/c++/mq2.cxx
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 "mq2.h"
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
int is_running = 0;
|
||||
uint16_t buffer [128];
|
||||
upm::MQ2 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
is_running = 1;
|
||||
}
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
// Attach gas sensor to A0
|
||||
sensor = new upm::MQ2(0);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
thresholdContext ctx;
|
||||
ctx.averageReading = 0;
|
||||
ctx.runningAverage = 0;
|
||||
ctx.averagedOver = 2;
|
||||
|
||||
// Infinite loop, ends when script is cancelled
|
||||
// Repeatedly, take a sample every 2 milliseconds;
|
||||
// find the average of 128 samples; and
|
||||
// print a running graph of the averages using a resolution of 5
|
||||
while (!is_running) {
|
||||
int len = sensor->getSampledWindow (2, 128, buffer);
|
||||
if (len) {
|
||||
int thresh = sensor->findThreshold (&ctx, 30, buffer, len);
|
||||
sensor->printGraph(&ctx, 5);
|
||||
if (thresh) {
|
||||
// do something ....
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
79
examples/c++/mq3.cxx
Normal file
79
examples/c++/mq3.cxx
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 "mq3.h"
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
int is_running = 0;
|
||||
uint16_t buffer [128];
|
||||
upm::MQ3 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
is_running = 1;
|
||||
}
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
// Attach gas sensor to A0
|
||||
sensor = new upm::MQ3(0);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
thresholdContext ctx;
|
||||
ctx.averageReading = 0;
|
||||
ctx.runningAverage = 0;
|
||||
ctx.averagedOver = 2;
|
||||
|
||||
// Infinite loop, ends when script is cancelled
|
||||
// Repeatedly, take a sample every 2 milliseconds;
|
||||
// find the average of 128 samples; and
|
||||
// print a running graph of the averages using a resolution of 5
|
||||
while (!is_running) {
|
||||
int len = sensor->getSampledWindow (2, 128, buffer);
|
||||
if (len) {
|
||||
int thresh = sensor->findThreshold (&ctx, 30, buffer, len);
|
||||
sensor->printGraph(&ctx, 5);
|
||||
if (thresh) {
|
||||
// do something ....
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
78
examples/c++/mq303a.cxx
Normal file
78
examples/c++/mq303a.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 "mq303a.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 an mq303a sensor on analog pin A0
|
||||
|
||||
// This device uses a heater powered from an analog I/O pin.
|
||||
// If using A0 as the data pin, then you need to use A1, as the heater
|
||||
// pin (if using a grove mq303a). For A1, we can use the D15 gpio,
|
||||
// setup as an output, and drive it low to power the heater.
|
||||
|
||||
upm::MQ303A *mq303a = new upm::MQ303A(0, 15);
|
||||
|
||||
cout << "Enabling heater and waiting 2 minutes for warmup." << endl;
|
||||
mq303a->heaterEnable(true);
|
||||
sleep(120);
|
||||
|
||||
cout << "This sensor may need to warm until the value drops below about 450."
|
||||
<< endl;
|
||||
|
||||
// Print the detected alcohol value every second
|
||||
while (shouldRun)
|
||||
{
|
||||
int val = mq303a->value();
|
||||
|
||||
cout << "Alcohol detected (higher means stronger alcohol): "
|
||||
<< val << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
mq303a->heaterEnable(false);
|
||||
|
||||
delete mq303a;
|
||||
return 0;
|
||||
}
|
74
examples/c++/mq5.cxx
Normal file
74
examples/c++/mq5.cxx
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 "mq5.h"
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
int is_running = 0;
|
||||
uint16_t buffer [128];
|
||||
upm::MQ5 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
is_running = 1;
|
||||
}
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
sensor = new upm::MQ5(0);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
thresholdContext ctx;
|
||||
ctx.averageReading = 0;
|
||||
ctx.runningAverage = 0;
|
||||
ctx.averagedOver = 2;
|
||||
|
||||
while (!is_running) {
|
||||
int len = sensor->getSampledWindow (2, 128, buffer);
|
||||
if (len) {
|
||||
int thresh = sensor->findThreshold (&ctx, 30, buffer, len);
|
||||
sensor->printGraph(&ctx, 7);
|
||||
if (thresh) {
|
||||
// do something ....
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
74
examples/c++/mq9.cxx
Normal file
74
examples/c++/mq9.cxx
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 "mq9.h"
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
int is_running = 0;
|
||||
uint16_t buffer [128];
|
||||
upm::MQ9 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
is_running = 1;
|
||||
}
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
sensor = new upm::MQ9(0);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
thresholdContext ctx;
|
||||
ctx.averageReading = 0;
|
||||
ctx.runningAverage = 0;
|
||||
ctx.averagedOver = 2;
|
||||
|
||||
while (!is_running) {
|
||||
int len = sensor->getSampledWindow (2, 128, buffer);
|
||||
if (len) {
|
||||
int thresh = sensor->findThreshold (&ctx, 30, buffer, len);
|
||||
sensor->printGraph(&ctx, 5);
|
||||
if (thresh) {
|
||||
// do something ....
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
78
examples/c++/my9221.cxx
Normal file
78
examples/c++/my9221.cxx
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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 "my9221.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 MY9221, we use D2 for the data, and D3 for the
|
||||
// data clock. This was tested with a Grove LED bar.
|
||||
|
||||
upm::MY9221* bar = new upm::MY9221(2, 3);
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
// count up from green to red
|
||||
for (int i=1; i<=10; i++)
|
||||
{
|
||||
bar->setBarLevel(i, true);
|
||||
usleep(50000);
|
||||
}
|
||||
sleep(1);
|
||||
|
||||
// count down from red to green
|
||||
for (int i=1; i<=10; i++)
|
||||
{
|
||||
bar->setBarLevel(i, false);
|
||||
usleep(50000);
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
// turn off the LED's
|
||||
bar->setBarLevel(0, true);
|
||||
|
||||
delete bar;
|
||||
return 0;
|
||||
}
|
177
examples/c++/nrf8001_broadcast.cxx
Normal file
177
examples/c++/nrf8001_broadcast.cxx
Normal file
@ -0,0 +1,177 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 "nrf8001.h"
|
||||
#include "nrf8001_broadcast.h"
|
||||
#include <lib_aci.h>
|
||||
#include <aci_setup.h>
|
||||
#include <signal.h>
|
||||
|
||||
#ifdef SERVICES_PIPE_TYPE_MAPPING_CONTENT
|
||||
static services_pipe_type_mapping_t
|
||||
services_pipe_type_mapping[NUMBER_OF_PIPES] = SERVICES_PIPE_TYPE_MAPPING_CONTENT;
|
||||
#else
|
||||
#define NUMBER_OF_PIPES 0
|
||||
static services_pipe_type_mapping_t * services_pipe_type_mapping = NULL;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Store the setup for the nRF8001 in the flash of the AVR to save on RAM
|
||||
*/
|
||||
static hal_aci_data_t setup_msgs[NB_SETUP_MESSAGES] = SETUP_MESSAGES_CONTENT;
|
||||
|
||||
/**
|
||||
* aci_struct that will contain
|
||||
* total initial credits
|
||||
* current credit
|
||||
* current state of the aci (setup/standby/active/sleep)
|
||||
* open remote pipe pending
|
||||
* close remote pipe pending
|
||||
* Current pipe available bitmap
|
||||
* Current pipe closed bitmap
|
||||
* Current connection interval, slave latency and link supervision timeout
|
||||
* Current State of the the GATT client (Service Discovery)
|
||||
* Status of the bond (R) Peer address
|
||||
*/
|
||||
static struct aci_state_t aci_state;
|
||||
|
||||
/**
|
||||
* Temporary buffers for sending ACI commands
|
||||
*/
|
||||
static hal_aci_evt_t aci_data;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
init_aci_setup () {
|
||||
/**
|
||||
* Point ACI data structures to the the setup data that the nRFgo studio generated for the nRF8001
|
||||
*/
|
||||
if (NULL != services_pipe_type_mapping) {
|
||||
aci_state.aci_setup_info.services_pipe_type_mapping = &services_pipe_type_mapping[0];
|
||||
} else {
|
||||
aci_state.aci_setup_info.services_pipe_type_mapping = NULL;
|
||||
}
|
||||
|
||||
aci_state.aci_setup_info.number_of_pipes = NUMBER_OF_PIPES;
|
||||
aci_state.aci_setup_info.setup_msgs = setup_msgs;
|
||||
aci_state.aci_setup_info.num_setup_msgs = NB_SETUP_MESSAGES;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
|
||||
init_aci_setup ();
|
||||
init_local_interfaces (&aci_state, 10, 8, 4);
|
||||
|
||||
while (1) {
|
||||
static bool setup_required = false;
|
||||
if (lib_aci_event_get (&aci_state, &aci_data)) {
|
||||
aci_evt_t * aci_evt;
|
||||
aci_evt = &aci_data.evt;
|
||||
|
||||
switch(aci_evt->evt_opcode) {
|
||||
/**
|
||||
As soon as you reset the nRF8001 you will get an ACI Device Started Event
|
||||
*/
|
||||
case ACI_EVT_DEVICE_STARTED: {
|
||||
aci_state.data_credit_available = aci_evt->params.device_started.credit_available;
|
||||
switch(aci_evt->params.device_started.device_mode) {
|
||||
case ACI_DEVICE_SETUP:
|
||||
/**
|
||||
When the device is in the setup mode
|
||||
*/
|
||||
printf ("Evt Device Started: Setup\n");
|
||||
setup_required = true;
|
||||
break;
|
||||
|
||||
case ACI_DEVICE_STANDBY:
|
||||
printf ("Evt Device Started: Standby\n");
|
||||
lib_aci_broadcast(10/* in seconds */, 0x0100 /* advertising interval 100ms */);
|
||||
printf ("Broadcasting started\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
break; //ACI Device Started Event
|
||||
|
||||
case ACI_EVT_CMD_RSP:
|
||||
if (ACI_STATUS_SUCCESS != aci_evt->params.cmd_rsp.cmd_status) {
|
||||
printf ("ACI_EVT_CMD_RSP\n");
|
||||
while (1);
|
||||
}
|
||||
break;
|
||||
|
||||
case ACI_EVT_CONNECTED:
|
||||
printf ("ACI_EVT_CONNECTED\n");
|
||||
break;
|
||||
|
||||
case ACI_EVT_PIPE_STATUS:
|
||||
printf ("ACI_EVT_PIPE_STATUS\n");
|
||||
break;
|
||||
|
||||
case ACI_EVT_DISCONNECTED:
|
||||
if (ACI_STATUS_ERROR_ADVT_TIMEOUT == aci_evt->params.disconnected.aci_status) {
|
||||
printf ("Broadcasting timed out\n");
|
||||
} else {
|
||||
printf ("Evt Disconnected. Link Loss\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case ACI_EVT_DATA_RECEIVED:
|
||||
printf ("ACI_EVT_DATA_RECEIVED\n");
|
||||
break;
|
||||
|
||||
case ACI_EVT_HW_ERROR:
|
||||
printf ("ACI_EVT_HW_ERROR\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (setup_required) {
|
||||
if (SETUP_SUCCESS == do_aci_setup(&aci_state)) {
|
||||
setup_required = false;
|
||||
}
|
||||
}
|
||||
usleep (100);
|
||||
}
|
||||
|
||||
close_local_interfaces (&aci_state);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
93
examples/c++/nrf8001_broadcast.h
Normal file
93
examples/c++/nrf8001_broadcast.h
Normal file
@ -0,0 +1,93 @@
|
||||
#include "hal_platform.h"
|
||||
#include "aci.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
#define PIPE_GAP_DEVICE_NAME_SET 1
|
||||
|
||||
#define NUMBER_OF_PIPES 1
|
||||
|
||||
#define SERVICES_PIPE_TYPE_MAPPING_CONTENT {\
|
||||
{ACI_STORE_LOCAL, ACI_SET}, \
|
||||
}
|
||||
|
||||
#define GAP_PPCP_MAX_CONN_INT 0xffff /**< Maximum connection interval as a multiple of 1.25 msec , 0xFFFF means no specific value requested */
|
||||
#define GAP_PPCP_MIN_CONN_INT 0xffff /**< Minimum connection interval as a multiple of 1.25 msec , 0xFFFF means no specific maximum*/
|
||||
#define GAP_PPCP_SLAVE_LATENCY 0
|
||||
#define GAP_PPCP_CONN_TIMEOUT 0xffff /** Connection Supervision timeout multiplier as a multiple of 10msec, 0xFFFF means no specific value requested */
|
||||
|
||||
#define NB_SETUP_MESSAGES 13
|
||||
#define SETUP_MESSAGES_CONTENT {\
|
||||
{0x00,\
|
||||
{\
|
||||
0x07,0x06,0x00,0x00,0x03,0x02,0x41,0xd7,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x01,0x01,0x00,0x00,0x06,0x00,0x01,\
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x10,0x1c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x90,0x00,0x64,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x10,0x38,0x02,0xff,0x02,0x58,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
0x00,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x05,0x06,0x10,0x54,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x00,0x04,0x04,0x02,0x02,0x00,0x01,0x28,0x00,0x01,0x00,0x18,0x04,0x04,0x05,0x05,0x00,\
|
||||
0x02,0x28,0x03,0x01,0x0e,0x03,0x00,0x00,0x2a,0x04,0x14,0x0b,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x1c,0x05,0x00,0x03,0x2a,0x00,0x01,0x62,0x63,0x61,0x73,0x74,0x63,0x73,0x65,0x6d,0x69,\
|
||||
0x2e,0x04,0x04,0x05,0x05,0x00,0x04,0x28,0x03,0x01,0x02,0x05,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x38,0x00,0x01,0x2a,0x06,0x04,0x03,0x02,0x00,0x05,0x2a,0x01,0x01,0x00,0x00,0x04,0x04,\
|
||||
0x05,0x05,0x00,0x06,0x28,0x03,0x01,0x02,0x07,0x00,0x04,0x2a,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x54,0x06,0x04,0x09,0x08,0x00,0x07,0x2a,0x04,0x01,0xff,0xff,0xff,0xff,0x00,0x00,0xff,\
|
||||
0xff,0x04,0x04,0x02,0x02,0x00,0x08,0x28,0x00,0x01,0x01,0x18,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x04,0x06,0x20,0x70,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x0d,0x06,0x40,0x00,0x2a,0x00,0x01,0x00,0x80,0x04,0x00,0x03,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x06,0x06,0x60,0x00,0x00,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x06,0x06,0xf0,0x00,0x03,0x4c,0xf2,\
|
||||
},\
|
||||
},\
|
||||
}
|
362
examples/c++/nrf8001_helloworld.cxx
Normal file
362
examples/c++/nrf8001_helloworld.cxx
Normal file
@ -0,0 +1,362 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 "nrf8001.h"
|
||||
#include "nrf8001_helloworld.h"
|
||||
#include <lib_aci.h>
|
||||
#include <aci_setup.h>
|
||||
#include <signal.h>
|
||||
#include "uart_over_ble.h"
|
||||
|
||||
/*
|
||||
* You can use the nRF UART app in the Apple iOS app store and Google Play for Android 4.3 for Samsung Galaxy S4
|
||||
* with this helloworld application
|
||||
*/
|
||||
|
||||
#ifdef SERVICES_PIPE_TYPE_MAPPING_CONTENT
|
||||
static services_pipe_type_mapping_t
|
||||
services_pipe_type_mapping[NUMBER_OF_PIPES] = SERVICES_PIPE_TYPE_MAPPING_CONTENT;
|
||||
#else
|
||||
#define NUMBER_OF_PIPES 0
|
||||
static services_pipe_type_mapping_t * services_pipe_type_mapping = NULL;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Store the setup for the nRF8001 in the flash of the AVR to save on RAM
|
||||
*/
|
||||
static hal_aci_data_t setup_msgs[NB_SETUP_MESSAGES] = SETUP_MESSAGES_CONTENT;
|
||||
|
||||
/**
|
||||
* aci_struct that will contain
|
||||
* total initial credits
|
||||
* current credit
|
||||
* current state of the aci (setup/standby/active/sleep)
|
||||
* open remote pipe pending
|
||||
* close remote pipe pending
|
||||
* Current pipe available bitmap
|
||||
* Current pipe closed bitmap
|
||||
* Current connection interval, slave latency and link supervision timeout
|
||||
* Current State of the the GATT client (Service Discovery)
|
||||
* Status of the bond (R) Peer address
|
||||
*/
|
||||
static struct aci_state_t aci_state;
|
||||
|
||||
/**
|
||||
* Temporary buffers for sending ACI commands
|
||||
*/
|
||||
static hal_aci_evt_t aci_data;
|
||||
|
||||
/*
|
||||
Timing change state variable
|
||||
*/
|
||||
static bool timing_change_done = false;
|
||||
|
||||
/*
|
||||
Used to test the UART TX characteristic notification
|
||||
*/
|
||||
static uart_over_ble_t uart_over_ble;
|
||||
static uint8_t uart_buffer[20];
|
||||
static uint8_t uart_buffer_len = 0;
|
||||
static uint8_t dummychar = 0;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
init_aci_setup () {
|
||||
/**
|
||||
* Point ACI data structures to the the setup data that the nRFgo studio generated for the nRF8001
|
||||
*/
|
||||
if (NULL != services_pipe_type_mapping) {
|
||||
aci_state.aci_setup_info.services_pipe_type_mapping = &services_pipe_type_mapping[0];
|
||||
} else {
|
||||
aci_state.aci_setup_info.services_pipe_type_mapping = NULL;
|
||||
}
|
||||
|
||||
aci_state.aci_setup_info.number_of_pipes = NUMBER_OF_PIPES;
|
||||
aci_state.aci_setup_info.setup_msgs = setup_msgs;
|
||||
aci_state.aci_setup_info.num_setup_msgs = NB_SETUP_MESSAGES;
|
||||
}
|
||||
|
||||
void
|
||||
uart_over_ble_init (void) {
|
||||
uart_over_ble.uart_rts_local = true;
|
||||
}
|
||||
|
||||
bool
|
||||
uart_tx (uint8_t *buffer, uint8_t buffer_len) {
|
||||
bool status = false;
|
||||
|
||||
if (lib_aci_is_pipe_available(&aci_state, PIPE_UART_OVER_BTLE_UART_TX_TX) &&
|
||||
(aci_state.data_credit_available >= 1)) {
|
||||
status = lib_aci_send_data(PIPE_UART_OVER_BTLE_UART_TX_TX, buffer, buffer_len);
|
||||
if (status) {
|
||||
aci_state.data_credit_available--;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
bool
|
||||
uart_process_control_point_rx(uint8_t *byte, uint8_t length) {
|
||||
bool status = false;
|
||||
aci_ll_conn_params_t *conn_params;
|
||||
|
||||
if (lib_aci_is_pipe_available(&aci_state, PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_TX) ) {
|
||||
switch (*byte) {
|
||||
/*
|
||||
Queues a ACI Disconnect to the nRF8001 when this packet is received.
|
||||
May cause some of the UART packets being sent to be dropped
|
||||
*/
|
||||
case UART_OVER_BLE_DISCONNECT:
|
||||
/*
|
||||
Parameters:
|
||||
None
|
||||
*/
|
||||
lib_aci_disconnect(&aci_state, ACI_REASON_TERMINATE);
|
||||
status = true;
|
||||
break;
|
||||
|
||||
/*
|
||||
Queues an ACI Change Timing to the nRF8001
|
||||
*/
|
||||
case UART_OVER_BLE_LINK_TIMING_REQ:
|
||||
/*
|
||||
Parameters:
|
||||
Connection interval min: 2 bytes
|
||||
Connection interval max: 2 bytes
|
||||
Slave latency: 2 bytes
|
||||
Timeout: 2 bytes
|
||||
Same format as Peripheral Preferred Connection Parameters (See nRFgo studio -> nRF8001 Configuration -> GAP Settings
|
||||
Refer to the ACI Change Timing Request in the nRF8001 Product Specifications
|
||||
*/
|
||||
conn_params = (aci_ll_conn_params_t *)(byte+1);
|
||||
lib_aci_change_timing( conn_params->min_conn_interval,
|
||||
conn_params->max_conn_interval,
|
||||
conn_params->slave_latency,
|
||||
conn_params->timeout_mult);
|
||||
status = true;
|
||||
break;
|
||||
|
||||
/*
|
||||
Clears the RTS of the UART over BLE
|
||||
*/
|
||||
case UART_OVER_BLE_TRANSMIT_STOP:
|
||||
/*
|
||||
Parameters:
|
||||
None
|
||||
*/
|
||||
uart_over_ble.uart_rts_local = false;
|
||||
status = true;
|
||||
break;
|
||||
|
||||
|
||||
/*
|
||||
Set the RTS of the UART over BLE
|
||||
*/
|
||||
case UART_OVER_BLE_TRANSMIT_OK:
|
||||
/*
|
||||
Parameters:
|
||||
None
|
||||
*/
|
||||
uart_over_ble.uart_rts_local = true;
|
||||
status = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
|
||||
init_aci_setup ();
|
||||
init_local_interfaces (&aci_state, 10, 8, 4);
|
||||
|
||||
while (1) {
|
||||
static bool setup_required = false;
|
||||
|
||||
// We enter the if statement only when there is a ACI event available to be processed
|
||||
if (lib_aci_event_get(&aci_state, &aci_data)) {
|
||||
aci_evt_t * aci_evt;
|
||||
aci_evt = &aci_data.evt;
|
||||
switch(aci_evt->evt_opcode) {
|
||||
/**
|
||||
As soon as you reset the nRF8001 you will get an ACI Device Started Event
|
||||
*/
|
||||
case ACI_EVT_DEVICE_STARTED: {
|
||||
aci_state.data_credit_total = aci_evt->params.device_started.credit_available;
|
||||
switch(aci_evt->params.device_started.device_mode) {
|
||||
case ACI_DEVICE_SETUP:
|
||||
/**
|
||||
When the device is in the setup mode
|
||||
*/
|
||||
printf ("Evt Device Started: Setup \n");
|
||||
setup_required = true;
|
||||
break;
|
||||
|
||||
case ACI_DEVICE_STANDBY:
|
||||
printf ("Evt Device Started: Standby \n");
|
||||
// Looking for an iPhone by sending radio advertisements
|
||||
// When an iPhone connects to us we will get an ACI_EVT_CONNECTED event from the nRF8001
|
||||
if (aci_evt->params.device_started.hw_error) {
|
||||
usleep (20000); //Handle the HW error event correctly.
|
||||
} else {
|
||||
lib_aci_connect(0/* in seconds : 0 means forever */, 0x0050 /* advertising interval 50ms*/);
|
||||
printf ("Advertising started \n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break; // ACI Device Started Event
|
||||
|
||||
case ACI_EVT_CMD_RSP:
|
||||
//If an ACI command response event comes with an error -> stop
|
||||
if (ACI_STATUS_SUCCESS != aci_evt->params.cmd_rsp.cmd_status) {
|
||||
//ACI ReadDynamicData and ACI WriteDynamicData will have status codes of
|
||||
//TRANSACTION_CONTINUE and TRANSACTION_COMPLETE
|
||||
//all other ACI commands will have status code of ACI_STATUS_SCUCCESS for a successful command
|
||||
printf ("ACI_EVT_CMD_RSP \n");
|
||||
}
|
||||
if (ACI_CMD_GET_DEVICE_VERSION == aci_evt->params.cmd_rsp.cmd_opcode) {
|
||||
//Store the version and configuration information of the nRF8001 in the Hardware Revision String Characteristic
|
||||
lib_aci_set_local_data(&aci_state, PIPE_DEVICE_INFORMATION_HARDWARE_REVISION_STRING_SET,
|
||||
(uint8_t *)&(aci_evt->params.cmd_rsp.params.get_device_version), sizeof(aci_evt_cmd_rsp_params_get_device_version_t));
|
||||
}
|
||||
break;
|
||||
|
||||
case ACI_EVT_CONNECTED:
|
||||
printf ("ACI_EVT_CONNECTED");
|
||||
uart_over_ble_init ();
|
||||
timing_change_done = false;
|
||||
aci_state.data_credit_available = aci_state.data_credit_total;
|
||||
|
||||
/*
|
||||
Get the device version of the nRF8001 and store it in the Hardware Revision String
|
||||
*/
|
||||
lib_aci_device_version();
|
||||
break;
|
||||
|
||||
case ACI_EVT_PIPE_STATUS:
|
||||
printf ("ACI_EVT_PIPE_STATUS \n");
|
||||
if (lib_aci_is_pipe_available(&aci_state, PIPE_UART_OVER_BTLE_UART_TX_TX) && (false == timing_change_done)) {
|
||||
lib_aci_change_timing_GAP_PPCP(); // change the timing on the link as specified in the nRFgo studio -> nRF8001 conf. -> GAP.
|
||||
// Used to increase or decrease bandwidth
|
||||
timing_change_done = true;
|
||||
|
||||
char hello[]="Hello World, works";
|
||||
uart_tx((uint8_t *)&hello[0], strlen(hello));
|
||||
}
|
||||
break;
|
||||
|
||||
case ACI_EVT_TIMING:
|
||||
printf ("Evt link connection interval changed \n");
|
||||
lib_aci_set_local_data(&aci_state,
|
||||
PIPE_UART_OVER_BTLE_UART_LINK_TIMING_CURRENT_SET,
|
||||
(uint8_t *)&(aci_evt->params.timing.conn_rf_interval), /* Byte aligned */
|
||||
PIPE_UART_OVER_BTLE_UART_LINK_TIMING_CURRENT_SET_MAX_SIZE);
|
||||
break;
|
||||
|
||||
case ACI_EVT_DISCONNECTED:
|
||||
printf ("ACI_EVT_DISCONNECTED \n");
|
||||
lib_aci_connect(0/* in seconds : 0 means forever */, 0x0050 /* advertising interval 50ms*/);
|
||||
printf ("Advertising started \n");
|
||||
break;
|
||||
|
||||
case ACI_EVT_DATA_RECEIVED:
|
||||
if (PIPE_UART_OVER_BTLE_UART_RX_RX == aci_evt->params.data_received.rx_data.pipe_number) {
|
||||
for(int i=0; i<aci_evt->len - 2; i++) {
|
||||
uart_buffer[i] = aci_evt->params.data_received.rx_data.aci_data[i];
|
||||
}
|
||||
|
||||
uart_buffer_len = aci_evt->len - 2;
|
||||
if (lib_aci_is_pipe_available(&aci_state, PIPE_UART_OVER_BTLE_UART_TX_TX)) {
|
||||
}
|
||||
}
|
||||
|
||||
if (PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_RX == aci_evt->params.data_received.rx_data.pipe_number) {
|
||||
//Subtract for Opcode and Pipe number
|
||||
uart_process_control_point_rx(&aci_evt->params.data_received.rx_data.aci_data[0], aci_evt->len - 2);
|
||||
}
|
||||
|
||||
printf ("Incomming data - %s\n", uart_buffer);
|
||||
break;
|
||||
|
||||
case ACI_EVT_DATA_CREDIT:
|
||||
printf ("ACI_EVT_DATA_CREDIT \n");
|
||||
aci_state.data_credit_available = aci_state.data_credit_available + aci_evt->params.data_credit.credit;
|
||||
break;
|
||||
|
||||
case ACI_EVT_PIPE_ERROR:
|
||||
printf ("ACI_EVT_PIPE_ERROR \n");
|
||||
//Increment the credit available as the data packet was not sent.
|
||||
//The pipe error also represents the Attribute protocol Error Response sent from the peer and that should not be counted
|
||||
//for the credit.
|
||||
if (ACI_STATUS_ERROR_PEER_ATT_ERROR != aci_evt->params.pipe_error.error_code) {
|
||||
aci_state.data_credit_available++;
|
||||
}
|
||||
break;
|
||||
|
||||
case ACI_EVT_HW_ERROR:
|
||||
printf ("ACI_EVT_HW_ERROR \n");
|
||||
lib_aci_connect(0/* in seconds, 0 means forever */, 0x0050 /* advertising interval 50ms*/);
|
||||
printf ("Advertising started \n");
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* setup_required is set to true when the device starts up and enters setup mode.
|
||||
* It indicates that do_aci_setup() should be called. The flag should be cleared if
|
||||
* do_aci_setup() returns ACI_STATUS_TRANSACTION_COMPLETE.
|
||||
*/
|
||||
if(setup_required) {
|
||||
if (SETUP_SUCCESS == do_aci_setup(&aci_state)) {
|
||||
setup_required = false;
|
||||
}
|
||||
}
|
||||
|
||||
usleep (100);
|
||||
}
|
||||
|
||||
close_local_interfaces (&aci_state);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
254
examples/c++/nrf8001_helloworld.h
Normal file
254
examples/c++/nrf8001_helloworld.h
Normal file
@ -0,0 +1,254 @@
|
||||
#include "hal_platform.h"
|
||||
#include "aci.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
#define SETUP_ID 0
|
||||
#define SETUP_FORMAT 2 /** nRF8001 Cx */
|
||||
#define ACI_DYNAMIC_DATA_SIZE 263
|
||||
|
||||
/* Service: GATT - Characteristic: Service Changed - Pipe: TX_ACK */
|
||||
#define PIPE_GATT_SERVICE_CHANGED_TX_ACK 1
|
||||
#define PIPE_GATT_SERVICE_CHANGED_TX_ACK_MAX_SIZE 4
|
||||
|
||||
/* Service: Device Information - Characteristic: Hardware Revision String - Pipe: SET */
|
||||
#define PIPE_DEVICE_INFORMATION_HARDWARE_REVISION_STRING_SET 2
|
||||
#define PIPE_DEVICE_INFORMATION_HARDWARE_REVISION_STRING_SET_MAX_SIZE 9
|
||||
|
||||
/* Service: Device Information - Characteristic: Manufacturer Name String - Pipe: SET */
|
||||
#define PIPE_DEVICE_INFORMATION_MANUFACTURER_NAME_STRING_SET 3
|
||||
#define PIPE_DEVICE_INFORMATION_MANUFACTURER_NAME_STRING_SET_MAX_SIZE 20
|
||||
|
||||
/* Service: Device Information - Characteristic: Model Number String - Pipe: SET */
|
||||
#define PIPE_DEVICE_INFORMATION_MODEL_NUMBER_STRING_SET 4
|
||||
#define PIPE_DEVICE_INFORMATION_MODEL_NUMBER_STRING_SET_MAX_SIZE 8
|
||||
|
||||
/* Service: Device Information - Characteristic: Firmware Revision String - Pipe: SET */
|
||||
#define PIPE_DEVICE_INFORMATION_FIRMWARE_REVISION_STRING_SET 5
|
||||
#define PIPE_DEVICE_INFORMATION_FIRMWARE_REVISION_STRING_SET_MAX_SIZE 4
|
||||
|
||||
/* Service: Device Information - Characteristic: PNP_ID - Pipe: SET */
|
||||
#define PIPE_DEVICE_INFORMATION_PNP_ID_SET 6
|
||||
#define PIPE_DEVICE_INFORMATION_PNP_ID_SET_MAX_SIZE 7
|
||||
|
||||
/* Service: UART over BTLE - Characteristic: UART RX - Pipe: RX */
|
||||
#define PIPE_UART_OVER_BTLE_UART_RX_RX 7
|
||||
#define PIPE_UART_OVER_BTLE_UART_RX_RX_MAX_SIZE 20
|
||||
|
||||
/* Service: UART over BTLE - Characteristic: UART TX - Pipe: TX */
|
||||
#define PIPE_UART_OVER_BTLE_UART_TX_TX 8
|
||||
#define PIPE_UART_OVER_BTLE_UART_TX_TX_MAX_SIZE 20
|
||||
|
||||
/* Service: UART over BTLE - Characteristic: UART Control Point - Pipe: TX */
|
||||
#define PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_TX 9
|
||||
#define PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_TX_MAX_SIZE 9
|
||||
|
||||
/* Service: UART over BTLE - Characteristic: UART Control Point - Pipe: RX */
|
||||
#define PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_RX 10
|
||||
#define PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_RX_MAX_SIZE 9
|
||||
|
||||
/* Service: UART over BTLE - Characteristic: UART Link Timing Current - Pipe: SET */
|
||||
#define PIPE_UART_OVER_BTLE_UART_LINK_TIMING_CURRENT_SET 11
|
||||
#define PIPE_UART_OVER_BTLE_UART_LINK_TIMING_CURRENT_SET_MAX_SIZE 6
|
||||
|
||||
|
||||
#define NUMBER_OF_PIPES 11
|
||||
|
||||
#define SERVICES_PIPE_TYPE_MAPPING_CONTENT {\
|
||||
{ACI_STORE_LOCAL, ACI_TX_ACK}, \
|
||||
{ACI_STORE_LOCAL, ACI_SET}, \
|
||||
{ACI_STORE_LOCAL, ACI_SET}, \
|
||||
{ACI_STORE_LOCAL, ACI_SET}, \
|
||||
{ACI_STORE_LOCAL, ACI_SET}, \
|
||||
{ACI_STORE_LOCAL, ACI_SET}, \
|
||||
{ACI_STORE_LOCAL, ACI_RX}, \
|
||||
{ACI_STORE_LOCAL, ACI_TX}, \
|
||||
{ACI_STORE_LOCAL, ACI_TX}, \
|
||||
{ACI_STORE_LOCAL, ACI_RX}, \
|
||||
{ACI_STORE_LOCAL, ACI_SET}, \
|
||||
}
|
||||
|
||||
#define GAP_PPCP_MAX_CONN_INT 0x12 /**< Maximum connection interval as a multiple of 1.25 msec , 0xFFFF means no specific value requested */
|
||||
#define GAP_PPCP_MIN_CONN_INT 0xa /**< Minimum connection interval as a multiple of 1.25 msec , 0xFFFF means no specific value requested */
|
||||
#define GAP_PPCP_SLAVE_LATENCY 0
|
||||
#define GAP_PPCP_CONN_TIMEOUT 0xa /** Connection Supervision timeout multiplier as a multiple of 10msec, 0xFFFF means no specific value requested */
|
||||
|
||||
#define NB_SETUP_MESSAGES 30
|
||||
#define SETUP_MESSAGES_CONTENT {\
|
||||
{0x00,\
|
||||
{\
|
||||
0x07,0x06,0x00,0x00,0x02,0x02,0x41,0xfe,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0a,0x00,0x0b,0x01,0x01,0x00,0x00,0x06,0x00,0x00,\
|
||||
0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1e,0x06,0x10,0x1c,0x01,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x14,0x03,0x90,0x01,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x00,0x04,0x04,0x02,0x02,0x00,0x01,0x28,0x00,0x01,0x00,0x18,0x04,0x04,0x05,0x05,0x00,\
|
||||
0x02,0x28,0x03,0x01,0x02,0x03,0x00,0x00,0x2a,0x04,0x04,0x14,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x1c,0x05,0x00,0x03,0x2a,0x00,0x01,0x48,0x65,0x6c,0x6c,0x6f,0x63,0x73,0x65,0x6d,0x69,\
|
||||
0x2e,0x63,0x6f,0x6d,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x38,0x05,0x05,0x00,0x04,0x28,0x03,0x01,0x02,0x05,0x00,0x01,0x2a,0x06,0x04,0x03,0x02,\
|
||||
0x00,0x05,0x2a,0x01,0x01,0x80,0x00,0x04,0x04,0x05,0x05,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x54,0x06,0x28,0x03,0x01,0x02,0x07,0x00,0x04,0x2a,0x06,0x04,0x09,0x08,0x00,0x07,0x2a,\
|
||||
0x04,0x01,0x0a,0x00,0x12,0x00,0x00,0x00,0x0a,0x00,0x04,0x04,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x70,0x02,0x02,0x00,0x08,0x28,0x00,0x01,0x01,0x18,0x04,0x04,0x05,0x05,0x00,0x09,0x28,\
|
||||
0x03,0x01,0x22,0x0a,0x00,0x05,0x2a,0x26,0x04,0x05,0x04,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x8c,0x0a,0x2a,0x05,0x01,0x00,0x00,0x00,0x00,0x46,0x14,0x03,0x02,0x00,0x0b,0x29,0x02,\
|
||||
0x01,0x00,0x00,0x04,0x04,0x02,0x02,0x00,0x0c,0x28,0x00,0x01,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0xa8,0x0a,0x18,0x04,0x04,0x05,0x05,0x00,0x0d,0x28,0x03,0x01,0x02,0x0e,0x00,0x27,0x2a,\
|
||||
0x04,0x04,0x09,0x01,0x00,0x0e,0x2a,0x27,0x01,0x0a,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0xc4,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x05,0x05,0x00,0x0f,0x28,0x03,0x01,0x02,\
|
||||
0x10,0x00,0x29,0x2a,0x04,0x04,0x14,0x02,0x00,0x10,0x2a,0x29,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0xe0,0x01,0x30,0x31,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x05,0x05,0x00,0x11,0x28,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0xfc,0x03,0x01,0x02,0x12,0x00,0x24,0x2a,0x04,0x04,0x08,0x02,0x00,0x12,0x2a,0x24,0x01,\
|
||||
0x31,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x05,0x05,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0x18,0x00,0x13,0x28,0x03,0x01,0x02,0x14,0x00,0x26,0x2a,0x04,0x04,0x04,0x02,0x00,0x14,\
|
||||
0x2a,0x26,0x01,0x33,0x34,0x00,0x00,0x04,0x04,0x05,0x05,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0x34,0x15,0x28,0x03,0x01,0x02,0x16,0x00,0x50,0x2a,0x06,0x04,0x08,0x07,0x00,0x16,0x2a,\
|
||||
0x50,0x01,0x02,0x00,0x00,0xaa,0xaa,0xcc,0xcc,0x04,0x04,0x10,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0x50,0x10,0x00,0x17,0x28,0x00,0x01,0x9e,0xca,0xdc,0x24,0x0e,0xe5,0xa9,0xe0,0x93,0xf3,\
|
||||
0xa3,0xb5,0x01,0x00,0x40,0x6e,0x04,0x04,0x13,0x13,0x00,0x18,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0x6c,0x28,0x03,0x01,0x04,0x19,0x00,0x9e,0xca,0xdc,0x24,0x0e,0xe5,0xa9,0xe0,0x93,0xf3,\
|
||||
0xa3,0xb5,0x02,0x00,0x40,0x6e,0x44,0x10,0x14,0x00,0x00,0x19,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0x88,0x00,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x13,0x13,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0xa4,0x1a,0x28,0x03,0x01,0x10,0x1b,0x00,0x9e,0xca,0xdc,0x24,0x0e,0xe5,0xa9,0xe0,0x93,\
|
||||
0xf3,0xa3,0xb5,0x03,0x00,0x40,0x6e,0x14,0x00,0x14,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0xc0,0x1b,0x00,0x03,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0x14,0x03,0x02,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0xdc,0x00,0x1c,0x29,0x02,0x01,0x00,0x00,0x04,0x04,0x13,0x13,0x00,0x1d,0x28,0x03,0x01,\
|
||||
0x14,0x1e,0x00,0x9e,0xca,0xdc,0x24,0x0e,0xe5,0xa9,0xe0,0x93,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0xf8,0xf3,0xa3,0xb5,0x04,0x00,0x40,0x6e,0x54,0x10,0x09,0x00,0x00,0x1e,0x00,0x04,0x02,\
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0x14,0x03,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x22,0x14,0x02,0x00,0x1f,0x29,0x02,0x01,0x00,0x00,0x04,0x04,0x13,0x13,0x00,0x20,0x28,0x03,\
|
||||
0x01,0x02,0x21,0x00,0x9e,0xca,0xdc,0x24,0x0e,0xe5,0xa9,0xe0,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1b,0x06,0x22,0x30,0x93,0xf3,0xa3,0xb5,0x05,0x00,0x40,0x6e,0x06,0x04,0x07,0x06,0x00,0x21,0x00,0x05,\
|
||||
0x02,0xff,0xff,0xff,0xff,0xff,0xff,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x40,0x00,0x2a,0x05,0x01,0x00,0x04,0x04,0x00,0x0a,0x00,0x0b,0x2a,0x27,0x01,0x00,0x80,0x04,\
|
||||
0x00,0x0e,0x00,0x00,0x2a,0x29,0x01,0x00,0x80,0x04,0x00,0x10,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x40,0x1c,0x00,0x00,0x2a,0x24,0x01,0x00,0x80,0x04,0x00,0x12,0x00,0x00,0x2a,0x26,0x01,0x00,\
|
||||
0x80,0x04,0x00,0x14,0x00,0x00,0x2a,0x50,0x01,0x00,0x80,0x04,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x40,0x38,0x00,0x16,0x00,0x00,0x00,0x02,0x02,0x00,0x08,0x04,0x00,0x19,0x00,0x00,0x00,0x03,\
|
||||
0x02,0x00,0x02,0x04,0x00,0x1b,0x00,0x1c,0x00,0x04,0x02,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x13,0x06,0x40,0x54,0x0a,0x04,0x00,0x1e,0x00,0x1f,0x00,0x05,0x02,0x00,0x80,0x04,0x00,0x21,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x13,0x06,0x50,0x00,0x9e,0xca,0xdc,0x24,0x0e,0xe5,0xa9,0xe0,0x93,0xf3,0xa3,0xb5,0x00,0x00,0x40,0x6e,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x06,0x06,0xf0,0x00,0x02,0xb2,0xd1,\
|
||||
},\
|
||||
},\
|
||||
}
|
77
examples/c++/nrf_receiver.cxx
Normal file
77
examples/c++/nrf_receiver.cxx
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 <string.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "nrf24l01.h"
|
||||
#include <signal.h>
|
||||
|
||||
int running = 0;
|
||||
upm::NRF24L01 *comm = NULL;
|
||||
|
||||
uint8_t local_address[5] = {0x01, 0x01, 0x01, 0x01, 0x01};
|
||||
uint8_t broadcast_address[5] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
running = 1;
|
||||
}
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
void nrf_handler () {
|
||||
std::cout << "Reciever :: " << *((uint32_t *)&(comm->m_rxBuffer[0])) << std::endl;
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
comm = new upm::NRF24L01(7, 8);
|
||||
comm->setSourceAddress ((uint8_t *) local_address);
|
||||
comm->setDestinationAddress ((uint8_t *) broadcast_address);
|
||||
comm->setPayload (MAX_BUFFER);
|
||||
comm->configure ();
|
||||
comm->setSpeedRate (upm::NRF_250KBPS);
|
||||
comm->setChannel (99);
|
||||
comm->dataRecievedHandler = nrf_handler;
|
||||
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
while (!running) {
|
||||
comm->pollListener ();
|
||||
}
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete comm;
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
78
examples/c++/nrf_transmitter.cxx
Normal file
78
examples/c++/nrf_transmitter.cxx
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 <string.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "nrf24l01.h"
|
||||
#include <signal.h>
|
||||
|
||||
int running = 0;
|
||||
upm::NRF24L01 *comm = NULL;
|
||||
|
||||
uint8_t destAddress[5] = {0x01, 0x01, 0x01, 0x01, 0x01};
|
||||
uint8_t srcAddress[5] = {0x01, 0x01, 0x01, 0x01, 0x02};
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
running = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void nrf_handler () {
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
uint32_t dummyData = 0;
|
||||
comm = new upm::NRF24L01(7, 8);
|
||||
comm->setSourceAddress ((uint8_t *) srcAddress);
|
||||
comm->setDestinationAddress ((uint8_t *) destAddress);
|
||||
comm->setPayload (MAX_BUFFER);
|
||||
comm->setChannel (99);
|
||||
comm->configure ();
|
||||
comm->dataRecievedHandler = nrf_handler;
|
||||
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
while (!running) {
|
||||
memcpy (comm->m_txBuffer, &dummyData, sizeof (dummyData));
|
||||
comm->send ();
|
||||
std::cout << "devi2 :: sending data ...." << dummyData << std::endl;
|
||||
usleep (3000000);
|
||||
dummyData += 3000;
|
||||
}
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete comm;
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
79
examples/c++/nunchuck.cxx
Normal file
79
examples/c++/nunchuck.cxx
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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 "nunchuck.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// Instantiate a nunchuck controller bus 0
|
||||
upm::NUNCHUCK *nunchuck = new upm::NUNCHUCK(0);
|
||||
|
||||
// always do this first
|
||||
cout << "Initializing... " << endl;
|
||||
if (!nunchuck->init())
|
||||
{
|
||||
cerr << "nunchuck->init() failed." << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
nunchuck->update();
|
||||
|
||||
cout << "stickX: " << nunchuck->stickX
|
||||
<< ", stickY: " << nunchuck->stickY << endl;
|
||||
cout << "accelX: " << nunchuck->accelX
|
||||
<< ", accelY: " << nunchuck->accelY
|
||||
<< ", accelZ: " << nunchuck->accelZ << endl;
|
||||
|
||||
cout << "button C: "
|
||||
<< ((nunchuck->buttonC) ? "pressed" : "not pressed") << endl;
|
||||
cout << "button Z: "
|
||||
<< ((nunchuck->buttonZ) ? "pressed" : "not pressed") << endl;
|
||||
cout << endl;
|
||||
|
||||
usleep(100000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
delete nunchuck;
|
||||
return 0;
|
||||
}
|
98
examples/c++/oled-1308.cxx
Normal file
98
examples/c++/oled-1308.cxx
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveish <yevgeniy.kiveisha@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 "ssd1308.h"
|
||||
|
||||
#define DEVICE_ADDRESS 0x3C
|
||||
#define BUS_NUMBER 0x0
|
||||
|
||||
static uint8_t intel_logo[] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 192, 192, 192, 224,
|
||||
224, 224, 224, 240, 240, 248, 248, 120, 120, 120, 120, 60, 60, 60, 60, 60,
|
||||
62, 30, 30, 30, 30, 30, 30, 30, 31, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 31, 31, 31, 31, 31,
|
||||
30, 62, 62, 62, 62, 126, 126, 124, 124, 252, 252, 248, 248, 240, 240, 240,
|
||||
224, 224, 224, 192, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 128, 128, 128,
|
||||
128, 0, 56, 56, 28, 30, 14, 15, 15, 7, 7, 7, 7, 3, 3, 1, 1, 1, 1, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
192, 192, 192, 192, 192, 192, 192, 192, 0, 0, 0, 0, 192, 193, 195, 195,
|
||||
195, 7, 15, 15, 63, 127, 255, 255, 255, 254, 252, 252, 240, 192, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 128, 192, 192, 240, 248, 124, 124, 60, 0, 0, 0, 0, 159, 159,
|
||||
159, 159, 159, 159, 159, 159, 0, 0, 0, 0, 128, 128, 128, 128, 128, 128,
|
||||
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 0, 0,
|
||||
0, 0, 0, 0, 254, 254, 254, 254, 254, 254, 254, 254, 128, 128, 128, 128,
|
||||
128, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 192, 192, 192, 192, 192, 192, 128,
|
||||
128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
0, 0, 0, 0, 3, 7, 3, 3, 3, 0, 0, 0, 0, 0, 1, 1, 255, 255, 255, 255, 255,
|
||||
255, 255, 0, 0, 224, 248, 252, 252, 255, 127, 15, 15, 3, 1, 0, 0, 0, 0, 0,
|
||||
0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 15, 15, 15, 15, 15, 15, 255, 255, 255, 255, 255,
|
||||
255, 255, 252, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 15, 15,
|
||||
15, 15, 15, 224, 224, 252, 254, 255, 255, 255, 255, 159, 159, 143, 143,
|
||||
135, 135, 143, 159, 255, 255, 255, 255, 255, 255, 252, 248, 0, 0, 0, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128,
|
||||
224, 248, 248, 255, 255, 255, 255, 255, 127, 15, 255, 255, 255, 255, 255,
|
||||
255, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0,
|
||||
0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 192, 192, 192, 192, 192, 31, 31, 255, 255, 255,
|
||||
255, 255, 255, 231, 231, 199, 199, 199, 199, 199, 199, 199, 199, 231, 231,
|
||||
231, 231, 199, 135, 0, 0, 0, 63, 255, 255, 255, 255, 255, 255, 255, 0, 0,
|
||||
0, 0, 224, 240, 248, 248, 252, 254, 255, 255, 255, 127, 63, 63, 31, 15, 7,
|
||||
7, 1, 0, 0, 63, 63, 255, 255, 255, 255, 255, 240, 192, 192, 128, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 1, 3, 3, 7, 7, 7, 7, 7, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 3, 3, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 0, 0, 0, 1, 3, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 7, 7, 7,
|
||||
7, 7, 3, 3, 3, 1, 0, 0, 0, 0, 1, 3, 3, 7, 135, 135, 135, 192, 192, 0, 0, 7,
|
||||
7, 3, 3, 3, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 15, 15,
|
||||
31, 127, 127, 127, 255, 255, 252, 252, 252, 248, 240, 240, 240, 224, 224,
|
||||
224, 192, 192, 192, 192, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 128, 128, 128, 128, 128, 128, 128, 192, 192, 192, 192, 192,
|
||||
224, 224, 224, 224, 240, 240, 240, 240, 248, 248, 248, 248, 252, 252, 252,
|
||||
254, 254, 255, 255, 255, 255, 255, 255, 127, 127, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
|
||||
3, 3, 3, 7, 7, 7, 15, 15, 31, 31, 31, 63, 63, 63, 63, 63, 127, 127, 127,
|
||||
127, 127, 255, 255, 255, 255, 254, 254, 254, 254, 254, 254, 254, 254, 254,
|
||||
254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,
|
||||
255, 255, 255, 255, 255, 255, 255, 127, 127, 127, 127, 127, 127, 127, 127,
|
||||
63, 63, 63, 63, 63, 31, 31, 31, 31, 31, 15, 15, 15, 15, 7, 7, 7, 7, 3, 3,
|
||||
3, 3, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::SSD1308 *lcd = new upm::SSD1308(BUS_NUMBER, DEVICE_ADDRESS);
|
||||
|
||||
lcd->clear();
|
||||
lcd->draw(intel_logo, 1024);
|
||||
|
||||
lcd->close();
|
||||
//! [Interesting]
|
||||
}
|
126
examples/c++/oled-1327.cxx
Normal file
126
examples/c++/oled-1327.cxx
Normal file
@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveish <yevgeniy.kiveisha@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 "ssd1327.h"
|
||||
|
||||
#define DEVICE_ADDRESS 0x3C
|
||||
#define BUS_NUMBER 0x0
|
||||
|
||||
static uint8_t SeeedLogo[] ={
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x60, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x06, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xC0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0xC0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x03, 0x80, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x03, 0x80,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x03, 0xC0, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x01, 0xC0, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
|
||||
0x07, 0x80, 0x01, 0xE0, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x0F, 0x80, 0x01, 0xE0,
|
||||
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x0F, 0x00, 0x01, 0xE0, 0x08, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x30, 0x0F, 0x00, 0x01, 0xE0, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
|
||||
0x0F, 0x00, 0x01, 0xE0, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x0F, 0x00, 0x01, 0xE0,
|
||||
0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x0F, 0x00, 0x01, 0xE0, 0x18, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x38, 0x0F, 0x00, 0x01, 0xE0, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38,
|
||||
0x0F, 0x80, 0x01, 0xE0, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x0F, 0x80, 0x01, 0xE0,
|
||||
0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x0F, 0x80, 0x03, 0xE0, 0x78, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x1E, 0x07, 0x80, 0x03, 0xE0, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E,
|
||||
0x07, 0x80, 0x03, 0xE0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x07, 0x80, 0x03, 0xC1,
|
||||
0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x87, 0xC0, 0x07, 0xC1, 0xF0, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x0F, 0x83, 0xC0, 0x07, 0x83, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F,
|
||||
0xC3, 0xC0, 0x07, 0x87, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xE1, 0xE0, 0x07, 0x0F,
|
||||
0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xF0, 0xE0, 0x0F, 0x0F, 0x80, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01, 0xF8, 0xF0, 0x0E, 0x1F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
||||
0xF8, 0x70, 0x1C, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x30, 0x18, 0x7E,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x18, 0x30, 0xFC, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x1F, 0x88, 0x21, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x0F, 0xC4, 0x47, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE0, 0x0F, 0x80,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x02, 0x00, 0x06, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x06,
|
||||
0x00, 0x00, 0x60, 0x00, 0x7E, 0x3F, 0x0F, 0xC3, 0xF0, 0xFA, 0x0F, 0xDF, 0xE1, 0x9F, 0xEC, 0x7E,
|
||||
0xE6, 0x73, 0x9C, 0xE7, 0x39, 0xCE, 0x1C, 0xDF, 0xE1, 0xB9, 0xEC, 0xE7, 0xE0, 0x61, 0xD8, 0x66,
|
||||
0x1B, 0x86, 0x1C, 0x06, 0x61, 0xB0, 0x6D, 0xC3, 0x7C, 0x7F, 0xFF, 0xFF, 0xFF, 0x06, 0x0F, 0x86,
|
||||
0x61, 0xB0, 0x6D, 0x83, 0x3E, 0x7F, 0xFF, 0xFF, 0xFF, 0x06, 0x07, 0xC6, 0x61, 0xB0, 0x6D, 0x83,
|
||||
0xC3, 0x61, 0x18, 0x46, 0x03, 0x86, 0x18, 0x66, 0x61, 0xB0, 0x6D, 0xC3, 0xFE, 0x7F, 0x9F, 0xE7,
|
||||
0xF9, 0xFE, 0x1F, 0xE6, 0x3F, 0x9F, 0xEC, 0xFE, 0x7E, 0x3F, 0x0F, 0xC3, 0xF0, 0xFA, 0x0F, 0xC6,
|
||||
0x3F, 0x9F, 0xEC, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00,
|
||||
0x00, 0x20, 0x82, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x20, 0x82, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6C, 0xF3, 0xCF, 0x70, 0x9E, 0x79, 0xE7, 0x80, 0x00, 0x00,
|
||||
0x00, 0x00, 0x7D, 0x9E, 0x68, 0x20, 0xB2, 0xC8, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x9E,
|
||||
0x6F, 0x20, 0xB2, 0xF9, 0xE7, 0x80, 0x00, 0x00, 0x00, 0x00, 0x46, 0x9A, 0x61, 0x20, 0xB2, 0xCB,
|
||||
0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x7C, 0xF3, 0xCF, 0x30, 0x9E, 0x79, 0xE7, 0x90, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x02, 0x00, 0x00, 0x82, 0x60, 0x00, 0x00,
|
||||
0xF8, 0x00, 0x00, 0x40, 0x40, 0x02, 0x00, 0x00, 0x83, 0x60, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x40,
|
||||
0x60, 0xB7, 0x79, 0xE7, 0x81, 0xC7, 0x92, 0x70, 0x89, 0xE7, 0x9E, 0x78, 0x7C, 0xE2, 0xC9, 0x2C,
|
||||
0x81, 0xCC, 0xD2, 0x40, 0xFB, 0x21, 0xB2, 0x48, 0x40, 0x62, 0xF9, 0x2C, 0x80, 0x8C, 0xD2, 0x40,
|
||||
0x8B, 0xE7, 0xB0, 0x48, 0x40, 0xE2, 0xC9, 0x2C, 0x80, 0x84, 0xD2, 0x40, 0x8B, 0x2D, 0x92, 0x48,
|
||||
0x7D, 0xB3, 0x79, 0x27, 0x80, 0x87, 0x9E, 0x40, 0x8D, 0xE7, 0x9E, 0x48, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::SSD1327 *lcd = new upm::SSD1327(BUS_NUMBER, 0x3C);
|
||||
|
||||
// If you don't set the display to be white, the seeed logo will appear jagged
|
||||
lcd->setGrayLevel(12);
|
||||
lcd->draw(SeeedLogo, 96 * 96 / 8);
|
||||
|
||||
// Simple print hello world
|
||||
for (uint8_t i = 0; i < 12; i++)
|
||||
{
|
||||
lcd->setCursor(i, 0);
|
||||
lcd->setGrayLevel(i);
|
||||
lcd->write("Hello World");
|
||||
}
|
||||
|
||||
lcd->close();
|
||||
//! [Interesting]
|
||||
}
|
71
examples/c++/otp538u.cxx
Normal file
71
examples/c++/otp538u.cxx
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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 <iomanip>
|
||||
#include <signal.h>
|
||||
#include "otp538u.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
// analog voltage, usually 3.3 or 5.0
|
||||
#define OTP538U_AREF 5.0
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a OTP538U on analog pins A0 and A1
|
||||
// A0 is used for the Ambient Temperature and A1 is used for the
|
||||
// Object tempewrature.
|
||||
upm::OTP538U *temps = new upm::OTP538U(0, 1, OTP538U_AREF);
|
||||
|
||||
// Output ambient and object temperatures
|
||||
while (shouldRun)
|
||||
{
|
||||
cout << "Ambient temp: " << std::fixed << setprecision(2)
|
||||
<< temps->ambientTemperature()
|
||||
<< " C, Object temp: " << temps->objectTemperature()
|
||||
<< " C" << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete temps;
|
||||
return 0;
|
||||
}
|
63
examples/c++/ppd42ns.cxx
Normal file
63
examples/c++/ppd42ns.cxx
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Author: Zion Orent <zorent@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 "ppd42ns.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 dust sensor on GPIO pin D8
|
||||
upm::PPD42NS* dust = new upm::PPD42NS(8);
|
||||
upm::dustData data;
|
||||
cout << "This program will give readings every 30 seconds until you stop it" << endl;
|
||||
while (shouldRun)
|
||||
{
|
||||
data = dust->getData();
|
||||
cout << "Low pulse occupancy: " << data.lowPulseOccupancy << endl;
|
||||
cout << "Ratio: " << data.ratio << endl;
|
||||
cout << "Concentration: " << data.concentration << endl;
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete dust;
|
||||
return 0;
|
||||
}
|
61
examples/c++/pulsensor.cxx
Normal file
61
examples/c++/pulsensor.cxx
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 <string.h>
|
||||
#include <unistd.h>
|
||||
#include "pulsensor.h"
|
||||
#include <signal.h>
|
||||
|
||||
int doWork = 0;
|
||||
pulsensor_context sensor_ctx;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
doWork = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
handler (clbk_data data) {
|
||||
printf ("callback data (%d)\n", data);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
init_pulsensor (&sensor_ctx, handler);
|
||||
|
||||
start_sampler (&sensor_ctx);
|
||||
while (!doWork) {
|
||||
usleep (5);
|
||||
}
|
||||
stop_sampler (&sensor_ctx);
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
67
examples/c++/rfr359f.cxx
Normal file
67
examples/c++/rfr359f.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 "rfr359f.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 an RFR359F digital pin D2
|
||||
// This was tested on the Grove IR Distance Interrupter
|
||||
|
||||
upm::RFR359F* dInterruptor = new upm::RFR359F(2);
|
||||
|
||||
// The range appears to be about 4 inches, depending on adjustment
|
||||
while (shouldRun)
|
||||
{
|
||||
if (dInterruptor->objectDetected())
|
||||
cout << "Object detected" << endl;
|
||||
else
|
||||
cout << "Area is clear" << endl;
|
||||
|
||||
usleep(100000); // 100ms
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete dInterruptor;
|
||||
return 0;
|
||||
}
|
39
examples/c++/rgb-lcd.cxx
Normal file
39
examples/c++/rgb-lcd.cxx
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveish <yevgeniy.kiveisha@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 "jhd1313m1.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
// 0x62 RGB_ADDRESS, 0x3E LCD_ADDRESS
|
||||
upm::Jhd1313m1 *lcd = new upm::Jhd1313m1(0, 0x3E, 0x62);
|
||||
lcd->setCursor(0,0);
|
||||
lcd->write("Hello World");
|
||||
lcd->setCursor(1,2);
|
||||
lcd->write("Hello World");
|
||||
lcd->close();
|
||||
//! [Interesting]
|
||||
}
|
61
examples/c++/rotaryencoder.cxx
Normal file
61
examples/c++/rotaryencoder.cxx
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 "rotaryencoder.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 Rotary Encoder, using signal pins D2 and D3
|
||||
upm::RotaryEncoder* rotaryencoder = new upm::RotaryEncoder(2, 3);
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
cout << "Position: " << rotaryencoder->position() << endl;
|
||||
usleep(100000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete rotaryencoder;
|
||||
return 0;
|
||||
}
|
78
examples/c++/rpr220-intr.cxx
Normal file
78
examples/c++/rpr220-intr.cxx
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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 "rpr220.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
volatile unsigned int counter = 0;
|
||||
|
||||
// Our interrupt handler
|
||||
void rprISR(void *arg)
|
||||
{
|
||||
counter++;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// This example uses an interrupt handler to increment a counter
|
||||
|
||||
// Instantiate an RPR220 digital pin D2
|
||||
// This was tested on the Grove IR Reflective Sensor
|
||||
|
||||
upm::RPR220* rpr220 = new upm::RPR220(2);
|
||||
|
||||
// Here, we setup our Interupt Service Routine (ISR) to count
|
||||
// 'black' pulses detected.
|
||||
|
||||
rpr220->installISR(rprISR, NULL);
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
cout << "Counter: " << counter << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete rpr220;
|
||||
return 0;
|
||||
}
|
68
examples/c++/rpr220.cxx
Normal file
68
examples/c++/rpr220.cxx
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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 "rpr220.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// This example uses a simple method to determine current status
|
||||
|
||||
// Instantiate an RPR220 digital pin D2
|
||||
// This was tested on the Grove IR Reflective Sensor
|
||||
|
||||
upm::RPR220* rpr220 = new upm::RPR220(2);
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
if (rpr220->blackDetected())
|
||||
cout << "Black detected" << endl;
|
||||
else
|
||||
cout << "Black NOT detected" << endl;
|
||||
|
||||
usleep(100000); // 100ms
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete rpr220;
|
||||
return 0;
|
||||
}
|
79
examples/c++/st7735.cxx
Normal file
79
examples/c++/st7735.cxx
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 <string.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "st7735.h"
|
||||
#include <signal.h>
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::ST7735 * lcd = new upm::ST7735(7, 4, 9, 8);
|
||||
lcd->fillScreen (ST7735_RED);
|
||||
lcd->refresh ();
|
||||
|
||||
lcd->fillScreen (ST7735_CYAN);
|
||||
lcd->refresh ();
|
||||
|
||||
lcd->fillScreen (ST7735_BLACK);
|
||||
lcd->refresh ();
|
||||
|
||||
lcd->drawLine(10, 10, 10, 100, ST7735_MAGENTA);
|
||||
lcd->drawLine(20, 20, 10, 100, ST7735_YELLOW);
|
||||
lcd->drawLine(30, 30, 50, 100, ST7735_WHITE);
|
||||
lcd->refresh ();
|
||||
|
||||
lcd->drawPixel (20, 20, ST7735_GREEN);
|
||||
lcd->refresh ();
|
||||
|
||||
lcd->drawTriangle (50, 50, 80, 80, 60, 90, ST7735_GREEN);
|
||||
lcd->refresh ();
|
||||
|
||||
lcd->drawCircle (100, 110, 10, ST7735_BLUE);
|
||||
lcd->refresh ();
|
||||
|
||||
|
||||
lcd->setTextWrap(0x0);
|
||||
|
||||
lcd->setCursor(0, 30);
|
||||
lcd->setTextColor(ST7735_RED, ST7735_RED);
|
||||
lcd->setTextSize(1);
|
||||
lcd->print("Hello World!");
|
||||
|
||||
lcd->setCursor(10, 50);
|
||||
lcd->setTextColor(ST7735_RED, ST7735_YELLOW);
|
||||
lcd->setTextSize(2);
|
||||
lcd->print("BIG");
|
||||
|
||||
lcd->refresh ();
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete lcd;
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
73
examples/c++/stepmotor.cxx
Normal file
73
examples/c++/stepmotor.cxx
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 <string.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "stepmotor.h"
|
||||
#include <signal.h>
|
||||
|
||||
int doWork = 0;
|
||||
upm::StepMotor *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
doWork = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
sensor = new upm::StepMotor(4, 6);
|
||||
|
||||
while (!doWork) {
|
||||
sensor->setSpeed (500);
|
||||
sensor->stepForward (500);
|
||||
usleep (10000);
|
||||
sensor->stepBackwards (500);
|
||||
usleep (10000);
|
||||
|
||||
sensor->setSpeed (750);
|
||||
sensor->stepForward (500);
|
||||
usleep (10000);
|
||||
sensor->stepBackwards (500);
|
||||
usleep (10000);
|
||||
|
||||
sensor->setSpeed (1000);
|
||||
sensor->stepForward (500);
|
||||
usleep (10000);
|
||||
sensor->stepBackwards (500);
|
||||
usleep (10000);
|
||||
}
|
||||
|
||||
delete sensor;
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
65
examples/c++/ta12200.cxx
Normal file
65
examples/c++/ta12200.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 "ta12200.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 TA12-200 sensor on analog pin A0
|
||||
upm::TA12200* electricity = new upm::TA12200(0);
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
unsigned int maxVal = electricity->highestValue();
|
||||
float current = electricity->milliAmps(maxVal);
|
||||
|
||||
cout << "Max ADC Value: " << maxVal << ", current: " << current
|
||||
<< "mA" << endl;
|
||||
usleep(100000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete electricity;
|
||||
return 0;
|
||||
}
|
65
examples/c++/tcs3414cs.cxx
Normal file
65
examples/c++/tcs3414cs.cxx
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 "tcs3414cs.h"
|
||||
#include <signal.h>
|
||||
|
||||
int doWork = 0;
|
||||
upm::TCS3414CS *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
doWork = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::tcs3414sc_rgb_t rgb;
|
||||
|
||||
// Instantiate the color sensor on I2C
|
||||
sensor = new upm::TCS3414CS ();
|
||||
|
||||
// Print out the r, g, b, and clr value every 0.5 seconds
|
||||
while (!doWork) {
|
||||
sensor->readRGB (&rgb);
|
||||
std::cout << (int)rgb.r << ", " << (int)rgb.g << ", " << (int)rgb.b << ", " << rgb.clr << std::endl;
|
||||
usleep (500000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
64
examples/c++/th02.cxx
Normal file
64
examples/c++/th02.cxx
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 "th02.h"
|
||||
#include <signal.h>
|
||||
|
||||
int doWork = 0;
|
||||
upm::TH02 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
doWork = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
float temperature = 0.0;
|
||||
float humidity = 0.0;
|
||||
sensor = new upm::TH02 ();
|
||||
|
||||
while (!doWork) {
|
||||
temperature = sensor->getTemperature ();
|
||||
// humidity = sensor->getHumidity ();
|
||||
std::cout << "Temperature = " << temperature << ", Humidity = " << humidity << std::endl;
|
||||
usleep (500000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
70
examples/c++/tp401.cxx
Normal file
70
examples/c++/tp401.cxx
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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 "tp401.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
//! [Interesting]
|
||||
// Give a qualitative meaning to the value from the sensor
|
||||
std::string
|
||||
airQuality(uint16_t value)
|
||||
{
|
||||
if(value < 50) return "Fresh Air";
|
||||
if(value < 200) return "Normal Indoor Air";
|
||||
if(value < 400) return "Low Pollution";
|
||||
if(value < 600) return "High Pollution - Action Recommended";
|
||||
return "Very High Pollution - Take Action Immediately";
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
upm::TP401* airSensor = new upm::TP401(0); // Instantiate new grove air quality sensor on analog pin A0
|
||||
|
||||
cout << airSensor->name() << endl;
|
||||
|
||||
fprintf(stdout, "Heating sensor for 3 minutes...\n");
|
||||
// wait 3 minutes for sensor to warm up
|
||||
for(int i = 0; i < 3; i++) {
|
||||
if(i) {
|
||||
fprintf(stdout, "Please wait, %d minute(s) passed..\n", i);
|
||||
}
|
||||
sleep(60);
|
||||
}
|
||||
fprintf(stdout, "Sensor ready!\n");
|
||||
|
||||
while(true) {
|
||||
uint16_t value = airSensor->getSample(); // Read raw value
|
||||
float ppm = airSensor->getPPM(); // Read CO ppm (can vary slightly from previous read)
|
||||
fprintf(stdout, "raw: %4d ppm: %5.2f %s\n", value, ppm, airQuality(value).c_str());
|
||||
usleep(2500000); // Sleep for 2.5s
|
||||
}
|
||||
|
||||
delete airSensor;
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
54
examples/c++/tsl2561.cxx
Normal file
54
examples/c++/tsl2561.cxx
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Author: Nandkishor Sonar <Nandkishor.Sonar@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* LIGHT-TO-DIGITAL CONVERTER [TAOS-TSL2561]
|
||||
*
|
||||
* 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 "tsl2561.h"
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
upm::TSL2561 *sensor = NULL;
|
||||
int loopCount = 100;
|
||||
|
||||
//! [Interesting]
|
||||
if (argc < 2) {
|
||||
printf("Provide loop count \n");
|
||||
} else {
|
||||
loopCount = atoi(argv[1]);
|
||||
}
|
||||
sensor = new upm::TSL2561();
|
||||
|
||||
for(int i=0; i< loopCount; i++){
|
||||
fprintf(stdout, "Lux = %d\n", sensor->getLux());
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
delete(sensor);
|
||||
|
||||
return (0);
|
||||
}
|
54
examples/c++/ttp223.cxx
Normal file
54
examples/c++/ttp223.cxx
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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 "ttp223.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
// This example uses GPIO 0
|
||||
//! [Interesting]
|
||||
|
||||
// Create the TTP223 touch sensor object using GPIO pin 0
|
||||
upm::TTP223* touch = new upm::TTP223(0);
|
||||
|
||||
// Check whether or not a finger is near the touch sensor and
|
||||
// print accordingly, waiting one second between readings
|
||||
while( 1 ) {
|
||||
if ( touch->isPressed() ) {
|
||||
std::cout << touch->name() << " is pressed" << std::endl;
|
||||
} else {
|
||||
std::cout << touch->name() << " is not pressed" << std::endl;
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// Delete the touch sensor object
|
||||
delete touch;
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
97
examples/c++/ublox6.cxx
Normal file
97
examples/c++/ublox6.cxx
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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 "ublox6.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
const size_t bufferLength = 256;
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// Instantiate a Ublox6 GPS device on uart 0.
|
||||
upm::Ublox6* nmea = new upm::Ublox6(0);
|
||||
|
||||
// make sure port is initialized properly. 9600 baud is the default.
|
||||
if (!nmea->setupTty(B9600))
|
||||
{
|
||||
cerr << "Failed to setup tty port parameters" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Collect and output NMEA data. There are various libraries out on
|
||||
// the Internet, such as tinyGPS or tinyGPS++ that can handle
|
||||
// decoding NMEA data and presenting it in a more easily accessable
|
||||
// format. This example will just check for, and read raw NMEA data
|
||||
// from the device and output it on stdout.
|
||||
|
||||
// This device also supports numerous configuration options, which
|
||||
// you can set with writeData(). Please refer to the Ublox-6 data
|
||||
// sheet for further information on the formats of the data sent and
|
||||
// received, and the various operating modes available.
|
||||
|
||||
char nmeaBuffer[bufferLength];
|
||||
while (shouldRun)
|
||||
{
|
||||
// we don't want the read to block in this example, so always
|
||||
// check to see if data is available first.
|
||||
if (nmea->dataAvailable())
|
||||
{
|
||||
int rv = nmea->readData(nmeaBuffer, bufferLength);
|
||||
|
||||
if (rv > 0)
|
||||
write(1, nmeaBuffer, rv);
|
||||
|
||||
if (rv < 0) // some sort of read error occured
|
||||
{
|
||||
cerr << "Port read error." << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
usleep(100000); // 100ms
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete nmea;
|
||||
return 0;
|
||||
}
|
130
examples/c++/wt5001.cxx
Normal file
130
examples/c++/wt5001.cxx
Normal file
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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 "wt5001.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void printUsage(char *progname)
|
||||
{
|
||||
cout << "Usage:" << progname << " <command>" << endl;
|
||||
cout << "Commands:" << endl;
|
||||
cout << "0 - stop playing" << endl;
|
||||
cout << "1 - start playing track 1" << endl;
|
||||
cout << "2 - pause/un-pause playback" << endl;
|
||||
cout << "3 - next track" << endl;
|
||||
cout << "4 - previous track" << endl;
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
// Instantiate a WT5001 serial MP3 player on uart 0.
|
||||
// This example was tested on the Grove Serial MP3 module.
|
||||
|
||||
upm::WT5001* mp3 = new upm::WT5001(0);
|
||||
|
||||
int cmd = -1;
|
||||
if (argc > 1)
|
||||
cmd = atoi(argv[1]);
|
||||
|
||||
// make sure port is initialized properly. 9600 baud is the default.
|
||||
if (!mp3->setupTty(B9600))
|
||||
{
|
||||
cerr << "Failed to setup tty port parameters" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case 0:
|
||||
mp3->stop();
|
||||
break;
|
||||
|
||||
case 1:
|
||||
mp3->play(upm::WT5001::SD, 1);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
mp3->pause();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
mp3->next();
|
||||
break;
|
||||
|
||||
case 4:
|
||||
mp3->previous();
|
||||
break;
|
||||
|
||||
default:
|
||||
// nothing, just output usage, and info below
|
||||
printUsage(argv[0]);
|
||||
break;
|
||||
}
|
||||
|
||||
// Example: set the date
|
||||
// mp3->setDate(2015, 1, 1);
|
||||
|
||||
// Example: set the time
|
||||
// mp3->setTime(12, 30, 30);
|
||||
|
||||
// print out some information
|
||||
uint8_t vol = 0;
|
||||
if (mp3->getVolume(&vol))
|
||||
cout << "The current volume is: " << int(vol) << endl;
|
||||
|
||||
uint8_t ps = 0;
|
||||
if (mp3->getPlayState(&ps))
|
||||
cout << "The current play state is: " << int(ps) << endl;
|
||||
|
||||
uint16_t numf = 0;
|
||||
if (mp3->getNumFiles(upm::WT5001::SD, &numf))
|
||||
cout << "The number of files on the SD card is: " << int(numf) << endl;
|
||||
|
||||
uint16_t curf = 0;
|
||||
if (mp3->getCurrentFile(&curf))
|
||||
cout << "The current file is: " << int(curf) << endl;
|
||||
|
||||
uint16_t year = 0;
|
||||
uint8_t month = 0, day = 0;
|
||||
if (mp3->getDate(&year, &month, &day))
|
||||
cout << "The device date is: " << int(month) << "/" << int(day)
|
||||
<< "/" << int(year) << endl;
|
||||
|
||||
uint8_t hour = 0, minute = 0, second = 0;
|
||||
if (mp3->getTime(&hour, &minute, &second))
|
||||
cout << "The device time is: " << int(hour) << ":" << int(minute)
|
||||
<< ":" << int(second) << endl;
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete mp3;
|
||||
return 0;
|
||||
}
|
66
examples/c++/yg1006.cxx
Normal file
66
examples/c++/yg1006.cxx
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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 "yg1006.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 yg1006 flame sensor on digital pin D2
|
||||
upm::YG1006* flame = new upm::YG1006(2);
|
||||
|
||||
// check every second for the presence of a flame
|
||||
while (shouldRun)
|
||||
{
|
||||
bool val = flame->flameDetected();
|
||||
if (val)
|
||||
cout << "Flame detected." << endl;
|
||||
else
|
||||
cout << "No flame detected." << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete flame;
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user