rotate nju
This commit is contained in:
parent
5c7fca57d7
commit
578ae67c44
26
gfxlcd/demos/nju_3.py
Normal file
26
gfxlcd/demos/nju_3.py
Normal file
@ -0,0 +1,26 @@
|
||||
import RPi.GPIO
|
||||
import sys
|
||||
sys.path.append("../../")
|
||||
from gfxlcd.driver.nju6450.gpio import GPIO
|
||||
from gfxlcd.driver.nju6450.nju6450 import NJU6450
|
||||
RPi.GPIO.setmode(RPi.GPIO.BCM)
|
||||
|
||||
lcd = NJU6450(122, 32, GPIO())
|
||||
lcd.rotation = 270
|
||||
lcd.init()
|
||||
lcd.auto_flush = False
|
||||
|
||||
x, y = lcd.width // 2, lcd.height // 2
|
||||
|
||||
lcd.draw_pixel(3,1)
|
||||
lcd.draw_circle(x, y, 15)
|
||||
lcd.draw_circle(x-7, y-5, 3)
|
||||
lcd.draw_circle(x+7, y-5, 3)
|
||||
lcd.draw_arc(x, y, 10, 45, 135)
|
||||
lcd.draw_line(x, y-3, x-3, y+2)
|
||||
lcd.draw_line(x, y-3, x+3, y+2)
|
||||
lcd.draw_arc(x, y, 3, 45, 135)
|
||||
|
||||
lcd.fill_rect(0, 0, 5, 10)
|
||||
|
||||
lcd.flush(True)
|
19
gfxlcd/demos/nju_image_1.py
Normal file
19
gfxlcd/demos/nju_image_1.py
Normal file
@ -0,0 +1,19 @@
|
||||
import RPi.GPIO
|
||||
import sys
|
||||
from PIL import Image
|
||||
sys.path.append("../../")
|
||||
from gfxlcd.driver.nju6450.gpio import GPIO
|
||||
from gfxlcd.driver.nju6450.nju6450 import NJU6450
|
||||
RPi.GPIO.setmode(RPi.GPIO.BCM)
|
||||
|
||||
lcd_nju = NJU6450(122, 32, GPIO())
|
||||
lcd_nju.rotation = 90
|
||||
lcd_nju.init()
|
||||
lcd_nju.auto_flush = False
|
||||
|
||||
image_file = Image.open("assets/20x20.png")
|
||||
lcd_nju.threshold = 0
|
||||
|
||||
lcd_nju.draw_image(10, 0, image_file)
|
||||
|
||||
lcd_nju.flush(True)
|
@ -6,41 +6,6 @@ from gfxlcd.driver.ssd1306.spi import SPI
|
||||
from gfxlcd.driver.ssd1306.ssd1306 import SSD1306
|
||||
RPi.GPIO.setmode(RPi.GPIO.BCM)
|
||||
|
||||
|
||||
def hole(o, x, y):
|
||||
o.draw_pixel(x+1, y)
|
||||
o.draw_pixel(x+2, y)
|
||||
o.draw_pixel(x+3, y)
|
||||
o.draw_pixel(x+1, y + 4)
|
||||
o.draw_pixel(x+2, y + 4)
|
||||
o.draw_pixel(x+3, y + 4)
|
||||
o.draw_pixel(x, y + 1)
|
||||
o.draw_pixel(x+4, y + 1)
|
||||
o.draw_pixel(x, y + 2)
|
||||
o.draw_pixel(x+4, y + 2)
|
||||
o.draw_pixel(x, y + 3)
|
||||
o.draw_pixel(x+4, y + 3)
|
||||
|
||||
|
||||
def draw_points(o):
|
||||
for _ in range(0, 50):
|
||||
hole(o,
|
||||
random.randint(2, o.width - 10),
|
||||
random.randint(2, o.height - 10)
|
||||
)
|
||||
|
||||
|
||||
def draw_net(o):
|
||||
s = 0
|
||||
while s < o.width-1:
|
||||
o.draw_line(s, 0, s, o.height-1)
|
||||
s += 10
|
||||
s = 0
|
||||
while s < o.height-1:
|
||||
o.draw_line(0, s, o.width-1, s)
|
||||
s += 10
|
||||
|
||||
|
||||
lcd_oled = SSD1306(128, 64, SPI())
|
||||
lcd_oled.rotation = 90
|
||||
lcd_oled.init()
|
||||
|
@ -11,7 +11,6 @@ class Page(Pixel, metaclass=abc.ABCMeta):
|
||||
|
||||
def init(self):
|
||||
"""init page"""
|
||||
#self.rotate = rotate
|
||||
if self.rotation == 0 or self.rotation == 180:
|
||||
self.buffer = [[0] * (self.height // 8) for x in range(self.width)]
|
||||
else:
|
||||
@ -19,8 +18,6 @@ class Page(Pixel, metaclass=abc.ABCMeta):
|
||||
|
||||
def draw_pixel(self, pos_x, pos_y):
|
||||
"""draw a pixel at x,y"""
|
||||
if self.rotation == 90 or self.rotation == 270:
|
||||
pos_x, pos_y = pos_y, pos_x
|
||||
self.buffer[pos_x][pos_y//8] |= 1 << (pos_y % 8)
|
||||
self.flush()
|
||||
|
||||
|
@ -24,12 +24,16 @@ class NJU6450(Page, Chip):
|
||||
|
||||
def set_xy(self, pos_x, pos_y):
|
||||
"""set xy pos"""
|
||||
if pos_x < self.width/2:
|
||||
if self.rotation == 0 or self.rotation == 180:
|
||||
width = self.width
|
||||
else:
|
||||
width = self.height
|
||||
if pos_x < width//2:
|
||||
self.driver.cmd(0xB8 | pos_y, 0)
|
||||
self.driver.cmd(0x00 | pos_x, 0)
|
||||
else:
|
||||
self.driver.cmd(0xB8 | pos_y, 1)
|
||||
self.driver.cmd(0x00 | (pos_x - self.width//2), 1)
|
||||
self.driver.cmd(0x00 | (pos_x - width//2), 1)
|
||||
|
||||
def _converted_background_color(self):
|
||||
"""convert RGB background to available color"""
|
||||
@ -46,10 +50,37 @@ class NJU6450(Page, Chip):
|
||||
force = self.options['auto_flush']
|
||||
|
||||
if force:
|
||||
for j in range(0, self.height//8):
|
||||
for i in range(0, self.width):
|
||||
if self.rotation == 0 or self.rotation == 180:
|
||||
height, width = self.height, self.width
|
||||
else:
|
||||
width, height = self.height, self.width
|
||||
for j in range(0, height//8):
|
||||
for i in range(0, width):
|
||||
self.set_xy(i, j)
|
||||
if i < self.width/2:
|
||||
if i < width//2:
|
||||
self.driver.data(self.get_page_value(i, j), 0)
|
||||
else:
|
||||
self.driver.data(self.get_page_value(i, j), 1)
|
||||
|
||||
def draw_pixel(self, pos_x, pos_y):
|
||||
"""draw a pixel at x,y"""
|
||||
if self.rotation == 90:
|
||||
pos_x, pos_y = self.height - pos_y - 1, pos_x
|
||||
if self.rotation == 180:
|
||||
pos_x, pos_y = self.width - pos_x - 1, self.height - pos_y - 1
|
||||
if self.rotation == 270:
|
||||
pos_x, pos_y = pos_y, self.width - pos_x - 1
|
||||
Page.draw_pixel(self, pos_x, pos_y)
|
||||
|
||||
def fill_rect(self, pos_x1, pos_y1, pos_x2, pos_y2):
|
||||
"""draw a filled rectangle"""
|
||||
if self.rotation == 90:
|
||||
pos_x1, pos_y1 = self.height - pos_y1 - 1, pos_x1
|
||||
pos_x2, pos_y2 = self.height - pos_y2 - 1, pos_x2
|
||||
if self.rotation == 180:
|
||||
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
|
||||
Page.fill_rect(self, pos_x1, pos_y1, pos_x2, pos_y2)
|
||||
|
@ -101,10 +101,15 @@ class SSD1306(Page, Chip):
|
||||
|
||||
def set_area(self, pos_x1, pos_y1, pos_x2, pos_y2):
|
||||
"""set area to work on"""
|
||||
|
||||
self.driver.cmd(0x22)
|
||||
self.driver.cmd(0xb0 + pos_y1)
|
||||
self.driver.cmd(0xb0 + pos_y2)
|
||||
self.driver.cmd(0x21)
|
||||
self.driver.cmd(pos_x1)
|
||||
self.driver.cmd(pos_x2)
|
||||
|
||||
def draw_pixel(self, pos_x, pos_y):
|
||||
"""draw a pixel at x,y"""
|
||||
if self.rotation == 90 or self.rotation == 270:
|
||||
pos_x, pos_y = pos_y, pos_x
|
||||
Page.draw_pixel(self, pos_x, pos_y)
|
||||
|
Loading…
Reference in New Issue
Block a user