lcd/lcm1602/jhd1313m1: remove lcm1602 and jhd1313m1 from lcd library

The lcm1602 and jhd1313m1 drivers had been rewritten in C with a C++
wrapper some time ago, however the original lcm and jhd drivers were
still present in the lcd library.  In addition, to avoid header file
conflicts, the new, separated lcm and jhd header files were renamed
with a .hxx prefix.

This patch:

- renames the new lcm1602/ and jhd1313m1/ header files to have the
  usual .hpp prefix.

- removes the lcm1602, jhd1313m1, and sainsmartks drivers from the
  lcd/ (i2clcd) library.

- fixes the examples to use the "new" libraries (lcm1602 and
  jhd1313m1)

- changes the argument type for the createChar() (C++) to use a byte
  vector (std::vector<uint8_t>) rather than a typedef'd char array.
  The lcm1602_create_char() function (C) uses a standard char *.  The
  use of std::vector is well supported by SWIG.

- SWIG interface files changed to use upm_vectortypes.i, and removes
  the carrays helpers, which should no longer be needed for these
  drivers.

- removes the inclusion of the driver C .h header files into the SWIG
  interface files - this should not be needed for these drivers.

- the sainsmartks driver will be placed into it's own new lcdks (LCD
  Keypad Shield) library.  This library should support the
  SainsmartKS, DFRobot LCD Keypad Shield, and similar products from
  other manufacturers in a future commit.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
Jon Trulson 2017-03-15 11:43:50 -06:00
parent d965b92af1
commit ab171573f9
34 changed files with 114 additions and 1358 deletions

View File

@ -336,14 +336,14 @@ add_example (abpdrrt005pg2a5)
# These are special cases where you specify example binary, source file and module(s)
include_directories (${PROJECT_SOURCE_DIR}/src)
add_custom_example (groveled-multi-example-cxx groveled-multi.cxx grove)
add_custom_example (lcm1602-i2c-example-cxx lcm1602-i2c.cxx lcd)
add_custom_example (lcm1602-parallel-example-cxx lcm1602-parallel.cxx lcd)
add_custom_example (jhd1313m1-lcd-example-cxx jhd1313m1-lcd.cxx lcd)
add_custom_example (lcm1602-i2c-example-cxx lcm1602-i2c.cxx lcm1602)
add_custom_example (lcm1602-parallel-example-cxx lcm1602-parallel.cxx lcm1602)
add_custom_example (jhd1313m1-lcd-example-cxx jhd1313m1-lcd.cxx jhd1313m1)
add_custom_example (es08a-example-cxx es08a.cxx servo)
add_custom_example (ssd1306-oled-example-cxx ssd1306-oled.cxx lcd)
add_custom_example (ssd1308-oled-example-cxx ssd1308-oled.cxx lcd)
add_custom_example (ssd1327-oled-example-cxx ssd1327-oled.cxx lcd)
add_custom_example (sainsmartks-example-cxx sainsmartks.cxx lcd)
#add_custom_example (sainsmartks-example-cxx sainsmartks.cxx lcd)
add_custom_example (eboled-example-cxx eboled.cxx lcd)
add_custom_example (mpu60x0-example-cxx mpu60x0.cxx mpu9150)
add_custom_example (ak8975-example-cxx ak8975.cxx mpu9150)

View File

@ -167,10 +167,10 @@ add_example(Ads1115Sample ads1x15)
add_example(SensorTemplateSample sensortemplate)
add_example(P9813Sample p9813)
add_example_with_path(Jhd1313m1_lcdSample lcd i2clcd)
add_example_with_path(Jhd1313m1Sample lcd i2clcd)
add_example_with_path(Lcm1602_i2cSample lcd i2clcd)
add_example_with_path(Lcm1602_parallelSample lcd i2clcd)
add_example_with_path(Jhd1313m1_lcdSample jhd1313m1 jhd1313m1)
add_example_with_path(Jhd1313m1Sample jhd1313m1 jhd1313m1)
add_example_with_path(Lcm1602_i2cSample lcm1602 lcm1602)
add_example_with_path(Lcm1602_parallelSample lcm1602 lcm1602)
add_example_with_path(SSD1308_oledSample lcd i2clcd)
add_example_with_path(SSD1327_oledSample lcd i2clcd)
add_example_with_path(BME280_Example bmp280 bmp280)

View File

@ -26,7 +26,7 @@ public class Jhd1313m1Sample {
public static void main(String[] args) throws InterruptedException {
// ! [Interesting]
upm_i2clcd.Jhd1313m1 lcd = new upm_i2clcd.Jhd1313m1(0);
upm_jhd1313m1.Jhd1313m1 lcd = new upm_jhd1313m1.Jhd1313m1(0);
lcd.setCursor(0, 0);
lcd.write("Hello World");

View File

@ -26,7 +26,8 @@ public class Jhd1313m1_lcdSample{
public static void main(String[] args) throws InterruptedException {
//! [Interesting]
upm_i2clcd.Jhd1313m1 lcd = new upm_i2clcd.Jhd1313m1(1, 0x3E, 0x62);
upm_jhd1313m1.Jhd1313m1 lcd =
new upm_jhd1313m1.Jhd1313m1(1, 0x3E, 0x62);
lcd.setCursor(0,0);
lcd.write("Hello World");

View File

@ -27,7 +27,7 @@ public class Lcm1602_i2cSample {
public static void main(String[] args) throws InterruptedException {
// ! [Interesting]
upm_i2clcd.Lcm1602 lcd = new upm_i2clcd.Lcm1602(0, 0x27);
upm_lcm1602.Lcm1602 lcd = new upm_lcm1602.Lcm1602(0, 0x27);
lcd.setCursor(0, 0);
lcd.write("Hello World");
@ -37,13 +37,6 @@ public class Lcm1602_i2cSample {
lcd.write("Hello World");
Thread.sleep(3000);
lcd.setCursor(2, 4);
lcd.write("Hello World");
Thread.sleep(3000);
lcd.setCursor(3, 6);
lcd.write("Hello World");
Thread.sleep(3000);
// ! [Interesting]
}
}

View File

@ -38,7 +38,8 @@ public class Lcm1602_parallelSample {
// 10K trimmer potentiometer:
// ends to +5V and ground
// wiper to LCD VO pin (pin 3)
upm_i2clcd.Lcm1602 lcd = new upm_i2clcd.Lcm1602((short) 8, (short) 13, (short) 2, (short) 3, (short) 4, (short) 5, (short) 20, (short) 2);
upm_lcm1602.Lcm1602 lcd =
new upm_lcm1602.Lcm1602(8, 13, 2, 3, 4, 5, (short) 16, (short) 2);
lcd.setCursor(0, 0);
lcd.write("Hello World");

View File

@ -23,7 +23,7 @@
*/
// Load lcd module on I2C
var LCD = require('jsupm_i2clcd');
var LCD = require('jsupm_jhd1313m1');
// Initialize Jhd1313m1 at 0x62 (RGB_ADDRESS) and 0x3E (LCD_ADDRESS)
var myLcd = new LCD.Jhd1313m1 (0, 0x3E, 0x62);

View File

@ -21,7 +21,7 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from upm import pyupm_i2clcd as lcd
from upm import pyupm_jhd1313m1 as lcd
def main():
# Initialize Jhd1313m1 at 0x3E (LCD_ADDRESS) and 0x62 (RGB_ADDRESS)

View File

@ -2,8 +2,7 @@ upm_mixed_module_init (NAME jhd1313m1
DESCRIPTION "LCD Display Driver for the JHD1313M1 Controller for HD44780-based Displays"
C_HDR jhd1313m1.h
C_SRC jhd1313m1.c
CPP_HDR jhd1313m1.hxx
CPP_HDR jhd1313m1.hpp
CPP_SRC jhd1313m1.cxx
# FTI_SRC jhd1313m1_fti.c
CPP_WRAPS_C
REQUIRES mraa lcm1602)

View File

@ -1,31 +1,11 @@
%module javaupm_jhd1313m1
%include "../upm.i"
%include "stdint.i"
%include "../upm_vectortypes.i"
%include "typemaps.i"
%include "arrays_java.i";
%apply signed char[] {uint8_t []};
%ignore BasicFont;
%typemap(jni) (uint8_t *data, int bytes) "jbyteArray";
%typemap(jtype) (uint8_t *data, int bytes) "byte[]";
%typemap(jstype) (uint8_t *data, int bytes) "byte[]";
%typemap(javain) (uint8_t *data, int bytes) "$javainput";
%typemap(in) (uint8_t *data, int bytes) {
$1 = (uint8_t *) JCALL2(GetByteArrayElements, jenv, $input, NULL);
$2 = JCALL1(GetArrayLength, jenv, $input);
}
%typemap(freearg) (uint8_t *data, int bytes) {
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, 0);
}
%include "jhd1313m1.h"
%include "jhd1313m1.hxx"
%include "jhd1313m1.hpp"
%{
#include "jhd1313m1.hxx"
#include "jhd1313m1.hpp"
%}
%pragma(java) jniclasscode=%{

View File

@ -216,7 +216,7 @@ upm_result_t jhd1313m1_home(const jhd1313m1_context dev)
upm_result_t jhd1313m1_create_char(const jhd1313m1_context dev,
unsigned int slot,
jhd1313m1_custom_char_t data)
char *data)
{
assert(dev != NULL);

View File

@ -35,7 +35,7 @@
#include <stdexcept>
#include <unistd.h>
#include "jhd1313m1.hxx"
#include "jhd1313m1.hpp"
using namespace upm;
@ -83,9 +83,10 @@ upm_result_t Jhd1313m1::home()
}
upm_result_t Jhd1313m1::createChar(uint8_t charSlot,
jhd1313m1_custom_char_t charData)
std::vector<uint8_t> charData)
{
return jhd1313m1_create_char(m_jhd1313m1, charSlot, charData);
return jhd1313m1_create_char(m_jhd1313m1, charSlot,
(char *)charData.data());
}
upm_result_t Jhd1313m1::displayOn()

View File

@ -63,11 +63,6 @@ extern "C" {
uint8_t entryDisplayMode;
} *jhd1313m1_context;
/**
* Custom character.
*/
typedef char jhd1313m1_custom_char_t[8];
/**
* JHD1313M1 I2C initialization.
*
@ -147,7 +142,7 @@ extern "C" {
*/
upm_result_t jhd1313m1_create_char(const jhd1313m1_context dev,
unsigned int slot,
jhd1313m1_custom_char_t data);
char *data);
/**
* Turn the display on.

View File

@ -34,6 +34,7 @@
#pragma once
#include <string>
#include <vector>
#include "jhd1313m1.h"
namespace upm
@ -140,11 +141,11 @@ namespace upm
* Create a custom character
*
* @param charSlot the character slot to write, only 8 are available
* @param charData The character data (8 bytes) making up the character
* @param charData A vector containing 8 bytes making up the character
* @return Result of operation
*/
upm_result_t createChar(uint8_t charSlot,
jhd1313m1_custom_char_t charData);
std::vector<uint8_t> charData);
/**
* Turn the display on

View File

@ -1,9 +1,8 @@
%module jsupm_jhd1313m1
%include "../upm.i"
%include "../carrays_uint8_t.i"
%include "../upm_vectortypes.i"
%include "jhd1313m1.h"
%include "jhd1313m1.hxx"
%include "jhd1313m1.hpp"
%{
#include "jhd1313m1.hxx"
#include "jhd1313m1.hpp"
%}

View File

@ -2,12 +2,11 @@
%include "pyupm_doxy2swig.i"
%module pyupm_jhd1313m1
%include "../upm.i"
%include "../carrays_uint8_t.i"
%include "../upm_vectortypes.i"
%feature("autodoc", "3");
%include "jhd1313m1.h"
%include "jhd1313m1.hxx"
%include "jhd1313m1.hpp"
%{
#include "jhd1313m1.hxx"
#include "jhd1313m1.hpp"
%}

View File

@ -1,5 +1,5 @@
set (libname "i2clcd")
set (libdescription "LCD and OLED Display Library")
set (module_src lcd.cxx lcm1602.cxx jhd1313m1.cxx ssd1308.cxx eboled.cxx ssd1327.cxx sainsmartks.cxx ssd1306.cxx)
set (module_hpp lcd.hpp lcm1602.hpp jhd1313m1.hpp ssd1308.hpp eboled.hpp ssd1327.hpp ssd.hpp sainsmartks.hpp ssd1306.hpp)
set (libdescription "OLED Display Library")
set (module_src lcd.cxx ssd1308.cxx eboled.cxx ssd1327.cxx ssd1306.cxx)
set (module_hpp lcd.hpp ssd1308.hpp eboled.hpp ssd1327.hpp ssd.hpp ssd1306.hpp)
upm_module_init(mraa)

View File

@ -29,9 +29,6 @@
#include "ssd1308.hpp"
#include "ssd1306.hpp"
#include "eboled.hpp"
#include "lcm1602.hpp"
#include "jhd1313m1.hpp"
#include "sainsmartks.hpp"
%}
%include "lcd.hpp"
@ -40,9 +37,6 @@
%include "ssd1308.hpp"
%include "ssd1306.hpp"
%include "eboled.hpp"
%include "lcm1602.hpp"
%include "jhd1313m1.hpp"
%include "sainsmartks.hpp"
%pragma(java) jniclasscode=%{
static {

View File

@ -1,142 +0,0 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Contributions: Jon Trulson <jtrulson@ics.com>
*
* 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 <stdexcept>
#include <unistd.h>
#include "lcd_private.hpp"
#include "hd44780_bits.hpp"
#include "jhd1313m1.hpp"
using namespace upm;
Jhd1313m1::Jhd1313m1(int bus, int lcdAddress, int rgbAddress)
: Lcm1602(bus, lcdAddress, false), m_i2c_lcd_rgb(bus)
{
m_rgb_address = rgbAddress;
m_name = "Jhd1313m1";
mraa::Result ret = m_i2c_lcd_rgb.address(m_rgb_address);
if (ret != mraa::SUCCESS) {
throw std::invalid_argument(std::string(__FUNCTION__) +
": I2c.address() failed");
}
/* HD44780 requires writing three times to initialize or reset
according to the hardware errata on page 45 figure 23 of
the Hitachi HD44780 datasheet */
/* First try */
usleep(50000);
ret = command(LCD_FUNCTIONSET | LCD_8BITMODE);
/* Second try */
usleep(4500);
ret = command(LCD_FUNCTIONSET | LCD_8BITMODE);
/* Third try */
usleep(150);
ret = command(LCD_FUNCTIONSET | LCD_8BITMODE);
UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the LCD controller");
/* Set 2 row mode and font size */
ret = command(LCD_FUNCTIONSET | LCD_8BITMODE | LCD_2LINE | LCD_5x10DOTS);
UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the LCD controller");
usleep(100);
ret = displayOn();
UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the LCD controller");
usleep(100);
ret = clear();
UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the LCD controller");
usleep(2000);
ret = command(LCD_ENTRYMODESET | LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT);
UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the LCD controller");
ret = setColor(0xFF, 0xFF, 0xFF);
UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the RGB controller");
ret = backlightOn();
UPM_CHECK_MRAA_SUCCESS(ret, "Unable to initialise the RGB controller");
}
Jhd1313m1::~Jhd1313m1()
{
clear();
setColor(0x00, 0x00, 0x00);
}
mraa::Result
Jhd1313m1::setColor(uint8_t r, uint8_t g, uint8_t b)
{
mraa::Result ret;
ret = m_i2c_lcd_rgb.writeReg(0, 0);
UPM_GOTO_ON_MRAA_FAIL(ret, beach);
ret = m_i2c_lcd_rgb.writeReg(1, 0);
UPM_GOTO_ON_MRAA_FAIL(ret, beach);
ret = m_i2c_lcd_rgb.writeReg(0x04, r);
UPM_GOTO_ON_MRAA_FAIL(ret, beach);
ret = m_i2c_lcd_rgb.writeReg(0x03, g);
UPM_GOTO_ON_MRAA_FAIL(ret, beach);
ret = m_i2c_lcd_rgb.writeReg(0x02, b);
beach:
return ret;
}
mraa::Result
Jhd1313m1::backlightOn()
{
return m_i2c_lcd_rgb.writeReg(0x08, 0xAA);
}
mraa::Result
Jhd1313m1::backlightOff()
{
return m_i2c_lcd_rgb.writeReg(0x08, 0x00);
}
mraa::Result
Jhd1313m1::scroll(bool direction)
{
if (direction) {
return scrollDisplayLeft();
} else {
return scrollDisplayRight();
}
}
mraa::Result Jhd1313m1::command(uint8_t cmd)
{
return m_i2c_lcd_control->writeReg(LCD_CMD, cmd);
}
mraa::Result Jhd1313m1::data(uint8_t cmd)
{
return m_i2c_lcd_control->writeReg(LCD_DATA, cmd);
}

View File

@ -1,108 +0,0 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Contributions: Jon Trulson <jtrulson@ics.com>
*
* 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 "lcm1602.hpp"
namespace upm
{
/**
* @library i2clcd
* @sensor jhd1313m1
* @comname RGB Backlight 16x2 LCD Display
* @altname Grove RGB LCD
* @type display
* @man seeed adafruit sparkfun
* @web http://www.seeedstudio.com/depot/Grove-LCD-RGB-Backlight-p-1643.html?cPath=34_36
* @con i2c
* @kit gsk
*
* @brief API for the JHD1313M1 I2C controller for HD44780-based displays with
* an RGB backlight, such as a Grove RGB I2C LCD display
*
* JHD1313M1 has two I2C addreses: one belongs to a controller, very similar
* to the upm::Lcm1602 LCD driver, that controls the HD44780-based display, and the
* other controls only the backlight. This module was tested with the Seeed
* Grove LCD RGB Backlight v2.0 display that requires 5V to operate.
*
* @image html grovergblcd.jpg
* @snippet jhd1313m1-lcd.cxx Interesting
*/
class Jhd1313m1 : public Lcm1602
{
public:
/**
* Jhd1313m1 constructor
*
* @param bus I2C bus to use
* @param address Slave address the LCD is registered on
* @param address Slave address the RGB backlight is registered on
*/
Jhd1313m1(int bus, int lcdAddress = 0x3E, int rgbAddress = 0x62);
/**
* Jhd1313m1 destructor
*/
~Jhd1313m1();
/**
* Makes the LCD scroll text
*
* @param direction True if scrolling to the right
* @return Result of the operation
*/
mraa::Result scroll(bool direction);
/**
* Sets the color of the backlight
* Can be used to change the color even when the backlight is off
*
* @param r 0-255 value for red
* @param g 0-255 value for green
* @param b 0-255 value for blue
* @return Result of the operation
*/
mraa::Result setColor(uint8_t r, uint8_t g, uint8_t b);
/**
* Turns backlight on
*
* @return Result of operation
*/
mraa::Result backlightOn();
/**
* Turns backlight off, background color is saved
*
* @return Result of operation
*/
mraa::Result backlightOff();
protected:
virtual mraa::Result command(uint8_t cmd);
virtual mraa::Result data(uint8_t data);
private:
int m_rgb_address;
mraa::I2c m_i2c_lcd_rgb;
};
}

View File

@ -8,16 +8,6 @@
#include "lcd.hpp"
%}
%include "lcm1602.hpp"
%{
#include "lcm1602.hpp"
%}
%include "jhd1313m1.hpp"
%{
#include "jhd1313m1.hpp"
%}
%include "ssd1327.hpp"
%{
#include "ssd1327.hpp"
@ -33,11 +23,6 @@
#include "eboled.hpp"
%}
%include "sainsmartks.hpp"
%{
#include "sainsmartks.hpp"
%}
%include "ssd1306.hpp"
%{
#include "ssd1306.hpp"

View File

@ -1,474 +0,0 @@
/*
* The MIT License (MIT)
*
* Author: Daniel Mosquera
* Copyright (c) 2013 Daniel Mosquera
*
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Contributions: Jon Trulson <jtrulson@ics.com>
* Sergey Kiselev <sergey.kiselev@intel.com>
*
* 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 <string>
#include <stdexcept>
#include <unistd.h>
#include "hd44780_bits.hpp"
#include "lcm1602.hpp"
using namespace upm;
Lcm1602::Lcm1602(int bus_in, int addr_in, bool isExpander,
uint8_t numColumns, uint8_t numRows) :
m_numColumns(numColumns), m_numRows(numRows),
m_i2c_lcd_control(new mraa::I2c(bus_in)),
m_gpioRS(0), m_gpioEnable(0), m_gpioD0(0),
m_gpioD1(0), m_gpioD2(0), m_gpioD3(0)
{
mraa::Result error = mraa::SUCCESS;
m_name = "Lcm1602 (I2C)";
m_isI2C = true;
m_backlight = LCD_BACKLIGHT;
m_lcd_control_address = addr_in;
error = m_i2c_lcd_control->address(m_lcd_control_address);
if (error != mraa::SUCCESS) {
throw std::invalid_argument(std::string(__FUNCTION__) +
": I2c.address() failed");
return;
}
// default display control
m_displayControl = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
// if we are not dealing with an expander (say via a derived class
// like Jhd1313m1), then we do not want to execute the rest of the
// code below. Rather, the derived class's constructor should
// follow up with any setup required -- we will only initialize
// the I2C context and bail.
if (!isExpander)
return;
usleep(50000);
backlightOn();
usleep(100000);
write4bits(0x03 << 4);
usleep(4500);
write4bits(0x30);
usleep(4500);
write4bits(0x30);
usleep(150);
// Put into 4 bit mode
write4bits(0x20);
m_displayControl = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
// Set numeber of lines
command(LCD_FUNCTIONSET | 0x0f);
command(LCD_DISPLAYCONTROL | m_displayControl);
clear();
// Set entry mode.
m_entryDisplayMode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
command(LCD_ENTRYMODESET | m_entryDisplayMode);
home();
}
Lcm1602::Lcm1602(int rs, int enable, int d0,
int d1, int d2, int d3,
uint8_t numColumns, uint8_t numRows) :
m_numColumns(numColumns), m_numRows(numRows),
m_i2c_lcd_control(0),
m_gpioRS(new mraa::Gpio(rs)), m_gpioEnable(new mraa::Gpio(enable)),
m_gpioD0(new mraa::Gpio(d0)), m_gpioD1(new mraa::Gpio(d1)),
m_gpioD2(new mraa::Gpio(d2)), m_gpioD3(new mraa::Gpio(d3))
{
m_name = "Lcm1602 (4-bit GPIO)";
m_isI2C = false;
m_backlight = LCD_BACKLIGHT;
// setup our gpios
m_gpioRS->dir(mraa::DIR_OUT);
m_gpioEnable->dir(mraa::DIR_OUT);
m_gpioD0->dir(mraa::DIR_OUT);
m_gpioD1->dir(mraa::DIR_OUT);
m_gpioD2->dir(mraa::DIR_OUT);
m_gpioD3->dir(mraa::DIR_OUT);
// set RS and Enable low to begin issuing commands
m_gpioRS->write(0);
m_gpioEnable->write(0);
// wait to stabilize
usleep(100000);
// set 4bit mode
// These steps are adapted from the HD44780 datasheet, figure 24
// try 1
write4bits(0x03);
usleep(4500);
// try 2
write4bits(0x03);
usleep(4500);
// try 3
write4bits(0x03);
usleep(150);
// Finally, put into 4 bit mode
write4bits(0x02);
// Set number of lines
command(LCD_FUNCTIONSET | LCD_2LINE | LCD_4BITMODE | LCD_5x8DOTS);
m_displayControl = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
command(LCD_DISPLAYCONTROL | m_displayControl);
usleep(2000);
clear();
// Set entry mode.
m_entryDisplayMode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
command(LCD_ENTRYMODESET | m_entryDisplayMode);
home();
}
Lcm1602::~Lcm1602()
{
// clean up after ourselves
if (m_isI2C)
{
delete m_i2c_lcd_control;
}
else
{
delete m_gpioRS;
delete m_gpioEnable;
delete m_gpioD0;
delete m_gpioD1;
delete m_gpioD2;
delete m_gpioD3;
}
}
/*
* **************
* virtual area
* **************
*/
mraa::Result
Lcm1602::write(std::string msg)
{
mraa::Result error = mraa::SUCCESS;
for (std::string::size_type i = 0; i < msg.size(); ++i) {
error = data(msg[i]);
}
return error;
}
mraa::Result
Lcm1602::setCursor(int row, int column)
{
column = column % m_numColumns;
uint8_t offset = column;
switch (m_numRows)
{
case 1:
// Single row displays with more than 8 columns usually have their
// DDRAM split in two halves. The first half starts at address 00.
// The second half starts at address 40. E.g. 16x2 DDRAM mapping:
// 00 01 02 03 04 05 06 07 40 41 42 43 44 45 46 47
if (m_numColumns > 8)
{
offset = (column % (m_numColumns / 2)) +
(column / (m_numColumns / 2)) * 0x40;
}
break;
case 2:
// this should work for any display with two rows
// DDRAM mapping:
// 00 .. 27
// 40 .. 67
offset += row * 0x40;
break;
case 4:
if (m_numColumns == 16)
{
// 16x4 display
// DDRAM mapping:
// 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
// 40 41 42 43 43 45 46 47 48 49 4A 4B 4C 4D 4E 4F
// 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
// 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F
int row_addr[] = { 0x00, 0x40, 0x10, 0x50 };
offset += row_addr[row];
}
else
{
// 20x4 display
// DDRAM mapping:
// 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13
// 40 41 42 43 43 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53
// 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27
// 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F 60 61 62 63 64 65 66 67
int row_addr[] = { 0x00, 0x40, 0x14, 0x54 };
offset += row_addr[row];
}
break;
}
return command(LCD_CMD | offset);
}
mraa::Result
Lcm1602::clear()
{
mraa::Result ret;
ret = command(LCD_CLEARDISPLAY);
usleep(2000); // this command takes awhile
return ret;
}
mraa::Result
Lcm1602::home()
{
mraa::Result ret;
ret = command(LCD_RETURNHOME);
usleep(2000); // this command takes awhile
return ret;
}
mraa::Result
Lcm1602::createChar(uint8_t charSlot, uint8_t charData[])
{
mraa::Result error = mraa::SUCCESS;
charSlot &= 0x07; // only have 8 positions we can set
error = command(LCD_SETCGRAMADDR | (charSlot << 3));
if (error == mraa::SUCCESS) {
for (int i = 0; i < 8; i++) {
error = data(charData[i]);
}
}
return error;
}
mraa::Result Lcm1602::displayOn()
{
m_displayControl |= LCD_DISPLAYON;
return command(LCD_DISPLAYCONTROL | m_displayControl);
}
mraa::Result Lcm1602::displayOff()
{
m_displayControl &= ~LCD_DISPLAYON;
return command(LCD_DISPLAYCONTROL | m_displayControl);
}
mraa::Result Lcm1602::cursorOn()
{
m_displayControl |= LCD_CURSORON;
return command(LCD_DISPLAYCONTROL | m_displayControl);
}
mraa::Result Lcm1602::cursorOff()
{
m_displayControl &= ~LCD_CURSORON;
return command(LCD_DISPLAYCONTROL | m_displayControl);
}
mraa::Result Lcm1602::cursorBlinkOn()
{
m_displayControl |= LCD_BLINKON;
return command(LCD_DISPLAYCONTROL | m_displayControl);
}
mraa::Result Lcm1602::cursorBlinkOff()
{
m_displayControl &= ~LCD_BLINKON;
return command(LCD_DISPLAYCONTROL | m_displayControl);
}
mraa::Result Lcm1602::backlightOn()
{
m_backlight = LCD_BACKLIGHT;
return expandWrite(m_backlight);
}
mraa::Result Lcm1602::backlightOff()
{
m_backlight = LCD_NOBACKLIGHT;
return expandWrite(m_backlight);
}
mraa::Result Lcm1602::scrollDisplayLeft()
{
return command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
}
mraa::Result Lcm1602::scrollDisplayRight()
{
return command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
}
mraa::Result Lcm1602::entryLeftToRight()
{
m_entryDisplayMode |= LCD_ENTRYLEFT;
return command(LCD_ENTRYMODESET | m_entryDisplayMode);
}
mraa::Result Lcm1602::entryRightToLeft()
{
m_entryDisplayMode &= ~LCD_ENTRYLEFT;
return command(LCD_ENTRYMODESET | m_entryDisplayMode);
}
mraa::Result Lcm1602::autoscrollOn()
{
m_entryDisplayMode |= LCD_ENTRYSHIFTINCREMENT;
return command(LCD_ENTRYMODESET | m_entryDisplayMode);
}
mraa::Result Lcm1602::autoscrollOff()
{
m_entryDisplayMode &= ~LCD_ENTRYSHIFTINCREMENT;
return command(LCD_ENTRYMODESET | m_entryDisplayMode);
}
mraa::Result Lcm1602::command(uint8_t cmd)
{
return send(cmd, 0);
}
mraa::Result Lcm1602::data(uint8_t cmd)
{
return send(cmd, LCD_RS); // 1
}
/*
* **************
* private area
* **************
*/
mraa::Result
Lcm1602::send(uint8_t value, int mode)
{
mraa::Result ret = mraa::SUCCESS;
uint8_t h;
uint8_t l;
if (m_isI2C)
{
h = value & 0xf0;
l = (value << 4) & 0xf0;
ret = write4bits(h | mode);
ret = write4bits(l | mode);
return ret;
}
// else, gpio (4 bit)
// register select
m_gpioRS->write(mode);
h = value >> 4;
l = value & 0x0f;
ret = write4bits(h);
ret = write4bits(l);
return ret;
}
mraa::Result
Lcm1602::write4bits(uint8_t value)
{
mraa::Result ret = mraa::SUCCESS;
if (m_isI2C)
{
ret = expandWrite(value);
ret = pulseEnable(value);
return ret;
}
// else gpio
ret = m_gpioD0->write( ((value >> 0) & 0x01) );
ret = m_gpioD1->write( ((value >> 1) & 0x01) );
ret = m_gpioD2->write( ((value >> 2) & 0x01) );
ret = m_gpioD3->write( ((value >> 3) & 0x01) );
ret = pulseEnable(value); // value is ignored here for gpio
return ret;
}
mraa::Result
Lcm1602::expandWrite(uint8_t value)
{
// invalid for gpio
if (!m_isI2C)
return mraa::ERROR_INVALID_RESOURCE;
uint8_t buffer = value | m_backlight;
return m_i2c_lcd_control->writeByte(buffer);
}
mraa::Result
Lcm1602::pulseEnable(uint8_t value)
{
mraa::Result ret = mraa::SUCCESS;
if (m_isI2C)
{
ret = expandWrite(value | LCD_EN);
usleep(1);
ret = expandWrite(value & ~LCD_EN);
usleep(50);
return ret;
}
// else gpio
ret = m_gpioEnable->write(0);
usleep(1);
ret = m_gpioEnable->write(1);
usleep(1); // must be > 450ns
ret = m_gpioEnable->write(0);
usleep(100); // must be >37us
return ret;
}

View File

@ -1,285 +0,0 @@
/*
* The MIT License (MIT)
*
* Author: Daniel Mosquera
* Copyright (c) 2013 Daniel Mosquera
*
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Contributions: Jon Trulson <jtrulson@ics.com>
* Sergey Kiselev <sergey.kiselev@intel.com>
*
* Permission is hereby granted, free of uint8_tge, 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/i2c.hpp>
#include <mraa/gpio.hpp>
#include "lcd.hpp"
namespace upm
{
/**
* @library i2clcd
* @sensor lcm1602
* @comname 16x2 and 20x4 LCD Display
* @type display
* @man adafruit sparkfun seeed
* @web https://www.adafruit.com/datasheets/TC1602A-01T.pdf
* @con i2c gpio
*
* @brief API for the LCM1602 I2C controller for HD44780-based displays
*
* This supports all sizes of HD44780 displays, from 16x2 to 4x20. The
* controller has no idea of the actual display hardware, so it lets you write
* farther than you can see. These displays with such controllers are available
* from various manufacturers with different I2C addresses. Adafruit*
* TC1602A-01T seems to be a well-documented example. The driver also supports
* parallel GPIO connections directly to the HD44780 in case you are not using
* an I2C expander/backpack.
*
* @image html lcm1602.jpeg
* Example for LCM1602 displays that use the I2C bus
* @snippet lcm1602-i2c.cxx Interesting
* Code sample for GPIO based LCM1602 displays
* @snippet lcm1602-parallel.cxx Interesting
*/
class Lcm1602 : public LCD
{
public:
/**
* Lcm1602 constructor; calls libmraa initialisation functions
*
* @param bus I2C bus to use. Default 0 (autodetect).
* @param address Slave address the LCD is registered on. Default 0x27
* @param isExpander True if we are dealing with an I2C expander,
* false otherwise. Default is true.
* @param numColumns Number of columns the display has. Default 16.
* @param numRows Number of rows the display has. Default 2.
*/
Lcm1602(int bus = 0, int address = 0x27, bool isExpander=true,
uint8_t numColumns = 16, uint8_t numRows = 2);
/**
* Lcm1602 alternate constructor, used for GPIO based HD44780
* controllers supporting RS, Enable, and 4 data pins in 4-bit
* mode.
*
* @param rs Register select pin
* @param enable Enable pin
* @param d0 Data 0 pin
* @param d1 Data 1 pin
* @param d2 Data 2 pin
* @param d3 Data 3 pin
* @param numColumns Number of columns the display has. Default 16.
* @param numRows Number of rows the display has. Default 2.
*/
Lcm1602(int rs, int enable,
int d0, int d1, int d2, int d3,
uint8_t numColumns = 16, uint8_t numRows = 2);
/**
* Lcm1602 destructor
*/
~Lcm1602();
/**
* Writes a string to the LCD
*
* @param msg std::string to write to the display; note: only ASCII
* characters are supported
* @return Result of the operation
*/
mraa::Result write(std::string msg);
/**
* Sets the cursor to specified coordinates
*
* @param row Row to set the cursor to
* @param column Column to set the cursor to
* @return Result of the operation
*/
mraa::Result setCursor(int row, int column);
/**
* Clears the display of all characters
*
* @return Result of the operation
*/
mraa::Result clear();
/**
* Returns to the original coordinates (0,0)
*
* @return Result of the operation
*/
mraa::Result home();
/**
* Create a custom character
*
* @param charSlot the character slot to write, only 8 are available
* @param charData The character data (8 bytes) making up the character
* @return Result of operation
*/
mraa::Result createChar(uint8_t charSlot, uint8_t charData[]);
/**
* Turn the display on
*
* @return Result of operation
*/
mraa::Result displayOn();
/**
* Turn the display off
*
* @return Result of operation
*/
mraa::Result displayOff();
/**
* Turn the cursor on
*
* @return Result of operation
*/
mraa::Result cursorOn();
/**
* Turn the cursor off
*
* @return Result of operation
*/
mraa::Result cursorOff();
/**
* Turn cursor blink on
*
* @return Result of operation
*/
mraa::Result cursorBlinkOn();
/**
* Turn cursor blink off
*
* @return Result of operation
*/
mraa::Result cursorBlinkOff();
/**
* Turn backlight on
*
* @return Result of operation
*/
mraa::Result backlightOn();
/**
* Turn backlight off
*
* @return Result of operation
*/
mraa::Result backlightOff();
/**
* Scroll the display left, without changing the character RAM
*
* @return Result of operation
*/
mraa::Result scrollDisplayLeft();
/**
* Scroll the display right, without changing the character RAM
*
* @return Result of operation
*/
mraa::Result scrollDisplayRight();
/**
* set the entry mode so that characters are added left to right
*
* @return Result of operation
*/
mraa::Result entryLeftToRight();
/**
* set the entry mode so that characters are added right to left
*
* @return Result of operation
*/
mraa::Result entryRightToLeft();
/**
* Right justify text entered from the cursor
*
* @return Result of operation
*/
mraa::Result autoscrollOn();
/**
* Left justify text entered from the cursor
*
* @return Result of operation
*/
mraa::Result autoscrollOff();
protected:
mraa::Result send(uint8_t value, int mode);
mraa::Result write4bits(uint8_t value);
mraa::Result expandWrite(uint8_t value);
mraa::Result pulseEnable(uint8_t value);
uint8_t m_displayControl;
uint8_t m_entryDisplayMode;
// Display size
uint8_t m_numColumns;
uint8_t m_numRows;
mraa::I2c* m_i2c_lcd_control;
// gpio operation
mraa::Gpio* m_gpioRS;
mraa::Gpio* m_gpioEnable;
mraa::Gpio* m_gpioD0;
mraa::Gpio* m_gpioD1;
mraa::Gpio* m_gpioD2;
mraa::Gpio* m_gpioD3;
// Backlight
uint8_t m_backlight;
// Add a command() and data() virtual member functions, with a
// default implementation in lcm1602. This is expected to be
// implemented by derived classes with different needs (Jhd1313m1,
// for example).
virtual mraa::Result command(uint8_t cmd);
virtual mraa::Result data(uint8_t data);
int m_lcd_control_address;
private:
// true if using i2c, false otherwise (gpio)
bool m_isI2C;
};
}

View File

@ -12,16 +12,6 @@
#include "lcd.hpp"
%}
%include "lcm1602.hpp"
%{
#include "lcm1602.hpp"
%}
%include "jhd1313m1.hpp"
%{
#include "jhd1313m1.hpp"
%}
%include "ssd1327.hpp"
%{
#include "ssd1327.hpp"
@ -37,11 +27,6 @@
#include "eboled.hpp"
%}
%include "sainsmartks.hpp"
%{
#include "sainsmartks.hpp"
%}
%include "ssd1306.hpp"
%{
#include "ssd1306.hpp"

View File

@ -1,48 +0,0 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2015 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 "sainsmartks.hpp"
using namespace upm;
SAINSMARTKS::SAINSMARTKS(int rs, int enable,
int d0, int d1, int d2, int d3,
int keypad)
: Lcm1602(rs, enable, d0, d1, d2, d3),
m_aioKeypad(keypad)
{
m_name = "Sainsmart LCD Keypad Shield";
}
SAINSMARTKS::~SAINSMARTKS()
{
}
float SAINSMARTKS::getRawKeyValue()
{
return m_aioKeypad.readFloat();
}

View File

@ -1,92 +0,0 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2015 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.hpp>
#include "lcm1602.hpp"
namespace upm
{
/**
* @library i2clcd
* @sensor sainsmartks
* @comname LCD Keypad Shield
* @type display
* @man sainsmart dfrobot sparkfun
* @web http://www.sainsmart.com/sainsmart-1602-lcd-keypad-shield-for-arduino-duemilanove-uno-mega2560-mega1280.html
* @web http://www.dfrobot.com/index.php?route=product/product&product_id=51
* @web https://www.sparkfun.com/products/13293
* @con gpio analog
*
* @brief API for Sainsmart LCD Keypad Shield
*
* The Sainsmart LCD Keypad Shield uses 6 digital outputs and 1 analog input
* (for the keypad). The outputs are used to drive an attached LCM1602 LCD
* controller. This driver should also be compatible with the similar LCD
* keypad shields from DFRobot and Sparkfun.
*
* @image html keypadlcd.jpg
* @snippet sainsmartks.cxx Interesting
*/
class SAINSMARTKS : public Lcm1602
{
public:
/**
* SAINSMARTKS constructor
*
* As this is a shield, you will not likely have any choice over
* the pins that are used. For this reason, we provide defaults
* for all of them -- of course they can be changed if your device
* is different.
*
* @param rs register select pin
* @param enable enable pin
* @param d0 data 0 pin
* @param d1 data 1 pin
* @param d2 data 2 pin
* @param d3 data 3 pin
* @param keypad analog pin of the keypad
*/
SAINSMARTKS(int rs=8, int enable=9,
int d0=4, int d1=5, int d2=6, int d3=7,
int keypad=0);
/**
* SAINSMARTKS destructor
*/
~SAINSMARTKS();
/**
* returns the floating point representation of the key that is
* being pushed. Each key produces a different value between 0.0
* and 1.0, and only one key can be read at a time.
*
* @return the floating point value representing a key
*/
float getRawKeyValue();
private:
mraa::Aio m_aioKeypad;
};
}

View File

@ -2,8 +2,7 @@ upm_mixed_module_init (NAME lcm1602
DESCRIPTION "LCD Display Driver for the LCM1602 Controller for HD44780-based Displays"
C_HDR lcm1602.h
C_SRC lcm1602.c
CPP_HDR lcm1602.hxx
CPP_HDR lcm1602.hpp
CPP_SRC lcm1602.cxx
# FTI_SRC lcm1602_fti.c
CPP_WRAPS_C
REQUIRES mraa)

View File

@ -1,32 +1,11 @@
%module javaupm_lcm1602
%include "../upm.i"
%include "stdint.i"
%include "../upm_vectortypes.i"
%include "typemaps.i"
%include "arrays_java.i";
%apply signed char[] {uint8_t []};
%ignore BasicFont;
%typemap(jni) (uint8_t *data, int bytes) "jbyteArray";
%typemap(jtype) (uint8_t *data, int bytes) "byte[]";
%typemap(jstype) (uint8_t *data, int bytes) "byte[]";
%typemap(javain) (uint8_t *data, int bytes) "$javainput";
%typemap(in) (uint8_t *data, int bytes) {
$1 = (uint8_t *) JCALL2(GetByteArrayElements, jenv, $input, NULL);
$2 = JCALL1(GetArrayLength, jenv, $input);
}
%typemap(freearg) (uint8_t *data, int bytes) {
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, 0);
}
%include "lcm1602.h"
%include "lcm1602.hxx"
%include "lcm1602.hpp"
%{
#include "lcm1602.hxx"
#include "lcm1602.hpp"
%}
%pragma(java) jniclasscode=%{

View File

@ -1,9 +1,8 @@
%module jsupm_lcm1602
%include "../upm.i"
%include "../carrays_uint8_t.i"
%include "../upm_vectortypes.i"
%include "lcm1602.h"
%include "lcm1602.hxx"
%include "lcm1602.hpp"
%{
#include "lcm1602.hxx"
#include "lcm1602.hpp"
%}

View File

@ -377,7 +377,7 @@ upm_result_t lcm1602_home(const lcm1602_context dev)
upm_result_t lcm1602_create_char(const lcm1602_context dev,
unsigned int slot,
lcm1602_custom_char_t data)
char *data)
{
assert(dev != NULL);

View File

@ -35,7 +35,7 @@
#include <stdexcept>
#include <unistd.h>
#include "lcm1602.hxx"
#include "lcm1602.hpp"
using namespace upm;
@ -86,9 +86,9 @@ upm_result_t Lcm1602::home()
}
upm_result_t Lcm1602::createChar(uint8_t charSlot,
lcm1602_custom_char_t charData)
std::vector<uint8_t> charData)
{
return lcm1602_create_char(m_lcm1602, charSlot, charData);
return lcm1602_create_char(m_lcm1602, charSlot, (char *)charData.data());
}
upm_result_t Lcm1602::displayOn()

View File

@ -81,11 +81,6 @@ extern "C" {
uint8_t backlight;
} *lcm1602_context;
/**
* Custom character.
*/
typedef char lcm1602_custom_char_t[8];
/**
* LCM1602 I2C initialization. This is used for those devices
* using an I2C expander, or other I2C interface. If you are
@ -181,7 +176,7 @@ extern "C" {
*/
upm_result_t lcm1602_create_char(const lcm1602_context dev,
unsigned int slot,
lcm1602_custom_char_t data);
char *data);
/**
* Turn the display on.

View File

@ -34,6 +34,7 @@
#pragma once
#include <string>
#include <vector>
#include "lcm1602.h"
namespace upm
@ -144,11 +145,11 @@ namespace upm
* Create a custom character
*
* @param charSlot the character slot to write, only 8 are available
* @param charData The character data (8 bytes) making up the character
* @param charData A vector containing 8 bytes making up the character
* @return Result of operation
*/
upm_result_t createChar(uint8_t charSlot,
lcm1602_custom_char_t charData);
std::vector<uint8_t> charData);
/**
* Turn the display on

View File

@ -2,12 +2,11 @@
%include "pyupm_doxy2swig.i"
%module pyupm_lcm1602
%include "../upm.i"
%include "../carrays_uint8_t.i"
%include "../upm_vectortypes.i"
%feature("autodoc", "3");
%include "lcm1602.h"
%include "lcm1602.hxx"
%include "lcm1602.hpp"
%{
#include "lcm1602.hxx"
#include "lcm1602.hpp"
%}