mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 09:21:12 +03:00
lcdks: renamed from sainsmartks, added backlight support
The sainsmartks driver has been reimplemented in it's own, new C/C++ library: lcdks (LCD Keypad Shield). In addition, support for an optional backlight GPIO was added. This was tested with the SainsmartKS and DFRobot LCD Keypad Shields. Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
@ -332,6 +332,7 @@ add_example (max30100)
|
||||
add_example (sensortemplate)
|
||||
add_example (p9813)
|
||||
add_example (abpdrrt005pg2a5)
|
||||
add_example (lcdks)
|
||||
|
||||
# These are special cases where you specify example binary, source file and module(s)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src)
|
||||
@ -343,7 +344,6 @@ 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 (eboled-example-cxx eboled.cxx lcd)
|
||||
add_custom_example (mpu60x0-example-cxx mpu60x0.cxx mpu9150)
|
||||
add_custom_example (ak8975-example-cxx ak8975.cxx mpu9150)
|
||||
|
@ -1,6 +1,8 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* The MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@ -26,41 +28,46 @@
|
||||
#include <signal.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "sainsmartks.hpp"
|
||||
#include "lcdks.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// use default pins
|
||||
upm::SAINSMARTKS* lcd = new upm::SAINSMARTKS();
|
||||
lcd->setCursor(0,0);
|
||||
lcd->write("Sainsmart KS");
|
||||
lcd->setCursor(1,2);
|
||||
lcd->write("Hello World");
|
||||
|
||||
// output current key value every second.
|
||||
while (shouldRun)
|
||||
{
|
||||
cout << "Button value: " << lcd->getRawKeyValue() << endl;
|
||||
sleep(1);
|
||||
}
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
delete lcd;
|
||||
|
||||
return 0;
|
||||
// Instantiate a LCDKS (LCD Keypad Shield) using default pins
|
||||
|
||||
// NOTE: The default pins do not include support for a gpio
|
||||
// controlled backlight. If you need one, you will need to specify
|
||||
// all neccessary pins to the constructor.
|
||||
upm::LCDKS* lcd = new upm::LCDKS();
|
||||
|
||||
lcd->setCursor(0,0);
|
||||
lcd->write("LCDKS driver");
|
||||
lcd->setCursor(1,2);
|
||||
lcd->write("Hello World");
|
||||
|
||||
// output current key value every second.
|
||||
while (shouldRun)
|
||||
{
|
||||
cout << "Button value: " << lcd->getKeyValue() << endl;
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
delete lcd;
|
||||
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
@ -152,6 +152,7 @@ add_example (nunchuck)
|
||||
add_example (bno055)
|
||||
add_example (bmp280)
|
||||
add_example (abpdrrt005pg2a5)
|
||||
add_example (lcdks)
|
||||
|
||||
# Custom examples
|
||||
add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps)
|
||||
|
89
examples/c/lcdks.c
Normal file
89
examples/c/lcdks.c
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* The MIT License
|
||||
*
|
||||
* 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 <signal.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "upm_utilities.h"
|
||||
#include "lcdks.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a LCDKS (LCD Keypad Shield) using default pins
|
||||
|
||||
// LCD connection:
|
||||
// LCD RS pin to digital pin 8
|
||||
// LCD Enable pin to digital pin 9
|
||||
// LCD D4 pin to digital pin 4
|
||||
// LCD D5 pin to digital pin 5
|
||||
// LCD D6 pin to digital pin 6
|
||||
// LCD D7 pin to digital pin 7
|
||||
// Keypad analog pin 0
|
||||
// Backlight GPIO -1 (disabled)
|
||||
|
||||
// NOTE: The default pins do not include support for a gpio
|
||||
// controlled backlight. If you need one, specify the correct pin
|
||||
// as the last argument instead of -1.
|
||||
lcdks_context lcd = lcdks_init(8, 9, 4, 5, 6, 7, 0, -1);
|
||||
|
||||
if (!lcd)
|
||||
{
|
||||
printf("lcdks_init() failed.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
lcdks_set_cursor(lcd, 0, 0);
|
||||
lcdks_write(lcd, "LCDKS driver", 12);
|
||||
lcdks_set_cursor(lcd, 1, 2);
|
||||
lcdks_write(lcd, "Hello World", 11);
|
||||
|
||||
// output current key value every second.
|
||||
while (shouldRun)
|
||||
{
|
||||
printf("Button value: %f\n", lcdks_get_key_value(lcd));
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
lcdks_close(lcd);
|
||||
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* The MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@ -22,29 +24,32 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var sainsmartObj = require('jsupm_i2clcd');
|
||||
var lcdksObj = require('jsupm_lcdks');
|
||||
|
||||
// Instantiate a Sainsmart LCD Keypad Shield using default pins
|
||||
var lcd = new sainsmartObj.SAINSMARTKS();
|
||||
// Instantiate a LCDKS (LCD Keypad Shield) using default pins
|
||||
|
||||
// NOTE: The default pins do not include support for a gpio
|
||||
// controlled backlight. If you need one, you will need to specify
|
||||
// all neccessary pins to the constructor.
|
||||
var lcd = new lcdksObj.LCDKS();
|
||||
|
||||
lcd.setCursor(0,0);
|
||||
lcd.write("Sainsmart KS");
|
||||
lcd.write("LCDKS driver");
|
||||
lcd.setCursor(1,2);
|
||||
lcd.write("Hello World");
|
||||
|
||||
// output current key value every second.
|
||||
setInterval(function()
|
||||
{
|
||||
console.log("Button value: " + lcd.getRawKeyValue());
|
||||
console.log("Button value: " + lcd.getKeyValue());
|
||||
}, 1000);
|
||||
|
||||
// exit on ^C
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
lcd = null;
|
||||
sainsmartObj.cleanUp();
|
||||
sainsmartObj = null;
|
||||
lcdksObj.cleanUp();
|
||||
lcdksObj = null;
|
||||
console.log("Exiting.");
|
||||
process.exit(0);
|
||||
});
|
||||
|
@ -1,6 +1,8 @@
|
||||
#!/usr/bin/python
|
||||
# Author: Jon Trulson <jtrulson@ics.com>
|
||||
# Copyright (c) 2015 Intel Corporation.
|
||||
# Copyright (c) 2017 Intel Corporation.
|
||||
#
|
||||
# The MIT License
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
@ -23,7 +25,7 @@
|
||||
|
||||
from __future__ import print_function
|
||||
import time, sys, signal, atexit
|
||||
from upm import pyupm_i2clcd as sainsmartObj
|
||||
from upm import pyupm_lcdks as lcdksObj
|
||||
|
||||
def main():
|
||||
## Exit handlers ##
|
||||
@ -32,7 +34,6 @@ def main():
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit,
|
||||
# including functions from ringCoder
|
||||
def exitHandler():
|
||||
print("Exiting")
|
||||
sys.exit(0)
|
||||
@ -41,17 +42,21 @@ def main():
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
# Instantiate a Sainsmart LCD Keypad Shield using default pins
|
||||
lcd = sainsmartObj.SAINSMARTKS()
|
||||
# Instantiate a LCDKS (LCD Keypad Shield) using default pins
|
||||
|
||||
# NOTE: The default pins do not include support for a gpio
|
||||
# controlled backlight. If you need one, you will need to specify
|
||||
# all neccessary pins to the constructor.
|
||||
lcd = lcdksObj.LCDKS()
|
||||
|
||||
lcd.setCursor(0,0)
|
||||
lcd.write("Sainsmart KS")
|
||||
lcd.write("LCDKS driver")
|
||||
lcd.setCursor(1,2)
|
||||
lcd.write("Hello World")
|
||||
|
||||
# output current key value every second.
|
||||
while(1):
|
||||
print("Button value: ", lcd.getRawKeyValue())
|
||||
print("Button value: ", lcd.getKeyValue())
|
||||
time.sleep(1)
|
||||
|
||||
if __name__ == '__main__':
|
Reference in New Issue
Block a user