Permalink
Browse files

Merge pull request #14 from davemckelvie/feature/led-matrix-display

Feature/led matrix display
  • Loading branch information...
davemckelvie committed Sep 14, 2017
2 parents e13d638 + d3baedb commit 6a52911b31f42992a20ba63f441f8ef102ab96c0
View
@@ -21,12 +21,12 @@ ext {
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
minSdkVersion 24
targetSdkVersion 25
targetSdkVersion 26
versionCode 1
versionName "1.0"
@@ -46,11 +46,11 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:appcompat-v7:26.0.2'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
provided 'com.google.android.things:androidthings:0.1-devpreview'
provided 'com.google.android.things:androidthings:0.5.1-devpreview'
}
apply from: 'install.gradle'
@@ -107,7 +107,8 @@ private void initButtonMask() {
*/
private void initInputDriver() {
inputDriver = InputDriver.builder(InputDevice.SOURCE_CLASS_BUTTON)
InputDriver.Builder builder = new InputDriver.Builder(InputDevice.SOURCE_CLASS_BUTTON);
inputDriver = builder
.setName(TAG)
.setVersion(DRIVER_VERSION)
.setKeys(toIntArray(buttonMap.values().toArray(new Integer[buttonMap.size()])))
@@ -1,23 +1,11 @@
/*
* Copyright 2016 Dave McKelvie <www.android.geek.nz>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nz.geek.android.things.drivers.lcd;
package nz.geek.android.things.drivers.display;
public interface Lcd {
/**
* Interface for a character display
*/
public interface CharacterDisplay {
/**
* Connect to the LCD display. This initialises the display.
* Connect to the display. This initialises the display.
*/
void connect();
@@ -26,6 +14,12 @@
*/
void disconnect();
/**
* Enable the display
* @param enable true to enable, false to disable
*/
void enable(boolean enable);
/**
* Print a message to the display starting at the given display line
* @param line the line to print the message [1:height]
@@ -34,12 +28,44 @@
void print(int line, String message);
/**
* Switch on and off the LCD backlight
* Clear a given line of the display
* @param line line to clear [1:height]
*/
void clearLine(int line);
/**
* clear the display. Fills DDRAM with space character (0x20)
*/
void clearDisplay();
/**
* Switch on and off the backlight
* @param enable true to enable
*/
void enableBackLight(boolean enable);
/**
* Does the display have a back light?
* @return true if it does
*/
boolean hasBackLight();
/**
* Get the number of display character rows
* @return rows
*/
int getWidth();
/**
* Get the number of display character columns
* @return columns
*/
int getHeight();
/**
* OK, it's a bit of a stretch to put this method into the interface,
* it's not applicable to LED displays (or is it?).
*
* write a bit pattern to CGRAM to generate a custom character
*
* <pre>
@@ -56,33 +82,19 @@
* @param address the CGRAM address to write the bit pattern to.
* @param pattern the bit pattern to write
*/
void setCgRam(int address, byte[] pattern);
void setCustomCharacter(int address, byte[] pattern);
/**
* Clear a given line of the LCD display
* @param line line to clear [1:height]
* Variant of {@link #setCustomCharacter(int, byte[])} that returns the address used
* to store the custom character
* @param pattern bit pattern of the custom character
* @return the address used
*/
void clearLine(int line);
/**
* clear the display. Fills DDRAM with space character (0x20)
*/
void clearDisplay();
/**
* Get the number of LCD character rows
* @return LCD rows
*/
int getWidth();
/**
* Get the number of LCD character columns
* @return LCD columns
*/
int getHeight();
int setCustomCharacter(byte[] pattern);
/**
* Load bargraph characters into CGRAM
*/
void initBarGraph();
}
@@ -34,13 +34,11 @@ protected BaseI2cDevice(I2cDevice device) {
protected static String getBus() {
PeripheralManagerService peripheralManagerService = new PeripheralManagerService();
List<String> deviceList = peripheralManagerService.getI2cBusList();
String bus;
if (deviceList.isEmpty()) {
bus = "I2C1";
return "I2C1";
} else {
bus = deviceList.get(0);
return deviceList.get(0);
}
return bus;
}
@Nullable
@@ -268,7 +268,8 @@ public void registerSensorDriver() {
}
public UserSensor getUserSensor() {
return UserSensor.builder()
UserSensor.Builder builder = new UserSensor.Builder();
return builder
.setName("tcs3472")
.setVendor("TAOS")
.setType(Sensor.TYPE_LIGHT)
@@ -17,11 +17,12 @@
import com.google.android.things.pio.PeripheralManagerService;
import nz.geek.android.things.drivers.display.CharacterDisplay;
import nz.geek.android.things.drivers.i2c.Pcf8574;
import static nz.geek.android.things.drivers.i2c.Pcf8574.BV;
public class I2cSerialCharLcd implements Lcd {
public class I2cSerialCharLcd implements CharacterDisplay {
private static final int SPACE = 0x20;
@@ -168,6 +169,11 @@ public void disconnect() {
}
}
@Override
public void enable(boolean enable) {
// TODO: 13/09/17
}
/**
* print a message to the display
* @param line the line number to print to
@@ -288,6 +294,11 @@ public void enableBackLight(boolean enable) {
}
}
@Override
public boolean hasBackLight() {
return hasBackLight;
}
private void setCgRamPattern(int address, byte[] pattern) {
writeCommand(LCD_SET_CG_RAM | address); // set CGRAM address
for (byte aPattern : pattern) {
@@ -296,7 +307,7 @@ private void setCgRamPattern(int address, byte[] pattern) {
}
@Override
public void setCgRam(int address, byte[] pattern) {
public void setCustomCharacter(int address, byte[] pattern) {
setCgRamPattern(address, pattern);
if (isDoubleDisplay()) {
switchDisplay(2);
@@ -305,6 +316,12 @@ public void setCgRam(int address, byte[] pattern) {
}
}
@Override
public int setCustomCharacter(byte[] pattern) {
// TODO: 12/09/17
return 0;
}
@Override
public void clearLine(int line) {
writeCommand(lineToAddress(line));
@@ -330,12 +347,12 @@ public int getHeight() {
@Override
public void initBarGraph() {
setCgRam(0x00, new byte[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00});
setCgRam(0x08, new byte[]{0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00});
setCgRam(0x10, new byte[]{0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00});
setCgRam(0x18, new byte[]{0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x00});
setCgRam(0x20, new byte[]{0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x00});
setCgRam(0x28, new byte[]{0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00});
setCustomCharacter(0x00, new byte[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00});
setCustomCharacter(0x08, new byte[]{0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00});
setCustomCharacter(0x10, new byte[]{0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00});
setCustomCharacter(0x18, new byte[]{0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x00});
setCustomCharacter(0x20, new byte[]{0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x00});
setCustomCharacter(0x28, new byte[]{0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00});
}
public static I2cSerialCharLcdBuilder builder(int width, int height) {
Oops, something went wrong.

0 comments on commit 6a52911

Please sign in to comment.