tm1637: Removing from upm due to possible derivation from lgpl code.

Signed-off-by: John Van Drasek <john.r.van.drasek@intel.com>
This commit is contained in:
John Van Drasek 2015-03-26 10:42:36 -07:00
parent b1fa94f1e3
commit 4a80a216c7
9 changed files with 3 additions and 424 deletions

View File

@ -91,11 +91,11 @@ make _pyupm_i2clcd
Sometimes you want to build a small C++ example against an installed library.
This is fairly easy if installed system-wide. Just link against the correct
library (in this case libupm-tm1637) and then add /usr/include/upm to the
library (in this case libupm-i2clcd) and then add /usr/include/upm to the
loader path:
~~~~~~~~~~~~
g++ test.cxx -lupm_tm1637 -I/usr/include/upm
g++ test.cxx -lupm-i2clcd -I/usr/include/upm
~~~~~~~~~~~~
You can also use pkg-config to return the information to you, which is
@ -103,5 +103,5 @@ considered the correct way if including UPM in a build system like cmake or
autotools on linux.
~~~~~~~~~~~
pkg-config --cflags --libs upm-tm1637
pkg-config --cflags --libs upm-i2clcd
~~~~~~~~~~~

View File

@ -14,7 +14,6 @@ add_executable (jhd1313m1-lcd-example jhd1313m1-lcd.cxx)
add_executable (buzzer-sound-example buzzer-sound.cxx)
add_executable (my9221-ledbar-example my9221-ledbar.cxx)
add_executable (my9221-updown-example my9221-updown.cxx)
add_executable (tm1637-example tm1637.cxx)
add_executable (nrf24l01-transmitter-example nrf24l01-transmitter.cxx)
add_executable (nrf24l01-receiver-example nrf24l01-receiver.cxx)
add_executable (nrf24l01-broadcast-example nrf24l01-broadcast.cxx)
@ -110,7 +109,6 @@ 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)
@ -203,7 +201,6 @@ target_link_libraries (jhd1313m1-lcd-example i2clcd ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (buzzer-sound-example buzzer ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (my9221-ledbar-example my9221 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (my9221-updown-example my9221 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (tm1637-example tm1637 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (nrf24l01-transmitter-example nrf24l01 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (nrf24l01-receiver-example nrf24l01 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (nrf24l01-broadcast-example nrf24l01 ${CMAKE_THREAD_LIBS_INIT})

View File

@ -1,42 +0,0 @@
/*
* 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;
}

View File

@ -1,25 +0,0 @@
# 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.
import pyupm_tm1637 as d
x = d.TM1637(8, 9)
x.write("1337")

View File

@ -1,5 +0,0 @@
set (libname "tm1637")
set (libdescription "upm 4 digit display tm1637")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

View File

@ -1,8 +0,0 @@
%module jsupm_tm1637
%include "../upm.i"
%{
#include "tm1637.h"
%}
%include "tm1637.h"

View File

@ -1,9 +0,0 @@
%module pyupm_tm1637
%include "../upm.i"
%feature("autodoc", "3");
%include "tm1637.h"
%{
#include "tm1637.h"
%}

View File

@ -1,191 +0,0 @@
/*
* 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 <stdlib.h>
#include "tm1637.h"
using namespace upm;
const uint8_t digitToSegment[] = {
// XGFEDCBA
0b00111111, // 0
0b00000110, // 1
0b01011011, // 2
0b01001111, // 3
0b01100110, // 4
0b01101101, // 5
0b01111101, // 6
0b00000111, // 7
0b01111111, // 8
0b01101111, // 9
0b01110111, // A
0b01111100, // B
0b00111001, // C
0b01000111, // D
0b01111001, // E
0b01110001 // F
};
TM1637::TM1637 (uint8_t di, uint8_t dcki) {
mraa_result_t error = MRAA_SUCCESS;
mraa_init();
// 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);
}
// 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);
}
// set direction (out)
error = mraa_gpio_dir(m_clkPinCtx, MRAA_GPIO_IN);
if (error != MRAA_SUCCESS) {
mraa_result_print(error);
}
// set direction (out)
error = mraa_gpio_dir(m_dataPinCtx, MRAA_GPIO_IN);
if (error != MRAA_SUCCESS) {
mraa_result_print(error);
}
error = mraa_gpio_write (m_dataPinCtx, LOW);
error = mraa_gpio_write (m_clkPinCtx, LOW);
}
TM1637::~TM1637() {
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
TM1637::setBrightness (uint8_t level) {
m_brightness = level;
}
mraa_result_t
TM1637::setSegments (const uint8_t segments[], uint8_t length, uint8_t pos) {
start();
writeByte(TM1637_I2C_COMM1);
stop();
start();
writeByte(TM1637_I2C_COMM2 + (pos & 0x03));
for (uint8_t idx = 0; idx < length; idx++) {
writeByte(segments[idx]);
}
stop();
start();
writeByte(TM1637_I2C_COMM3 + (m_brightness & 0x0f));
stop();
}
mraa_result_t
TM1637::write (std::string msg) {
char leter = '\0';
uint8_t data[] = { 0x0, 0x0, 0x0, 0x0 };
for (uint8_t idx = 0; idx < msg.length(); idx++) {
leter = msg[idx];
if (idx < 4) {
data[idx] = digitToSegment[strtol(&leter, NULL, 16)];
}
}
setBrightness (0x0f);
setSegments(data);
}
mraa_result_t
TM1637::pinMode (mraa_gpio_context ctx, gpio_dir_t mode) {
mraa_result_t error = MRAA_SUCCESS;
error = mraa_gpio_dir(ctx, mode);
if (error != MRAA_SUCCESS) {
mraa_result_print(error);
}
}
mraa_result_t
TM1637::start() {
pinMode (m_dataPinCtx, MRAA_GPIO_OUT);
usleep(PULSE_LENGTH);
}
mraa_result_t
TM1637::stop() {
pinMode (m_dataPinCtx, MRAA_GPIO_OUT);
usleep(PULSE_LENGTH);
pinMode (m_clkPinCtx, MRAA_GPIO_IN);
usleep(PULSE_LENGTH);
pinMode (m_dataPinCtx, MRAA_GPIO_IN);
usleep(PULSE_LENGTH);
}
mraa_result_t
TM1637::writeByte(uint8_t value) {
for (uint8_t idx = 0; idx < 8; idx++) {
pinMode(m_clkPinCtx, MRAA_GPIO_OUT);
usleep(PULSE_LENGTH);
if (value & 0x01) {
pinMode(m_dataPinCtx, MRAA_GPIO_IN);
} else {
pinMode(m_dataPinCtx, MRAA_GPIO_OUT);
}
usleep(PULSE_LENGTH);
pinMode(m_clkPinCtx, MRAA_GPIO_IN);
usleep(PULSE_LENGTH);
value = value >> 1;
}
pinMode(m_clkPinCtx, MRAA_GPIO_OUT);
pinMode(m_dataPinCtx, MRAA_GPIO_IN);
usleep(PULSE_LENGTH);
pinMode(m_clkPinCtx, MRAA_GPIO_IN);
usleep(PULSE_LENGTH);
uint8_t ack = mraa_gpio_read (m_dataPinCtx);
if (ack == 0) {
pinMode(m_dataPinCtx, MRAA_GPIO_OUT);
} usleep(PULSE_LENGTH);
pinMode(m_clkPinCtx, MRAA_GPIO_OUT);
usleep(50);
}

View File

@ -1,138 +0,0 @@
/*
* 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 <mraa/aio.h>
#include <mraa/gpio.h>
#define SEG_A 0b00000001
#define SEG_B 0b00000010
#define SEG_C 0b00000100
#define SEG_D 0b00001000
#define SEG_E 0b00010000
#define SEG_F 0b00100000
#define SEG_G 0b01000000
#define TM1637_I2C_COMM1 0x40
#define TM1637_I2C_COMM2 0xC0
#define TM1637_I2C_COMM3 0x80
#define PULSE_LENGTH 50
#define HIGH 1
#define LOW 0
namespace upm {
/**
* @brief C++ API for Seven segments screen
*
* This file defines the TM1637 C++ interface for lib4digitdisplay
*
* @defgroup tm1637 libupm-tm1637
* @ingroup seeed gpio display
*/
/**
* @library tm1637
* @sensor tm1637
* @comname Seven segment screen display
* @type display
* @man seeed
* @web http://www.seeedstudio.com/wiki/Grove_-_4-Digit_Display
* @con gpio
*
* @brief C++ API for Seven segments screen
*
* This file defines the TM1637 C++ interface for lib4digitdisplay
* A
* ---
* F | | B
* -G-
* E | | C
* ---
* D
*
* @snippet tm1637.cxx Interesting
*/
class TM1637 {
public:
/**
* Instanciates a TM1637 object
*
* @param di data pin
* @param dcki clock pin
*/
TM1637 (uint8_t di, uint8_t dcki);
/**
* TM1637 object destructor, this will close all used Gpio
* pins (di and dcki)
*/
~TM1637 ();
/**
* Set the brightness of the seven segment display
*
* @param level The brightness level of leds
*/
mraa_result_t setBrightness (uint8_t level);
/**
* Set the the segment screen data and number of segments
*
* @param segments data to write on the segments, each elemnt
* in array is segment
* @param length number of elements in segments array
* @param pos data writing offset
*/
mraa_result_t setSegments (const uint8_t segments[], uint8_t length = 4, uint8_t pos = 0);
/**
* Write message on the screen.
*
* @param msg The message to be written on the sreen
*/
mraa_result_t write (std::string msg);
/**
* Return name of the component
*/
std::string name()
{
return m_name;
}
private:
mraa_result_t start();
mraa_result_t stop();
mraa_result_t writeByte (uint8_t value);
mraa_result_t pinMode (mraa_gpio_context ctx, gpio_dir_t mode);
mraa_gpio_context m_clkPinCtx;
mraa_gpio_context m_dataPinCtx;
std::string m_name;
uint8_t m_brightness;
};
}