Merge pull request #16 from bkosciow/develop

Develop
This commit is contained in:
Bartosz 2017-07-09 14:35:09 +02:00 committed by GitHub
commit c576a56e56
19 changed files with 131 additions and 68 deletions

View File

@ -19,7 +19,6 @@ class Chip(metaclass=abc.ABCMeta):
"""get width""" """get width"""
if self.rotation == 0 or self.rotation == 180: if self.rotation == 0 or self.rotation == 180:
return self._width return self._width
else:
return self._height return self._height
@property @property
@ -27,7 +26,6 @@ class Chip(metaclass=abc.ABCMeta):
"""get height""" """get height"""
if self.rotation == 0 or self.rotation == 180: if self.rotation == 0 or self.rotation == 180:
return self._height return self._height
else:
return self._width return self._width
@abc.abstractmethod @abc.abstractmethod

View File

@ -3,6 +3,7 @@ import abc
class Font(metaclass=abc.ABCMeta): class Font(metaclass=abc.ABCMeta):
"""Font abstract"""
font = [] # Dictionary with hex that describe each char font = [] # Dictionary with hex that describe each char
size = (0, 0) size = (0, 0)
@ -12,8 +13,3 @@ class Font(metaclass=abc.ABCMeta):
def get(self, letter): def get(self, letter):
"""return array with letter""" """return array with letter"""
return self.font[ord(letter)] return self.font[ord(letter)]
@property
def size(self):
"""get font size"""
return self.size

View File

@ -1,12 +1,13 @@
"""Touch panel interface""" """Touch panel interface"""
import spidev # pylint: disable=I0011,F0401
import abc import abc
import RPi.GPIO import spidev # pylint: disable=I0011,F0401
import RPi.GPIO # pylint: disable=I0011,F0401
class Touch(metaclass=abc.ABCMeta): class Touch(metaclass=abc.ABCMeta):
"""Touch class""" """Touch class"""
def __init__(self, width, height, int_pin=None, callback=None, cs_pin=None, spi=0, speed=1000000): def __init__(self, width, height, int_pin=None,
callback=None, cs_pin=None, spi=0, speed=1000000):
self.width = width self.width = width
self.height = height self.height = height
self.spi = spidev.SpiDev() self.spi = spidev.SpiDev()
@ -30,7 +31,8 @@ class Touch(metaclass=abc.ABCMeta):
if self.int_pin: if self.int_pin:
RPi.GPIO.setup(self.int_pin, RPi.GPIO.IN) RPi.GPIO.setup(self.int_pin, RPi.GPIO.IN)
RPi.GPIO.add_event_detect( RPi.GPIO.add_event_detect(
self.int_pin, RPi.GPIO.BOTH, callback=self._interrupt, bouncetime=self.bouncetime self.int_pin, RPi.GPIO.BOTH, callback=self._interrupt,
bouncetime=self.bouncetime
) )
if self.cs_pin: if self.cs_pin:
RPi.GPIO.setup(self.cs_pin, RPi.GPIO.OUT) RPi.GPIO.setup(self.cs_pin, RPi.GPIO.OUT)
@ -53,7 +55,7 @@ class Touch(metaclass=abc.ABCMeta):
def _calculate_avr(self, points): def _calculate_avr(self, points):
"""calculate x,y by average""" """calculate x,y by average"""
if len(points) == 0: if not points:
return None return None
sum_x = 0 sum_x = 0
sum_y = 0 sum_y = 0
@ -67,5 +69,4 @@ class Touch(metaclass=abc.ABCMeta):
"""checks if point is in range""" """checks if point is in range"""
if self.rotate == 0 or self.rotate == 180: if self.rotate == 0 or self.rotate == 180:
return 0 <= pos_x <= self.width and 0 <= pos_y <= self.height return 0 <= pos_x <= self.width and 0 <= pos_y <= self.height
else:
return 0 <= pos_y <= self.width and 0 <= pos_x <= self.height return 0 <= pos_y <= self.width and 0 <= pos_x <= self.height

View File

@ -1,3 +1,4 @@
"""Page drawing algorithm"""
import abc import abc
from gfxlcd.drawing.pixel import Pixel from gfxlcd.drawing.pixel import Pixel

View File

@ -160,4 +160,3 @@ class Pixel(object):
pos_x + bit, pos_y + row, self.background_color pos_x + bit, pos_y + row, self.background_color
) )
data >>= 1 data >>= 1

View File

@ -1,10 +1,12 @@
import RPi.GPIO """Driver for AD7843 touch panel"""
import RPi.GPIO # pylint: disable=I0011,F0401
from gfxlcd.abstract.touch import Touch from gfxlcd.abstract.touch import Touch
class AD7843(Touch): class AD7843(Touch):
"""AD7843 class""" """AD7843 class"""
def __init__(self, width, height, int_pin=None, callback=None, cs_pin=None, spi=0, speed=1000000): def __init__(self, width, height, int_pin=None,
callback=None, cs_pin=None, spi=0, speed=1000000):
super().__init__(width, height, int_pin, callback, cs_pin, spi, speed) super().__init__(width, height, int_pin, callback, cs_pin, spi, speed)
self.correction = { self.correction = {
'x': 364, 'x': 364,
@ -16,20 +18,32 @@ class AD7843(Touch):
def _get_xy(self, offset_x, offset_y): def _get_xy(self, offset_x, offset_y):
"""correct x and y""" """correct x and y"""
if self.rotate == 0: if self.rotate == 0:
return int((offset_x - self.correction['x']) / self.correction['ratio_x']), \ return int(
int((offset_y - self.correction['y']) / self.correction['ratio_y']) (offset_x - self.correction['x']) / self.correction['ratio_x']
), int(
(offset_y - self.correction['y']) / self.correction['ratio_y']
)
if self.rotate == 90: if self.rotate == 90:
return self.height - int((offset_y - self.correction['y']) / self.correction['ratio_y']), \ return self.height - int(
int((offset_x - self.correction['x']) / self.correction['ratio_x']) (offset_y - self.correction['y']) / self.correction['ratio_y']
), int(
(offset_x - self.correction['x']) / self.correction['ratio_x']
)
if self.rotate == 180: if self.rotate == 180:
return self.width - int((offset_x - self.correction['x']) / self.correction['ratio_x']), \ return self.width - int(
self.height - int((offset_y - self.correction['y']) / self.correction['ratio_y']) (offset_x - self.correction['x']) / self.correction['ratio_x']
), self.height - int(
(offset_y - self.correction['y']) / self.correction['ratio_y']
)
if self.rotate == 270: if self.rotate == 270:
return int((offset_y - self.correction['y']) / self.correction['ratio_y']), \ return int(
self.width - int((offset_x - self.correction['x']) / self.correction['ratio_x']) (offset_y - self.correction['y']) / self.correction['ratio_y']
), self.width - int(
(offset_x - self.correction['x']) / self.correction['ratio_x']
)
def get_position(self): def get_position(self):
"""get touch coords""" """get touch coords"""

View File

@ -6,6 +6,7 @@ from charlcd.abstract.flush_event_interface import FlushEvent
class HD44780(BaseDriver, FlushEvent): class HD44780(BaseDriver, FlushEvent):
"""HD44780 driver for GfxLCD"""
def __init__(self, gfxlcd, lcd_flush=False): def __init__(self, gfxlcd, lcd_flush=False):
"""Class init""" """Class init"""
self.gfxlcd = gfxlcd self.gfxlcd = gfxlcd
@ -39,11 +40,11 @@ class HD44780(BaseDriver, FlushEvent):
if char < 100: if char < 100:
return return
char -= 100 char -= 100
y = char // self.width pos_y = char // self.width
x = char - (y*self.width) pos_x = char - (pos_y * self.width)
self.position = { self.position = {
'x': x * self.font.size[0], 'x': pos_x * self.font.size[0],
'y': y * self.font.size[1] 'y': pos_y * self.font.size[1]
} }
def shutdown(self): def shutdown(self):

View File

@ -1,5 +1,4 @@
"""ILI9486 chip driver""" """ILI9486 chip driver"""
import time
from gfxlcd.drawing.area import Area from gfxlcd.drawing.area import Area
from gfxlcd.abstract.chip import Chip from gfxlcd.abstract.chip import Chip
@ -27,34 +26,34 @@ class ILI9486(Area, Chip):
Chip.init(self) Chip.init(self)
self.driver.reset() self.driver.reset()
#Read Display MADCTL # Read Display MADCTL
self.driver.cmd(0x0b, None) self.driver.cmd(0x0b, None)
self.driver.data(0x00, None) self.driver.data(0x00, None)
self.driver.data(0x00, None) self.driver.data(0x00, None)
#Sleep OUT # Sleep OUT
self.driver.cmd(0x11, None) self.driver.cmd(0x11, None)
#Interface Pixel Format # Interface Pixel Format
self.driver.cmd(0x3a, None) self.driver.cmd(0x3a, None)
self.driver.data(0x55, None) #0x66 5-6-5 / 55 6-6-6 self.driver.data(0x55, None) #0x66 5-6-5 / 55 6-6-6
#Memory Access Control ( # Memory Access Control (
self.driver.cmd(0x36, None) self.driver.cmd(0x36, None)
self.driver.data(self.rotations[self.rotation], None) self.driver.data(self.rotations[self.rotation], None)
#Power Control 3 (For Normal Mode) # Power Control 3 (For Normal Mode)
self.driver.cmd(0xc2, None) self.driver.cmd(0xc2, None)
self.driver.data(0x44, None) self.driver.data(0x44, None)
#VCOM Control # VCOM Control
self.driver.cmd(0xc5, None) self.driver.cmd(0xc5, None)
self.driver.data(0x00, None) self.driver.data(0x00, None)
self.driver.data(0x00, None) self.driver.data(0x00, None)
self.driver.data(0x00, None) self.driver.data(0x00, None)
self.driver.data(0x00, None) self.driver.data(0x00, None)
#PGAMCTRL(Positive Gamma Control) # PGAMCTRL(Positive Gamma Control)
self.driver.cmd(0xe0, None) self.driver.cmd(0xe0, None)
self.driver.data(0x0F, None) self.driver.data(0x0F, None)
self.driver.data(0x1F, None) self.driver.data(0x1F, None)
@ -72,7 +71,7 @@ class ILI9486(Area, Chip):
self.driver.data(0x0D, None) self.driver.data(0x0D, None)
self.driver.data(0x00, None) self.driver.data(0x00, None)
#NGAMCTRL (Negative Gamma Correction) # NGAMCTRL (Negative Gamma Correction)
self.driver.cmd(0xe1, None) self.driver.cmd(0xe1, None)
self.driver.data(0x0F, None) self.driver.data(0x0F, None)
self.driver.data(0x32, None) self.driver.data(0x32, None)
@ -90,7 +89,7 @@ class ILI9486(Area, Chip):
self.driver.data(0x20, None) self.driver.data(0x20, None)
self.driver.data(0x00, None) self.driver.data(0x00, None)
#Digital Gamma Control 1 # Digital Gamma Control 1
self.driver.cmd(0xe2, None) self.driver.cmd(0xe2, None)
self.driver.data(0x0F, None) self.driver.data(0x0F, None)
self.driver.data(0x32, None) self.driver.data(0x32, None)
@ -108,10 +107,10 @@ class ILI9486(Area, Chip):
self.driver.data(0x20, None) self.driver.data(0x20, None)
self.driver.data(0x00, None) self.driver.data(0x00, None)
#Sleep OUT # Sleep OUT
self.driver.cmd(0x11, None) self.driver.cmd(0x11, None)
#Display ON # Display ON
self.driver.cmd(0x29, None) self.driver.cmd(0x29, None)
def _set_area(self, pos_x1, pos_y1, pos_x2, pos_y2): def _set_area(self, pos_x1, pos_y1, pos_x2, pos_y2):

View File

@ -1,6 +1,6 @@
"""SPI communication driver""" """SPI communication driver"""
import time import time
import spidev import spidev # pylint: disable=I0011,F0401
import RPi.GPIO # pylint: disable=I0011,F0401 import RPi.GPIO # pylint: disable=I0011,F0401
from gfxlcd.abstract.driver import Driver from gfxlcd.abstract.driver import Driver
RPi.GPIO.setmode(RPi.GPIO.BCM) RPi.GPIO.setmode(RPi.GPIO.BCM)

View File

@ -3,7 +3,6 @@ from gfxlcd.drawing.page import Page
from gfxlcd.abstract.chip import Chip from gfxlcd.abstract.chip import Chip
class NJU6450(Page, Chip): class NJU6450(Page, Chip):
"""Class for an LCD with NJU6450 chip""" """Class for an LCD with NJU6450 chip"""
def __init__(self, width, height, driver, auto_flush=False): def __init__(self, width, height, driver, auto_flush=False):
@ -81,6 +80,6 @@ class NJU6450(Page, Chip):
pos_x1, pos_y1 = self.width - pos_x1 - 1, self.height - pos_y1 - 1 pos_x1, pos_y1 = self.width - pos_x1 - 1, self.height - pos_y1 - 1
pos_x2, pos_y2 = self.width - pos_x2 - 1, self.height - pos_y2 - 1 pos_x2, pos_y2 = self.width - pos_x2 - 1, self.height - pos_y2 - 1
if self.rotation == 270: if self.rotation == 270:
pos_x1, pos_y1 = pos_y1 , self.width - pos_x1 - 1 pos_x1, pos_y1 = pos_y1, self.width - pos_x1 - 1
pos_x2, pos_y2 = pos_y2 , self.width - pos_x2 - 1 pos_x2, pos_y2 = pos_y2, self.width - pos_x2 - 1
Page.fill_rect(self, pos_x1, pos_y1, pos_x2, pos_y2) Page.fill_rect(self, pos_x1, pos_y1, pos_x2, pos_y2)

View File

@ -1,5 +1,4 @@
"""Area driver """ """Area driver """
import time
from gfxlcd.abstract.driver import Driver from gfxlcd.abstract.driver import Driver
@ -32,7 +31,9 @@ class AreaDriver(Driver):
def data(self, data, enable): def data(self, data, enable):
"""send data to display""" """send data to display"""
app_x, app_y = self.pointer app_x, app_y = self.pointer
self.buffer[self.area['start_x'] + app_x][self.area['start_y'] + app_y] = data self.buffer[
self.area['start_x'] + app_x][self.area['start_y'] + app_y
] = data
self._inc_pointer() self._inc_pointer()
def _inc_pointer(self): def _inc_pointer(self):
@ -47,4 +48,3 @@ class AreaDriver(Driver):
app_y = 0 app_y = 0
self.pointer = (app_x, app_y) self.pointer = (app_x, app_y)

View File

@ -1,4 +1,5 @@
import RPi.GPIO """XPT2046 touch pabel driver"""
import RPi.GPIO # pylint: disable=I0011,F0401
from gfxlcd.abstract.touch import Touch from gfxlcd.abstract.touch import Touch

View File

@ -1 +1,2 @@
__author__ = 'kosci' """font module"""
__author__ = 'Bartosz Kosciow'

View File

@ -1,3 +1,4 @@
"""font 8x8"""
from gfxlcd.abstract.font import Font from gfxlcd.abstract.font import Font

View File

@ -1,6 +1,18 @@
import sys import sys
from nose.tools import assert_equal
sys.path.append("../../") sys.path.append("../../")
from unittest.mock import patch, MagicMock
MockRPi = MagicMock()
MockSpidev = MagicMock()
modules = {
"RPi": MockRPi,
"RPi.GPIO": MockRPi.GPIO,
"spidev": MockSpidev
}
patcher = patch.dict("sys.modules", modules)
patcher.start()
from gfxlcd.driver.ili9325.gpio import GPIO from gfxlcd.driver.ili9325.gpio import GPIO
from gfxlcd.driver.ili9325.ili9325 import ILI9325 from gfxlcd.driver.ili9325.ili9325 import ILI9325
@ -11,3 +23,6 @@ class TestILI9325Drawing(object):
drv.pins['LED'] = 6 drv.pins['LED'] = 6
drv.pins['CS'] = 18 drv.pins['CS'] = 18
ILI9325(240, 320, drv) ILI9325(240, 320, drv)

View File

@ -1,6 +1,18 @@
import sys import sys
from nose.tools import assert_equal
sys.path.append("../../") sys.path.append("../../")
from unittest.mock import patch, MagicMock
MockRPi = MagicMock()
MockSpidev = MagicMock()
modules = {
"RPi": MockRPi,
"RPi.GPIO": MockRPi.GPIO,
"spidev": MockSpidev
}
patcher = patch.dict("sys.modules", modules)
patcher.start()
from gfxlcd.driver.ili9486.spi import SPI from gfxlcd.driver.ili9486.spi import SPI
from gfxlcd.driver.ili9486.ili9486 import ILI9486 from gfxlcd.driver.ili9486.ili9486 import ILI9486

View File

@ -1,6 +1,18 @@
import sys import sys
from nose.tools import assert_equal
sys.path.append("../../") sys.path.append("../../")
from unittest.mock import patch, MagicMock
MockRPi = MagicMock()
MockSpidev = MagicMock()
modules = {
"RPi": MockRPi,
"RPi.GPIO": MockRPi.GPIO,
"spidev": MockSpidev
}
patcher = patch.dict("sys.modules", modules)
patcher.start()
from gfxlcd.driver.nju6450.gpio import GPIO from gfxlcd.driver.nju6450.gpio import GPIO
from gfxlcd.driver.nju6450.nju6450 import NJU6450 from gfxlcd.driver.nju6450.nju6450 import NJU6450

View File

@ -1,6 +1,18 @@
import sys import sys
from nose.tools import assert_equal
sys.path.append("../../") sys.path.append("../../")
from unittest.mock import patch, MagicMock
MockRPi = MagicMock()
MockSpidev = MagicMock()
modules = {
"RPi": MockRPi,
"RPi.GPIO": MockRPi.GPIO,
"spidev": MockSpidev
}
patcher = patch.dict("sys.modules", modules)
patcher.start()
from gfxlcd.driver.ssd1306.spi import SPI from gfxlcd.driver.ssd1306.spi import SPI
from gfxlcd.driver.ssd1306.ssd1306 import SSD1306 from gfxlcd.driver.ssd1306.ssd1306 import SSD1306

View File

@ -9,6 +9,7 @@ deps=
future future
flake8 flake8
pylint pylint
charlcd
whitelist_externals = /bin/bash whitelist_externals = /bin/bash
commands= nosetests --with-xunit --xunit-file=junit-{envname}.xml gfxlcd/tests commands= nosetests --with-xunit --xunit-file=junit-{envname}.xml gfxlcd/tests
rm flake8-{envname}.log -f rm flake8-{envname}.log -f