Skip to content

Commit

Permalink
PY3 version for Matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
roidy committed Dec 19, 2020
1 parent 60b9168 commit 56acd3a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="service.odroidn2.oled" name="Odroid N2 OLED Driver" version="0.1.8" provider-name="roidy">
<addon id="service.odroidn2.oled" name="Odroid N2 OLED Driver" version="0.1.108" provider-name="roidy">
<requires>
<import addon="xbmc.python" version="2.26.0" />
<import addon="xbmc.python" version="3.0.0" />
</requires>
<extension point="xbmc.service" library="service.py" start="startup" />
<extension point="xbmc.addon.metadata">
Expand Down
2 changes: 1 addition & 1 deletion lib/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ def logWarning(message):


def logNotice(message):
log(message, xbmc.LOGNOTICE)
log(message, xbmc.LOGINFO)
56 changes: 28 additions & 28 deletions lib/oled.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from smbus2 import SMBus
from smbus2 import SMBusWrapper
from lib.smbus2 import SMBus
from lib.smbus2 import SMBusWrapper
from lib.logging import *
import time
import xbmcgui
import gpio
import spi
import lib.gpio
import lib.spi

CHARGEPUMP = 0x8D
COLUMNADDR = 0x21
Expand Down Expand Up @@ -224,29 +224,29 @@ def _initSSD1306_32(self):
def _displaySH1106(self):
page = 0xB0
step = self._width * 8
for y in xrange(0, step * 8, step):
for y in range(0, step * 8, step):
self._command(page)
self._command(0x02)
self._command(0x10)
page += 1

buffer = []
for x in xrange(self._width):
for x in range(self._width):
byte = 0
for n in xrange(0, step, self._width):
for n in range(0, step, self._width):
byte |= (self._image[x + y + n] & 0x01) << 8
byte >>= 1
buffer.append(byte)

# Write buffer data
for i in xrange(0, len(buffer), 16):
for i in range(0, len(buffer), 16):
with SMBusWrapper(2) as bus:
bus.write_i2c_block_data(self._i2c, 0x40, buffer[i:i+16])

def _displaySSD1306(self):
buffer = []
for page in xrange(self._pages):
for x in xrange(self._width):
for page in range(self._pages):
for x in range(self._width):
bits = 0
for bit in [0, 1, 2, 3, 4, 5, 6, 7]:
bits = bits << 1
Expand All @@ -261,14 +261,14 @@ def _displaySSD1306(self):
self._command(self._pages - 1) # Page end address.

# Write buffer data
for i in xrange(0, len(buffer), 16):
for i in range(0, len(buffer), 16):
with SMBusWrapper(2) as bus:
bus.write_i2c_block_data(self._i2c, 0x40, buffer[i:i+16])

def _displaySSD1309SPI(self):
buffer = []
for page in xrange(self._pages):
for x in xrange(self._width):
for page in range(self._pages):
for x in range(self._width):
bits = 0
for bit in [0, 1, 2, 3, 4, 5, 6, 7]:
bits = bits << 1
Expand All @@ -285,11 +285,11 @@ def _displaySSD1309SPI(self):

# Write buffer data
gpio.gpioWriteDC(1)
for i in xrange(0, len(buffer), 8):
for i in range(0, len(buffer), 8):
self.spi.transfer(buffer[i:i+8])

def clear(self):
for i in xrange(self._width * self._height):
for i in range(self._width * self._height):
self._image[i] = 0

def close(self):
Expand Down Expand Up @@ -331,13 +331,13 @@ def getStringWidth(self, str, charset):
def drawIcons(self, info, x, y, center, solid, charset):
if (center):
width = 0
for i in xrange(0, len(info)):
for i in range(0, len(info)):
w = self.getStringWidth(info[i], charset)
width += w + 4

x = ((128 - width) // 2) + 4

for i in xrange(0, len(info)):
for i in range(0, len(info)):
pos = self.drawString(
info[i], x, y, solid, charset)
x += pos + 4
Expand All @@ -353,8 +353,8 @@ def drawString(self, str, x, y, solid, charset):

if solid:
border = False
for by in xrange(y - 2, y + 1 + charHeight + 1):
for bx in xrange(x - 2, x + strWidth + 2):
for by in range(y - 2, y + 1 + charHeight + 1):
for bx in range(x - 2, x + strWidth + 2):
self._image[bx + (by * self._width)
] = 0
else:
Expand Down Expand Up @@ -384,17 +384,17 @@ def drawString(self, str, x, y, solid, charset):
px += charStride

if border:
for bx in xrange(x - 2, x + strWidth + 2 + dashFix):
for bx in range(x - 2, x + strWidth + 2 + dashFix):
self._image[bx + ((y - 3) * self._width)] = 1
self._image[bx + ((y + 2 + charHeight) * self._width)] = 1

for by in xrange(y - 2, y + 2 + charHeight):
for by in range(y - 2, y + 2 + charHeight):
self._image[x - 3 + (by * self._width)] = 1
self._image[x + 2 + strWidth + dashFix + (by * self._width)] = 1

if solid:
for by in xrange(y - 2, y + 1 + charHeight + 1):
for bx in xrange(x - 2, x + strWidth + 2 + dashFix):
for by in range(y - 2, y + 1 + charHeight + 1):
for bx in range(x - 2, x + strWidth + 2 + dashFix):
self._image[bx + (by * self._width)
] = not self._image[bx + (by * self._width)]
self._image[x - 2 +
Expand All @@ -410,13 +410,13 @@ def drawString(self, str, x, y, solid, charset):
return len(str) * charStride + dashFix + 3

def _drawChar(self, char, x, y, cw, cbh, chset):
for sx in xrange(0, cw):
for sy in xrange(0, cbh):
for sx in range(0, cw):
for sy in range(0, cbh):
dy = y
chdata = chset[char][sx + sy * cw]
for bit in [0, 1, 2, 3, 4, 5, 6, 7]:
self._image[(sx + x) + ((8 * sy) + dy) *
self._width] = (chdata >> bit) & 0x01
self._image[int((sx + x) + ((8 * sy) + dy) *
self._width)] = (chdata >> bit) & 0x01
dy += 1

def drawProgress(self, seconds, totalSeconds):
Expand All @@ -425,7 +425,7 @@ def drawProgress(self, seconds, totalSeconds):
else:
y = 56

for py in xrange(y - 3, y + 4):
for py in range(y - 3, y + 4):
self._image[10 + (py * self._width)] = 1
self._image[117 + (py * self._width)] = 1

Expand Down

0 comments on commit 56acd3a

Please sign in to comment.