md: C implementation; C++ wraps C

Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
Jon Trulson
2016-10-18 17:02:33 -06:00
parent df5b3805c5
commit 8ac8be9e0a
16 changed files with 813 additions and 397 deletions

View File

@ -1,6 +1,6 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2015 Intel Corporation.
* Copyright (c) 2015-2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -34,8 +34,7 @@ int main(int argc, char **argv)
//! [Interesting]
// Instantiate an I2C Motor Driver on I2C bus 0
upm::MD *motors = new upm::MD(MD_I2C_BUS,
MD_DEFAULT_I2C_ADDR);
upm::MD *motors = new upm::MD(MD_I2C_BUS, MD_DEFAULT_I2C_ADDR);
// This example demonstrates using the MD to drive a stepper motor
@ -46,13 +45,13 @@ int main(int argc, char **argv)
motors->setStepperSteps(100);
// let it go - clockwise rotation, 10 RPM speed
motors->enableStepper(upm::MD::STEP_DIR_CW, 10);
motors->enableStepper(MD_STEP_DIR_CW, 10);
sleep(3);
// Now do it backwards...
motors->setStepperSteps(100);
motors->enableStepper(upm::MD::STEP_DIR_CCW, 10);
motors->enableStepper(MD_STEP_DIR_CCW, 10);
// now disable
motors->disableStepper();

View File

@ -1,6 +1,6 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2014 Intel Corporation.
* Copyright (c) 2014-2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -34,18 +34,17 @@ int main(int argc, char **argv)
//! [Interesting]
// Instantiate an I2C Motor Driver on I2C bus 0
upm::MD *motors = new upm::MD(MD_I2C_BUS,
MD_DEFAULT_I2C_ADDR);
upm::MD *motors = new upm::MD(MD_I2C_BUS, MD_DEFAULT_I2C_ADDR);
// set direction to CW and set speed to 50%
cout << "Spin M1 and M2 at half speed for 3 seconds" << endl;
motors->setMotorDirections(upm::MD::DIR_CW, upm::MD::DIR_CW);
motors->setMotorDirections(MD_DIR_CW, MD_DIR_CW);
motors->setMotorSpeeds(127, 127);
sleep(3);
// counter clockwise
cout << "Reversing M1 and M2 for 3 seconds" << endl;
motors->setMotorDirections(upm::MD::DIR_CCW, upm::MD::DIR_CCW);
motors->setMotorDirections(MD_DIR_CCW, MD_DIR_CCW);
sleep(3);
//! [Interesting]