-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplay.py
More file actions
63 lines (52 loc) · 1.54 KB
/
display.py
File metadata and controls
63 lines (52 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import Image
import sys
import pygame
import config
MODE_SPI = 1
MODE_FB = 0
width = 0
height = 0
BLACK = ( 0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = ( 0, 255, 0)
BLUE = ( 0, 0, 255)
DARK_GREEN = ( 0, 204, 0)
ORANGE = (255, 153, 51)
def init():
global surf, disp, mode, image, width, height
global BLACK, WHITE, RED, GREEN, BLUE, DARK_GREEN, ORANGE
mode = (MODE_SPI if config.model == config.MODEL_PI2KF else MODE_FB)
if(mode == MODE_SPI):
import Adafruit_GPIO.SPI as SPI
import Adafruit_SSD1306
RST = 23
DC = 22
SPI_PORT = 0
SPI_DEVICE = 0
disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))
disp.begin()
disp.clear()
disp.display()
BLACK = 0
WHITE = RED = GREEN = BLUE = DARK_GREEN = ORANGE = 255
image = Image.new('1', (disp.width, disp.height))
width = disp.width
height = disp.width
else:
surf = pygame.display.set_mode((128, 128), 0, 16)
width = 128
height = 96
image = Image.new('RGB', (width, height))
return image
def update(image):
global surf, disp, mode
if(mode == MODE_SPI):
disp.image(image)
disp.display()
else:
print "update image"
idata = image.tobytes()
pgimage = pygame.image.fromstring(idata, image.size, image.mode)
surf.blit(pgimage, (0,32))
pygame.display.update()