Skip to content

Commit

Permalink
fixed issue with byte use on py 2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
gigapod committed Jul 5, 2019
1 parent 3e1c1ee commit 806d2aa
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions qwiic_micro_oled/moled_fonts.py
Expand Up @@ -18,6 +18,13 @@
#==================================================================================
# Copyright (c) 2019 SparkFun Electronics
#
<<<<<<< HEAD
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http:= www.gnu.org/licenses/>.
#-----------------------------------------------------------------------------

from __future__ import division
=======
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
Expand All @@ -37,6 +44,7 @@
# SOFTWARE.
#==================================================================================

>>>>>>> 3e1c1ee6286234cb0cbf4e8f90b7b6c03a051e6e
import sys
import os

Expand Down Expand Up @@ -87,6 +95,7 @@ def _loadFontFile(self, fontFile):

# read the font header
fHeader = fp.read(6)
fHeader = bytearray(fHeader) ## for int conversion
self.width = fHeader[0]
self.height = fHeader[1]
self.start_char = fHeader[2]
Expand All @@ -102,16 +111,21 @@ def _loadFontFile(self, fontFile):
# Double note: If the font is a single row - we add a byte to the row buffer
# Seems no margin was encoded on this font, and this bust be added

rowsPerChar = math.ceil(self.height/8)
rowsPerChar = int(math.ceil(self.height/8.))

# do we add a pad byte?
nPad = (rowsPerChar == 1)*1

# buffer padding bytes
bBuffer = bytearray(nPad)

# read in font
for iChar in range(self.total_char * rowsPerChar):

try:
self._fontData[iChar] = fp.read(self.width) + bytes( [0]*nPad )

self._fontData[iChar] = bytearray(fp.read(self.width)) + bBuffer

except Exception as exError:
print("Error reading font data. Character: %d, File:%s" % (iChar, _loadFontFile))

Expand Down

0 comments on commit 806d2aa

Please sign in to comment.