mirror of
https://github.com/eclipse/upm.git
synced 2025-07-04 19:01:21 +03:00
java: changed some C types to C++ types
Signed-off-by: Andrei Vasiliu <andrei.vasiliu@intel.com> Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com> Conflicts: src/mma7455/mma7455.cxx src/mma7455/mma7455.h src/sm130/sm130.cxx src/sm130/sm130.h
This commit is contained in:

committed by
Mihai Tudor Panu

parent
b8835958e2
commit
ab730038fd
@ -30,36 +30,19 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
StepMotor::StepMotor (int dirPin, int stePin) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
StepMotor::StepMotor (int dirPin, int stePin)
|
||||
: m_pwmStepContext(stePin), m_dirPinCtx(dirPin) {
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
m_name = "StepMotor";
|
||||
|
||||
mraa_init();
|
||||
mraa::init();
|
||||
|
||||
m_stePin = stePin;
|
||||
m_dirPin = dirPin;
|
||||
|
||||
m_pwmStepContext = mraa_pwm_init (m_stePin);
|
||||
m_dirPinCtx = mraa_gpio_init (m_dirPin);
|
||||
if (m_dirPinCtx == NULL) {
|
||||
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_dirPin);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
error = mraa_gpio_dir (m_dirPinCtx, MRAA_GPIO_OUT);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
}
|
||||
}
|
||||
|
||||
StepMotor::~StepMotor() {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
mraa_pwm_close (m_pwmStepContext);
|
||||
|
||||
error = mraa_gpio_close (m_dirPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
error = m_dirPinCtx.dir (mraa::DIR_OUT);
|
||||
if (error != mraa::SUCCESS) {
|
||||
mraa::printError (error);
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,51 +59,51 @@ StepMotor::setSpeed (int speed) {
|
||||
m_speed = speed;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
StepMotor::stepForward (int ticks) {
|
||||
dirForward ();
|
||||
return move (ticks);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
StepMotor::stepBackwards (int ticks) {
|
||||
dirBackwards ();
|
||||
return move (ticks);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
StepMotor::move (int ticks) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
mraa_pwm_enable (m_pwmStepContext, 1);
|
||||
m_pwmStepContext.enable (1);
|
||||
for (int tick = 0; tick < ticks; tick++) {
|
||||
mraa_pwm_period_us (m_pwmStepContext, m_speed);
|
||||
mraa_pwm_pulsewidth_us (m_pwmStepContext, PULSEWIDTH);
|
||||
m_pwmStepContext.period_us (m_speed);
|
||||
m_pwmStepContext.pulsewidth_us (PULSEWIDTH);
|
||||
}
|
||||
mraa_pwm_enable (m_pwmStepContext, 0);
|
||||
m_pwmStepContext.enable (0);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
StepMotor::dirForward () {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
error = mraa_gpio_write (m_dirPinCtx, HIGH);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
error = m_dirPinCtx.write (HIGH);
|
||||
if (error != mraa::SUCCESS) {
|
||||
mraa::printError (error);
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
StepMotor::dirBackwards () {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
error = mraa_gpio_write (m_dirPinCtx, LOW);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
error = m_dirPinCtx.write (LOW);
|
||||
if (error != mraa::SUCCESS) {
|
||||
mraa::printError (error);
|
||||
}
|
||||
|
||||
return error;
|
||||
|
@ -28,9 +28,18 @@
|
||||
|
||||
#include <string>
|
||||
#include <math.h>
|
||||
#include <mraa/pwm.h>
|
||||
#include <mraa/aio.h>
|
||||
#include <mraa/gpio.h>
|
||||
#include <mraa/pwm.hpp>
|
||||
#include <mraa/aio.hpp>
|
||||
#include <mraa/common.hpp>
|
||||
|
||||
#ifdef SWIGJAVA
|
||||
#undef SWIGJAVA
|
||||
#include <mraa/gpio.hpp>
|
||||
#define SWIGJAVA
|
||||
|
||||
#else
|
||||
#include <mraa/gpio.hpp>
|
||||
#endif
|
||||
|
||||
#define MIN_PERIOD 500
|
||||
#define MAX_PERIOD 1000
|
||||
@ -76,8 +85,11 @@ class StepMotor {
|
||||
|
||||
/**
|
||||
* StepMotor object destructor
|
||||
*/
|
||||
~StepMotor ();
|
||||
* no need for the destructor; all the connections will be
|
||||
* closed when m_dirPinCtx and m_pwmStepContext go out of
|
||||
* scope
|
||||
* ~StepMotor ();
|
||||
**/
|
||||
|
||||
/**
|
||||
* Sets the rotation speed
|
||||
@ -91,14 +103,14 @@ class StepMotor {
|
||||
*
|
||||
* @param ticks Number of ticks the motor moves
|
||||
*/
|
||||
mraa_result_t stepForward (int ticks);
|
||||
mraa::Result stepForward (int ticks);
|
||||
|
||||
/**
|
||||
* Rotates the motor backward
|
||||
*
|
||||
* @param ticks Number of ticks the motor moves
|
||||
*/
|
||||
mraa_result_t stepBackwards (int ticks);
|
||||
mraa::Result stepBackwards (int ticks);
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
@ -107,11 +119,11 @@ class StepMotor {
|
||||
int m_stePin;
|
||||
int m_speed;
|
||||
|
||||
mraa_gpio_context m_dirPinCtx;
|
||||
mraa_pwm_context m_pwmStepContext;
|
||||
mraa::Gpio m_dirPinCtx;
|
||||
mraa::Pwm m_pwmStepContext;
|
||||
|
||||
mraa_result_t move (int ticks);
|
||||
mraa_result_t dirForward ();
|
||||
mraa_result_t dirBackwards ();
|
||||
mraa::Result move (int ticks);
|
||||
mraa::Result dirForward ();
|
||||
mraa::Result dirBackwards ();
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user