mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
ledbar: added ledbar module
Signed-off-by: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
This commit is contained in:
parent
c60b342e0f
commit
dd55123062
@ -4,11 +4,13 @@ add_executable (grovetemp grovetemp.cxx)
|
|||||||
add_executable (lcm-lcd lcm-lcd.cxx)
|
add_executable (lcm-lcd lcm-lcd.cxx)
|
||||||
add_executable (rgb-lcd rgb-lcd.cxx)
|
add_executable (rgb-lcd rgb-lcd.cxx)
|
||||||
add_executable (buzzer-sound buzzer-sound.cxx)
|
add_executable (buzzer-sound buzzer-sound.cxx)
|
||||||
|
add_executable (led-bar led-bar.cxx)
|
||||||
|
|
||||||
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
|
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
|
||||||
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
|
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
|
||||||
include_directories (${PROJECT_SOURCE_DIR}/src/lcd)
|
include_directories (${PROJECT_SOURCE_DIR}/src/lcd)
|
||||||
include_directories (${PROJECT_SOURCE_DIR}/src/buzzer)
|
include_directories (${PROJECT_SOURCE_DIR}/src/buzzer)
|
||||||
|
include_directories (${PROJECT_SOURCE_DIR}/src/ledbar)
|
||||||
|
|
||||||
target_link_libraries (compass hmc5883l ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries (compass hmc5883l ${CMAKE_THREAD_LIBS_INIT})
|
||||||
target_link_libraries (groveled grove ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries (groveled grove ${CMAKE_THREAD_LIBS_INIT})
|
||||||
@ -16,3 +18,4 @@ target_link_libraries (grovetemp grove ${CMAKE_THREAD_LIBS_INIT})
|
|||||||
target_link_libraries (lcm-lcd i2clcd ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries (lcm-lcd i2clcd ${CMAKE_THREAD_LIBS_INIT})
|
||||||
target_link_libraries (rgb-lcd i2clcd ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries (rgb-lcd i2clcd ${CMAKE_THREAD_LIBS_INIT})
|
||||||
target_link_libraries (buzzer-sound buzzer ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries (buzzer-sound buzzer ${CMAKE_THREAD_LIBS_INIT})
|
||||||
|
target_link_libraries (led-bar ledbar ${CMAKE_THREAD_LIBS_INIT})
|
||||||
|
61
examples/led-bar.cxx
Normal file
61
examples/led-bar.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 "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)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "exiting application" << std::endl;
|
||||||
|
|
||||||
|
delete bar;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -2,3 +2,4 @@ add_subdirectory (hmc5883l)
|
|||||||
add_subdirectory (grove)
|
add_subdirectory (grove)
|
||||||
add_subdirectory (lcd)
|
add_subdirectory (lcd)
|
||||||
add_subdirectory (buzzer)
|
add_subdirectory (buzzer)
|
||||||
|
add_subdirectory (ledbar)
|
||||||
|
4
src/ledbar/CMakeLists.txt
Normal file
4
src/ledbar/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
set (libname "ledbar")
|
||||||
|
add_library (ledbar SHARED my9221.cxx)
|
||||||
|
include_directories (${MAA_INCLUDE_DIR})
|
||||||
|
target_link_libraries (ledbar ${MAA_LIBRARIES})
|
7
src/ledbar/jsupm_my9221.i
Normal file
7
src/ledbar/jsupm_my9221.i
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
%module jsupm_my9221
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "my9221.h"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "my9221.h"
|
118
src/ledbar/my9221.cxx
Normal file
118
src/ledbar/my9221.cxx
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
* 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 <iostream>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "my9221.h"
|
||||||
|
|
||||||
|
using namespace upm;
|
||||||
|
|
||||||
|
MY9221::MY9221 (uint8_t di, uint8_t dcki) {
|
||||||
|
maa_result_t error = MAA_SUCCESS;
|
||||||
|
maa_init();
|
||||||
|
|
||||||
|
// init clock context
|
||||||
|
m_clkPinCtx = maa_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);
|
||||||
|
}
|
||||||
|
// init data context
|
||||||
|
m_dataPinCtx = maa_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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set direction (out)
|
||||||
|
error = maa_gpio_dir(m_clkPinCtx, MAA_GPIO_OUT);
|
||||||
|
if (error != MAA_SUCCESS) {
|
||||||
|
maa_result_print(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set direction (out)
|
||||||
|
error = maa_gpio_dir(m_dataPinCtx, MAA_GPIO_OUT);
|
||||||
|
if (error != MAA_SUCCESS) {
|
||||||
|
maa_result_print(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MY9221::~MY9221() {
|
||||||
|
maa_result_t error = MAA_SUCCESS;
|
||||||
|
error = maa_gpio_close (m_dataPinCtx);
|
||||||
|
if (error != MAA_SUCCESS) {
|
||||||
|
maa_result_print(error);
|
||||||
|
}
|
||||||
|
error = maa_gpio_close (m_clkPinCtx);
|
||||||
|
if (error != MAA_SUCCESS) {
|
||||||
|
maa_result_print(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
maa_result_t
|
||||||
|
MY9221::setBarLevel (uint8_t level) {
|
||||||
|
if (level > 10) {
|
||||||
|
return MAA_ERROR_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
send16bitBlock (CMDMODE);
|
||||||
|
for(uint8_t block_idx = 0; block_idx < 12; block_idx++) {
|
||||||
|
uint32_t state = (block_idx < level) ? BIT_HIGH : BIT_LOW;
|
||||||
|
send16bitBlock (state);
|
||||||
|
}
|
||||||
|
lockData ();
|
||||||
|
}
|
||||||
|
|
||||||
|
maa_result_t
|
||||||
|
MY9221::lockData () {
|
||||||
|
maa_result_t error = MAA_SUCCESS;
|
||||||
|
error = maa_gpio_write (m_dataPinCtx, LOW);
|
||||||
|
usleep(100);
|
||||||
|
|
||||||
|
for(int idx = 0; idx < 4; idx++) {
|
||||||
|
error = maa_gpio_write (m_dataPinCtx, HIGH);
|
||||||
|
error = maa_gpio_write (m_dataPinCtx, LOW);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
maa_result_t
|
||||||
|
MY9221::send16bitBlock (short data) {
|
||||||
|
maa_result_t error = MAA_SUCCESS;
|
||||||
|
for (uint8_t bit_idx = 0; bit_idx < MAX_BIT_PER_BLOCK; bit_idx++) {
|
||||||
|
uint32_t state = (data & 0x8000) ? HIGH : LOW;
|
||||||
|
error = maa_gpio_write (m_dataPinCtx, state);
|
||||||
|
state = maa_gpio_read (m_clkPinCtx);
|
||||||
|
|
||||||
|
if (state) {
|
||||||
|
state = LOW;
|
||||||
|
} else {
|
||||||
|
state = HIGH;
|
||||||
|
}
|
||||||
|
|
||||||
|
error = maa_gpio_write (m_clkPinCtx, state);
|
||||||
|
|
||||||
|
data <<= 1;
|
||||||
|
}
|
||||||
|
}
|
58
src/ledbar/my9221.h
Normal file
58
src/ledbar/my9221.h
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <maa/aio.h>
|
||||||
|
#include <maa/gpio.h>
|
||||||
|
|
||||||
|
#define MAX_BIT_PER_BLOCK 16
|
||||||
|
#define CMDMODE 0x0000
|
||||||
|
#define BIT_HIGH 0x00ff
|
||||||
|
#define BIT_LOW 0x0000
|
||||||
|
|
||||||
|
#define HIGH 1
|
||||||
|
#define LOW 0
|
||||||
|
|
||||||
|
namespace upm {
|
||||||
|
|
||||||
|
class MY9221 {
|
||||||
|
public:
|
||||||
|
MY9221 (uint8_t di, uint8_t dcki);
|
||||||
|
~MY9221 ();
|
||||||
|
maa_result_t setBarLevel (uint8_t level);
|
||||||
|
std::string name()
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
maa_result_t lockData ();
|
||||||
|
maa_result_t send16bitBlock (short data);
|
||||||
|
|
||||||
|
std::string m_name;
|
||||||
|
maa_gpio_context m_clkPinCtx;
|
||||||
|
maa_gpio_context m_dataPinCtx;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
8
src/ledbar/pyupm_my9221.i
Normal file
8
src/ledbar/pyupm_my9221.i
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
%module pyupm_my9221
|
||||||
|
|
||||||
|
%feature("autodoc", "3");
|
||||||
|
|
||||||
|
%include "my9221.h"
|
||||||
|
%{
|
||||||
|
#include "my9221.h"
|
||||||
|
%}
|
Loading…
x
Reference in New Issue
Block a user