commit
c576a56e56
@ -19,7 +19,6 @@ class Chip(metaclass=abc.ABCMeta):
|
||||
"""get width"""
|
||||
if self.rotation == 0 or self.rotation == 180:
|
||||
return self._width
|
||||
else:
|
||||
return self._height
|
||||
|
||||
@property
|
||||
@ -27,7 +26,6 @@ class Chip(metaclass=abc.ABCMeta):
|
||||
"""get height"""
|
||||
if self.rotation == 0 or self.rotation == 180:
|
||||
return self._height
|
||||
else:
|
||||
return self._width
|
||||
|
||||
@abc.abstractmethod
|
||||
|
@ -3,6 +3,7 @@ import abc
|
||||
|
||||
|
||||
class Font(metaclass=abc.ABCMeta):
|
||||
"""Font abstract"""
|
||||
font = [] # Dictionary with hex that describe each char
|
||||
size = (0, 0)
|
||||
|
||||
@ -12,8 +13,3 @@ class Font(metaclass=abc.ABCMeta):
|
||||
def get(self, letter):
|
||||
"""return array with letter"""
|
||||
return self.font[ord(letter)]
|
||||
|
||||
@property
|
||||
def size(self):
|
||||
"""get font size"""
|
||||
return self.size
|
||||
|
@ -1,12 +1,13 @@
|
||||
"""Touch panel interface"""
|
||||
import spidev # pylint: disable=I0011,F0401
|
||||
import abc
|
||||
import RPi.GPIO
|
||||
import spidev # pylint: disable=I0011,F0401
|
||||
import RPi.GPIO # pylint: disable=I0011,F0401
|
||||
|
||||
|
||||
class Touch(metaclass=abc.ABCMeta):
|
||||
"""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.height = height
|
||||
self.spi = spidev.SpiDev()
|
||||
@ -30,7 +31,8 @@ class Touch(metaclass=abc.ABCMeta):
|
||||
if self.int_pin:
|
||||
RPi.GPIO.setup(self.int_pin, RPi.GPIO.IN)
|
||||
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:
|
||||
RPi.GPIO.setup(self.cs_pin, RPi.GPIO.OUT)
|
||||
@ -53,7 +55,7 @@ class Touch(metaclass=abc.ABCMeta):
|
||||
|
||||
def _calculate_avr(self, points):
|
||||
"""calculate x,y by average"""
|
||||
if len(points) == 0:
|
||||
if not points:
|
||||
return None
|
||||
sum_x = 0
|
||||
sum_y = 0
|
||||
@ -67,5 +69,4 @@ class Touch(metaclass=abc.ABCMeta):
|
||||
"""checks if point is in range"""
|
||||
if self.rotate == 0 or self.rotate == 180:
|
||||
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
|
||||
|
@ -1,3 +1,4 @@
|
||||
"""Page drawing algorithm"""
|
||||
import abc
|
||||
from gfxlcd.drawing.pixel import Pixel
|
||||
|
||||
|
@ -160,4 +160,3 @@ class Pixel(object):
|
||||
pos_x + bit, pos_y + row, self.background_color
|
||||
)
|
||||
data >>= 1
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
class AD7843(Touch):
|
||||
"""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)
|
||||
self.correction = {
|
||||
'x': 364,
|
||||
@ -16,20 +18,32 @@ class AD7843(Touch):
|
||||
def _get_xy(self, offset_x, offset_y):
|
||||
"""correct x and y"""
|
||||
if self.rotate == 0:
|
||||
return int((offset_x - self.correction['x']) / self.correction['ratio_x']), \
|
||||
int((offset_y - self.correction['y']) / self.correction['ratio_y'])
|
||||
return int(
|
||||
(offset_x - self.correction['x']) / self.correction['ratio_x']
|
||||
), int(
|
||||
(offset_y - self.correction['y']) / self.correction['ratio_y']
|
||||
)
|
||||
|
||||
if self.rotate == 90:
|
||||
return self.height - int((offset_y - self.correction['y']) / self.correction['ratio_y']), \
|
||||
int((offset_x - self.correction['x']) / self.correction['ratio_x'])
|
||||
return self.height - int(
|
||||
(offset_y - self.correction['y']) / self.correction['ratio_y']
|
||||
), int(
|
||||
(offset_x - self.correction['x']) / self.correction['ratio_x']
|
||||
)
|
||||
|
||||
if self.rotate == 180:
|
||||
return self.width - int((offset_x - self.correction['x']) / self.correction['ratio_x']), \
|
||||
self.height - int((offset_y - self.correction['y']) / self.correction['ratio_y'])
|
||||
return self.width - int(
|
||||
(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:
|
||||
return int((offset_y - self.correction['y']) / self.correction['ratio_y']), \
|
||||
self.width - int((offset_x - self.correction['x']) / self.correction['ratio_x'])
|
||||
return int(
|
||||
(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):
|
||||
"""get touch coords"""
|
||||
|
@ -6,6 +6,7 @@ from charlcd.abstract.flush_event_interface import FlushEvent
|
||||
|
||||
|
||||
class HD44780(BaseDriver, FlushEvent):
|
||||
"""HD44780 driver for GfxLCD"""
|
||||
def __init__(self, gfxlcd, lcd_flush=False):
|
||||
"""Class init"""
|
||||
self.gfxlcd = gfxlcd
|
||||
@ -39,11 +40,11 @@ class HD44780(BaseDriver, FlushEvent):
|
||||
if char < 100:
|
||||
return
|
||||
char -= 100
|
||||
y = char // self.width
|
||||
x = char - (y*self.width)
|
||||
pos_y = char // self.width
|
||||
pos_x = char - (pos_y * self.width)
|
||||
self.position = {
|
||||
'x': x * self.font.size[0],
|
||||
'y': y * self.font.size[1]
|
||||
'x': pos_x * self.font.size[0],
|
||||
'y': pos_y * self.font.size[1]
|
||||
}
|
||||
|
||||
def shutdown(self):
|
||||
|
@ -1,5 +1,4 @@
|
||||
"""ILI9486 chip driver"""
|
||||
import time
|
||||
from gfxlcd.drawing.area import Area
|
||||
from gfxlcd.abstract.chip import Chip
|
||||
|
||||
@ -27,34 +26,34 @@ class ILI9486(Area, Chip):
|
||||
Chip.init(self)
|
||||
self.driver.reset()
|
||||
|
||||
#Read Display MADCTL
|
||||
# Read Display MADCTL
|
||||
self.driver.cmd(0x0b, None)
|
||||
self.driver.data(0x00, None)
|
||||
self.driver.data(0x00, None)
|
||||
|
||||
#Sleep OUT
|
||||
# Sleep OUT
|
||||
self.driver.cmd(0x11, None)
|
||||
|
||||
#Interface Pixel Format
|
||||
# Interface Pixel Format
|
||||
self.driver.cmd(0x3a, None)
|
||||
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.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.data(0x44, None)
|
||||
|
||||
#VCOM Control
|
||||
# VCOM Control
|
||||
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)
|
||||
|
||||
#PGAMCTRL(Positive Gamma Control)
|
||||
# PGAMCTRL(Positive Gamma Control)
|
||||
self.driver.cmd(0xe0, None)
|
||||
self.driver.data(0x0F, None)
|
||||
self.driver.data(0x1F, None)
|
||||
@ -72,7 +71,7 @@ class ILI9486(Area, Chip):
|
||||
self.driver.data(0x0D, None)
|
||||
self.driver.data(0x00, None)
|
||||
|
||||
#NGAMCTRL (Negative Gamma Correction)
|
||||
# NGAMCTRL (Negative Gamma Correction)
|
||||
self.driver.cmd(0xe1, None)
|
||||
self.driver.data(0x0F, None)
|
||||
self.driver.data(0x32, None)
|
||||
@ -90,7 +89,7 @@ class ILI9486(Area, Chip):
|
||||
self.driver.data(0x20, None)
|
||||
self.driver.data(0x00, None)
|
||||
|
||||
#Digital Gamma Control 1
|
||||
# Digital Gamma Control 1
|
||||
self.driver.cmd(0xe2, None)
|
||||
self.driver.data(0x0F, None)
|
||||
self.driver.data(0x32, None)
|
||||
@ -108,10 +107,10 @@ class ILI9486(Area, Chip):
|
||||
self.driver.data(0x20, None)
|
||||
self.driver.data(0x00, None)
|
||||
|
||||
#Sleep OUT
|
||||
# Sleep OUT
|
||||
self.driver.cmd(0x11, None)
|
||||
|
||||
#Display ON
|
||||
# Display ON
|
||||
self.driver.cmd(0x29, None)
|
||||
|
||||
def _set_area(self, pos_x1, pos_y1, pos_x2, pos_y2):
|
||||
|
@ -1,6 +1,6 @@
|
||||
"""SPI communication driver"""
|
||||
import time
|
||||
import spidev
|
||||
import spidev # pylint: disable=I0011,F0401
|
||||
import RPi.GPIO # pylint: disable=I0011,F0401
|
||||
from gfxlcd.abstract.driver import Driver
|
||||
RPi.GPIO.setmode(RPi.GPIO.BCM)
|
||||
|
@ -3,7 +3,6 @@ from gfxlcd.drawing.page import Page
|
||||
from gfxlcd.abstract.chip import Chip
|
||||
|
||||
|
||||
|
||||
class NJU6450(Page, Chip):
|
||||
"""Class for an LCD with NJU6450 chip"""
|
||||
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_x2, pos_y2 = self.width - pos_x2 - 1, self.height - pos_y2 - 1
|
||||
if self.rotation == 270:
|
||||
pos_x1, pos_y1 = pos_y1 , self.width - pos_x1 - 1
|
||||
pos_x2, pos_y2 = pos_y2 , self.width - pos_x2 - 1
|
||||
pos_x1, pos_y1 = pos_y1, self.width - pos_x1 - 1
|
||||
pos_x2, pos_y2 = pos_y2, self.width - pos_x2 - 1
|
||||
Page.fill_rect(self, pos_x1, pos_y1, pos_x2, pos_y2)
|
||||
|
@ -1,5 +1,4 @@
|
||||
"""Area driver """
|
||||
import time
|
||||
from gfxlcd.abstract.driver import Driver
|
||||
|
||||
|
||||
@ -32,7 +31,9 @@ class AreaDriver(Driver):
|
||||
def data(self, data, enable):
|
||||
"""send data to display"""
|
||||
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()
|
||||
|
||||
def _inc_pointer(self):
|
||||
@ -47,4 +48,3 @@ class AreaDriver(Driver):
|
||||
app_y = 0
|
||||
|
||||
self.pointer = (app_x, app_y)
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
import RPi.GPIO
|
||||
"""XPT2046 touch pabel driver"""
|
||||
import RPi.GPIO # pylint: disable=I0011,F0401
|
||||
from gfxlcd.abstract.touch import Touch
|
||||
|
||||
|
||||
|
@ -1 +1,2 @@
|
||||
__author__ = 'kosci'
|
||||
"""font module"""
|
||||
__author__ = 'Bartosz Kosciow'
|
||||
|
@ -1,3 +1,4 @@
|
||||
"""font 8x8"""
|
||||
from gfxlcd.abstract.font import Font
|
||||
|
||||
|
||||
|
@ -1,6 +1,18 @@
|
||||
import sys
|
||||
from nose.tools import assert_equal
|
||||
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.ili9325 import ILI9325
|
||||
|
||||
@ -11,3 +23,6 @@ class TestILI9325Drawing(object):
|
||||
drv.pins['LED'] = 6
|
||||
drv.pins['CS'] = 18
|
||||
ILI9325(240, 320, drv)
|
||||
|
||||
|
||||
|
||||
|
@ -1,6 +1,18 @@
|
||||
import sys
|
||||
from nose.tools import assert_equal
|
||||
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.ili9486 import ILI9486
|
||||
|
||||
|
@ -1,6 +1,18 @@
|
||||
import sys
|
||||
from nose.tools import assert_equal
|
||||
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.nju6450 import NJU6450
|
||||
|
||||
|
@ -1,6 +1,18 @@
|
||||
import sys
|
||||
from nose.tools import assert_equal
|
||||
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.ssd1306 import SSD1306
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user