mirror of
https://github.com/eclipse/upm.git
synced 2025-07-28 06:31:16 +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
@ -4,7 +4,7 @@
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* This module is based on the my9221 driver
|
||||
*
|
||||
*
|
||||
* 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
|
||||
@ -33,70 +33,40 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
GroveCircularLED::GroveCircularLED (uint8_t di, uint8_t dcki) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
// init clock context
|
||||
m_clkPinCtx = mraa_gpio_init(dcki);
|
||||
if (m_clkPinCtx == NULL) {
|
||||
fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", dcki);
|
||||
exit(1);
|
||||
}
|
||||
mraa_gpio_use_mmaped(m_clkPinCtx, 1);
|
||||
GroveCircularLED::GroveCircularLED (uint8_t di, uint8_t dcki)
|
||||
: m_clkPinCtx(dcki),
|
||||
m_dataPinCtx(di) {
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
// init data context
|
||||
m_dataPinCtx = mraa_gpio_init(di);
|
||||
if (m_dataPinCtx == NULL) {
|
||||
fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", di);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
mraa_gpio_use_mmaped(m_dataPinCtx, 1);
|
||||
m_clkPinCtx.useMmap(true);
|
||||
m_dataPinCtx.useMmap(true);
|
||||
|
||||
// set direction (out)
|
||||
error = mraa_gpio_dir(m_clkPinCtx, MRAA_GPIO_OUT);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
|
||||
// set direction (out)
|
||||
error = mraa_gpio_dir(m_dataPinCtx, MRAA_GPIO_OUT);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
error = m_clkPinCtx.dir(mraa::DIR_OUT);
|
||||
if (error != mraa::SUCCESS) {
|
||||
printError(error);
|
||||
}
|
||||
}
|
||||
|
||||
GroveCircularLED::~GroveCircularLED() {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
error = mraa_gpio_close (m_dataPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
error = mraa_gpio_close (m_clkPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
GroveCircularLED::setSpinner (uint8_t position) {
|
||||
if (position < 0 || position >= 24) {
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
return mraa::ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
for(uint8_t block_idx = 0; block_idx < 24; block_idx++) {
|
||||
if (block_idx % 12 == 0) {
|
||||
for(uint8_t block_idx = 0; block_idx < 24; block_idx++) {
|
||||
if (block_idx % 12 == 0) {
|
||||
send16bitBlock (CMDMODE);
|
||||
}
|
||||
uint32_t state = (block_idx == position) ? BIT_HIGH : BIT_LOW;
|
||||
send16bitBlock (state);
|
||||
}
|
||||
return lockData ();
|
||||
uint32_t state = (block_idx == position) ? BIT_HIGH : BIT_LOW;
|
||||
send16bitBlock (state);
|
||||
}
|
||||
return lockData ();
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
GroveCircularLED::setLevel (uint8_t level, bool direction) {
|
||||
if (level < 0 || level > 24) {
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
return mraa::ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
if (direction) {
|
||||
for(uint8_t block_idx = 24; block_idx > 0; block_idx--) {
|
||||
@ -118,7 +88,7 @@ GroveCircularLED::setLevel (uint8_t level, bool direction) {
|
||||
return lockData ();
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
GroveCircularLED::setStatus (bool status[24]) {
|
||||
for(uint8_t block_idx = 0; block_idx < 24; block_idx++) {
|
||||
if (block_idx % 12 == 0) {
|
||||
@ -129,36 +99,36 @@ GroveCircularLED::setStatus (bool status[24]) {
|
||||
return lockData ();
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
GroveCircularLED::lockData () {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
error = mraa_gpio_write (m_dataPinCtx, LOW);
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
error = m_dataPinCtx.write (LOW);
|
||||
usleep(10);
|
||||
|
||||
for(int idx = 0; idx < 4; idx++) {
|
||||
error = mraa_gpio_write (m_dataPinCtx, HIGH);
|
||||
error = mraa_gpio_write (m_dataPinCtx, LOW);
|
||||
error = m_dataPinCtx.write(HIGH);
|
||||
error = m_dataPinCtx.write(LOW);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa::Result
|
||||
GroveCircularLED::send16bitBlock (short data) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
for (uint8_t bit_idx = 0; bit_idx < MAX_BIT_PER_BLOCK; bit_idx++) {
|
||||
uint32_t state = (data & 0x8000) ? HIGH : LOW;
|
||||
error = mraa_gpio_write (m_dataPinCtx, state);
|
||||
state = mraa_gpio_read (m_clkPinCtx);
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
for (uint8_t bit_idx = 0; bit_idx < MAX_BIT_PER_BLOCK; bit_idx++) {
|
||||
uint32_t state = (data & 0x8000) ? HIGH : LOW;
|
||||
error = m_dataPinCtx.write (state);
|
||||
state = m_clkPinCtx.read ();
|
||||
|
||||
if (state) {
|
||||
state = LOW;
|
||||
} else {
|
||||
state = HIGH;
|
||||
if (state) {
|
||||
state = LOW;
|
||||
} else {
|
||||
state = HIGH;
|
||||
}
|
||||
|
||||
error = m_clkPinCtx.write (state);
|
||||
|
||||
data <<= 1;
|
||||
}
|
||||
|
||||
error = mraa_gpio_write (m_clkPinCtx, state);
|
||||
|
||||
data <<= 1;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* This module is based on the my9221 driver
|
||||
*
|
||||
*
|
||||
* 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
|
||||
@ -27,8 +27,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/aio.h>
|
||||
#include <mraa/gpio.h>
|
||||
#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 MAX_BIT_PER_BLOCK 16
|
||||
#define CMDMODE 0x0000
|
||||
@ -45,7 +54,7 @@ namespace upm {
|
||||
* @defgroup grovecircularled libupm-grovecircularled
|
||||
* @ingroup seeed display gpio
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @library grovecircularled
|
||||
* @sensor grovecircularled
|
||||
@ -72,33 +81,28 @@ namespace upm {
|
||||
* @param dcki Clock pin
|
||||
*/
|
||||
GroveCircularLED (uint8_t di, uint8_t dcki);
|
||||
|
||||
/**
|
||||
* MY9221 object destructor
|
||||
*/
|
||||
~GroveCircularLED ();
|
||||
|
||||
|
||||
/**
|
||||
* Sets the lighting status
|
||||
*
|
||||
* @param level Selected level for the circular LED (0-24)
|
||||
* @param direction Up or down; up is true and default
|
||||
*/
|
||||
mraa_result_t setLevel (uint8_t level, bool direction=true);
|
||||
|
||||
mraa::Result setLevel (uint8_t level, bool direction=true);
|
||||
|
||||
/**
|
||||
* Sets the spinner (lights up all the other LEDs but one)
|
||||
*
|
||||
* @param position Selected position for the spinner (0-23)
|
||||
*/
|
||||
mraa_result_t setSpinner (uint8_t position);
|
||||
mraa::Result setSpinner (uint8_t position);
|
||||
|
||||
/**
|
||||
* Sets the lighting status
|
||||
*
|
||||
* @param status Boolean array (24 elements)
|
||||
*/
|
||||
mraa_result_t setStatus (bool status[24]);
|
||||
mraa::Result setStatus (bool status[24]);
|
||||
|
||||
/**
|
||||
* Returns the name of the component
|
||||
@ -108,12 +112,12 @@ namespace upm {
|
||||
return m_name;
|
||||
}
|
||||
private:
|
||||
mraa_result_t lockData ();
|
||||
mraa_result_t send16bitBlock (short data);
|
||||
|
||||
mraa::Result lockData ();
|
||||
mraa::Result send16bitBlock (short data);
|
||||
|
||||
std::string m_name;
|
||||
mraa_gpio_context m_clkPinCtx;
|
||||
mraa_gpio_context m_dataPinCtx;
|
||||
mraa::Gpio m_clkPinCtx;
|
||||
mraa::Gpio m_dataPinCtx;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user