Skip to content

Commit 69a225b

Browse files
author
Vincent Pillet
committed
tiniest container
1 parent a818552 commit 69a225b

18 files changed

+345
-0
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.

tiniest/Dockerfile

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
ARG PYTHON_VERSION=3.11
2+
3+
FROM alpine as builder
4+
ARG PYTHON_VERSION
5+
6+
RUN apk add --no-cache python3~=${PYTHON_VERSION}
7+
WORKDIR /usr/lib/python${PYTHON_VERSION}
8+
RUN python -m compileall -o 2 .
9+
RUN find . -name "*.cpython-*.opt-2.pyc" | awk '{print $1, $1}' | sed 's/__pycache__\///2' | sed 's/.cpython-[0-9]\{2,\}.opt-2//2' | xargs -n 2 mv
10+
#RUN find . -mindepth 1 | grep -v -E '^\./(encodings)([/.].*)?$' | xargs rm -rf
11+
RUN find . -name "*.py" -delete
12+
RUN find . -name "__pycache__" -exec rm -r {} +
13+
14+
RUN apk add --update alpine-sdk py3-pip python3-dev linux-headers swig zlib
15+
COPY requirements.txt requirements.txt
16+
RUN pip install --break-system-packages -r requirements.txt
17+
18+
19+
FROM scratch
20+
ARG PYTHON_VERSION
21+
22+
ENV PYTHONPATH=/usr/lib/python${PYTHON_VERSION}
23+
24+
COPY --from=builder /usr/bin/python3 /
25+
COPY --from=builder /lib/ld-musl-aarch64.so.1 /lib/ld-musl-aarch64.so.1
26+
COPY --from=builder /usr/lib/libffi* /usr/lib/
27+
COPY --from=builder /lib/libz* /lib/
28+
COPY --from=builder /usr/lib/libpython${PYTHON_VERSION}.so.1.0 /usr/lib/libpython${PYTHON_VERSION}.so.1.0
29+
COPY --from=builder /usr/lib/python${PYTHON_VERSION}/ /usr/lib/python${PYTHON_VERSION}/
30+
COPY . .
31+
32+
CMD ["/python3", "signs/sign.py"]

tiniest/go.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
docker build -t tiny .

tiniest/requirements.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
smbus
2+
spidev
3+
gpiozero
4+
pillow
5+
# lgpio

tiniest/signs/pic/speed-110.png

60.1 KB
Loading

tiniest/signs/pic/speed-130.png

64.2 KB
Loading

tiniest/signs/pic/speed-50.png

61.7 KB
Loading

tiniest/signs/pic/speed-80.png

63.3 KB
Loading

tiniest/signs/pic/speed-90.png

63.5 KB
Loading

tiniest/signs/sign.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import sys
2+
import os
3+
import logging
4+
import time
5+
import traceback
6+
from waveshare_OLED import OLED_1in5_rgb
7+
from PIL import Image,ImageDraw,ImageFont
8+
logging.basicConfig(level=logging.DEBUG)
9+
10+
try:
11+
disp = OLED_1in5_rgb.OLED_1in5_rgb()
12+
13+
logging.info("\r 1.5inch rgb OLED ")
14+
# Initialize library.
15+
disp.Init()
16+
# Clear display.
17+
logging.info("clear display")
18+
disp.clear()
19+
20+
logging.info ("***draw image")
21+
Himage2 = Image.new('RGB', (disp.width, disp.height), 0) # 0: clear the frame
22+
png = Image.open(os.path.join('signs/pic', 'speed-80.png'))
23+
Himage2.paste(png.resize((disp.width-20, disp.height-20)), (10,10))
24+
Himage2=Himage2.rotate(0)
25+
disp.ShowImage(disp.getbuffer(Himage2))
26+
time.sleep(10)
27+
28+
disp.clear()
29+
30+
except IOError as e:
31+
logging.info(e)
32+
33+
except KeyboardInterrupt:
34+
logging.info("ctrl + c:")
35+
disp.module_exit()
36+
exit()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# /*****************************************************************************
2+
# * | File : OLED_1in5_rgb.py
3+
# * | Author : Waveshare team
4+
# * | Function : Driver for OLED_1in5_rgb
5+
# * | Info :
6+
# *----------------
7+
# * | This version: V2.0
8+
# * | Date : 2020-08-17
9+
# * | Info :
10+
# ******************************************************************************/
11+
# Permission is hereby granted, free of charge, to any person obtaining a copy
12+
# of this software and associated documnetation files (the "Software"), to deal
13+
# in the Software without restriction, including without limitation the rights
14+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15+
# copies of the Software, and to permit persons to whom the Software is
16+
# furished to do so, subject to the following conditions:
17+
#
18+
# The above copyright notice and this permission notice shall be included in
19+
# all copies or substantial portions of the Software.
20+
#
21+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23+
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27+
# THE SOFTWARE.
28+
#
29+
30+
from . import config
31+
import time
32+
33+
Device_SPI = config.Device_SPI
34+
Device_I2C = config.Device_I2C
35+
36+
OLED_WIDTH = 128 #OLED width
37+
OLED_HEIGHT = 128 #OLED height
38+
39+
class OLED_1in5_rgb(config.RaspberryPi):
40+
41+
""" Write register address and data """
42+
def command(self, cmd):
43+
self.digital_write(self.DC_PIN,False)
44+
self.spi_writebyte([cmd])
45+
46+
""" Write data """
47+
def data(self, data):
48+
self.digital_write(self.DC_PIN,True)
49+
self.spi_writebyte([data])
50+
51+
def Init(self):
52+
if (self.module_init() != 0):
53+
return -1
54+
55+
self.width = OLED_WIDTH
56+
self.height = OLED_HEIGHT
57+
58+
"""Initialize dispaly"""
59+
self.reset()
60+
61+
if(self.Device == Device_I2C):
62+
print ("Only Device_SPI, Please revise config.py !!!")
63+
exit()
64+
65+
self.command(0xfd) # command lock
66+
self.data(0x12)
67+
self.command(0xfd) # command lock
68+
self.data(0xB1)
69+
70+
self.command(0xae) # display off
71+
self.command(0xa4) # Normal Display mode
72+
73+
self.command(0x15) # set column address
74+
self.data(0x00) # column address start 00
75+
self.data(0x7f) # column address end 127
76+
self.command(0x75) # set row address
77+
self.data(0x00) # row address start 00
78+
self.data(0x7f) # row address end 127
79+
80+
self.command(0xB3)
81+
self.data(0xF1)
82+
83+
self.command(0xCA)
84+
self.data(0x7F)
85+
86+
self.command(0xa0) # set re-map & data format
87+
self.data(0x74) # Horizontal address increment
88+
89+
self.command(0xa1) # set display start line
90+
self.data(0x00) # start 00 line
91+
92+
self.command(0xa2) # set display offset
93+
self.data(0x00)
94+
95+
self.command(0xAB)
96+
self.command(0x01)
97+
98+
self.command(0xB4)
99+
self.data(0xA0)
100+
self.data(0xB5)
101+
self.data(0x55)
102+
103+
self.command(0xC1)
104+
self.data(0xC8)
105+
self.data(0x80)
106+
self.data(0xC0)
107+
108+
self.command(0xC7)
109+
self.data(0x0F)
110+
111+
self.command(0xB1)
112+
self.data(0x32)
113+
114+
self.command(0xB2)
115+
self.data(0xA4)
116+
self.data(0x00)
117+
self.data(0x00)
118+
119+
self.command(0xBB)
120+
self.data(0x17)
121+
122+
self.command(0xB6)
123+
self.data(0x01)
124+
125+
self.command(0xBE)
126+
self.data(0x05)
127+
128+
self.command(0xA6)
129+
130+
time.sleep(0.1)
131+
self.command(0xAF);#--turn on oled panel
132+
133+
134+
def reset(self):
135+
"""Reset the display"""
136+
self.digital_write(self.RST_PIN,True)
137+
time.sleep(0.1)
138+
self.digital_write(self.RST_PIN,False)
139+
time.sleep(0.1)
140+
self.digital_write(self.RST_PIN,True)
141+
time.sleep(0.1)
142+
143+
def clear(self):
144+
_buffer = [0x00]*(self.width * self.height * 2)
145+
self.ShowImage(_buffer)
146+
147+
def getbuffer(self, image):
148+
buf = [0x00] * ((self.width*2) * self.height)
149+
imwidth, imheight = image.size
150+
pixels = image.load()
151+
for y in range(imheight):
152+
for x in range(imwidth):
153+
# Set the bits for the column of pixels at the current position.
154+
buf[x*2 + y*imwidth*2] = ((pixels[x,y][0] & 0xF8) | (pixels[x,y][1] >> 5))
155+
buf[x*2+1 + y*imwidth*2] = (((pixels[x,y][1]<<3) & 0xE0) | (pixels[x,y][2] >> 3))
156+
return buf
157+
158+
def ShowImage(self, pBuf):
159+
self.command(0x15) # set column address
160+
self.data(0x00) # column address start 00
161+
self.data(0x7f) # column address end 127
162+
self.command(0x75) # set row address
163+
self.data(0x00) # row address start 00
164+
self.data(0x7f) # row address end 127
165+
self.command(0x5C);
166+
for i in range(0, self.height):
167+
for j in range(0, self.width*2):
168+
self.data(pBuf[j + self.width*2*i])
169+
return
170+
171+

tiniest/signs/waveshare_OLED/__init__.py

Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# /*****************************************************************************
2+
# * | File : config.py
3+
# * | Author : Waveshare team
4+
# * | Function : Hardware underlying interface,for Raspberry pi
5+
# * | Info :
6+
# *----------------
7+
# * | This version: V1.0
8+
# * | Date : 2020-06-17
9+
# * | Info :
10+
# ******************************************************************************/
11+
# Permission is hereby granted, free of charge, to any person obtaining a copy
12+
# of this software and associated documnetation files (the "Software"), to deal
13+
# in the Software without restriction, including without limitation the rights
14+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15+
# copies of the Software, and to permit persons to whom the Software is
16+
# furished to do so, subject to the following conditions:
17+
#
18+
# The above copyright notice and this permission notice shall be included in
19+
# all copies or substantial portions of the Software.
20+
#
21+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23+
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27+
# THE SOFTWARE.
28+
#
29+
30+
31+
import time
32+
from smbus import SMBus
33+
import spidev
34+
import ctypes
35+
from gpiozero import *
36+
37+
Device_SPI = 1
38+
Device_I2C = 0
39+
40+
class RaspberryPi:
41+
def __init__(self,spi=spidev.SpiDev(0,0),spi_freq=10000000,rst = 27,dc = 25,bl = 18,bl_freq=1000,i2c=None):
42+
self.INPUT = False
43+
self.OUTPUT = True
44+
45+
self.SPEED =spi_freq
46+
47+
if(Device_SPI == 1):
48+
self.Device = Device_SPI
49+
self.spi = spi
50+
else :
51+
self.Device = Device_I2C
52+
self.address = 0x3c
53+
self.bus = SMBus(1)
54+
55+
self.RST_PIN = self.gpio_mode(rst,self.OUTPUT)
56+
self.DC_PIN = self.gpio_mode(dc,self.OUTPUT)
57+
58+
59+
def delay_ms(self,delaytime):
60+
time.sleep(delaytime / 1000.0)
61+
62+
def gpio_mode(self,Pin,Mode,pull_up = None,active_state = True):
63+
if Mode:
64+
return DigitalOutputDevice(Pin,active_high = True,initial_value =False)
65+
else:
66+
return DigitalInputDevice(Pin,pull_up=pull_up,active_state=active_state)
67+
68+
def digital_write(self, Pin, value):
69+
if value:
70+
Pin.on()
71+
else:
72+
Pin.off()
73+
74+
def digital_read(self, Pin):
75+
return Pin.value
76+
77+
def spi_writebyte(self,data):
78+
self.spi.writebytes([data[0]])
79+
80+
def i2c_writebyte(self,reg, value):
81+
self.bus.write_byte_data(self.address, reg, value)
82+
83+
def module_init(self):
84+
self.digital_write(self.RST_PIN,False)
85+
if(self.Device == Device_SPI):
86+
self.spi.max_speed_hz = self.SPEED
87+
self.spi.mode = 0b11
88+
self.digital_write(self.DC_PIN,False)
89+
return 0
90+
91+
def module_exit(self):
92+
if(self.Device == Device_SPI):
93+
self.spi.close()
94+
else :
95+
self.bus.close()
96+
self.digital_write(self.RST_PIN,False)
97+
self.digital_write(self.DC_PIN,False)
98+
99+
### END OF FILE ###

0 commit comments

Comments
 (0)