Unneeded code
This commit is contained in:
@@ -31,7 +31,6 @@ class Ctrl(object):
|
||||
self.avr = bbctrl.AVR(self)
|
||||
|
||||
self.i2c = bbctrl.I2C(args.i2c_port, args.demo)
|
||||
self.lcd = bbctrl.LCD(self)
|
||||
self.mach = bbctrl.Mach(self, self.avr)
|
||||
self.preplanner = bbctrl.Preplanner(self)
|
||||
if not args.demo:
|
||||
@@ -40,9 +39,6 @@ class Ctrl(object):
|
||||
|
||||
self.mach.connect()
|
||||
|
||||
self.lcd.add_new_page(bbctrl.MainLCDPage(self))
|
||||
self.lcd.add_new_page(bbctrl.IPLCDPage(self.lcd))
|
||||
|
||||
os.environ['GCODE_SCRIPT_PATH'] = self.get_upload()
|
||||
|
||||
except Exception:
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
################################################################################
|
||||
# #
|
||||
# This file is part of the Buildbotics firmware. #
|
||||
# #
|
||||
# Copyright (c) 2015 - 2018, Buildbotics LLC #
|
||||
# All rights reserved. #
|
||||
# #
|
||||
# This file ("the software") is free software: you can redistribute it #
|
||||
# and/or modify it under the terms of the GNU General Public License, #
|
||||
# version 2 as published by the Free Software Foundation. You should #
|
||||
# have received a copy of the GNU General Public License, version 2 #
|
||||
# along with the software. If not, see <http://www.gnu.org/licenses/>. #
|
||||
# #
|
||||
# The software is distributed in the hope that it will be useful, but #
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
|
||||
# Lesser General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU Lesser General Public #
|
||||
# License along with the software. If not, see #
|
||||
# <http://www.gnu.org/licenses/>. #
|
||||
# #
|
||||
# For information regarding this software email: #
|
||||
# "Joseph Coffland" <joseph@buildbotics.com> #
|
||||
# #
|
||||
################################################################################
|
||||
|
||||
import subprocess
|
||||
|
||||
import bbctrl
|
||||
|
||||
|
||||
class IPLCDPage(bbctrl.LCDPage):
|
||||
# From bbctrl.LCDPage
|
||||
def activate(self):
|
||||
p = subprocess.Popen(['hostname', '-I'], stdout = subprocess.PIPE)
|
||||
ips = p.communicate()[0].decode('utf-8').split()
|
||||
|
||||
p = subprocess.Popen(['hostname'], stdout = subprocess.PIPE)
|
||||
hostname = p.communicate()[0].decode('utf-8').strip()
|
||||
|
||||
self.clear()
|
||||
|
||||
self.text('Host: %s' % hostname[0:14], 0, 0)
|
||||
|
||||
for i in range(min(3, len(ips))):
|
||||
if len(ips[i]) <= 16:
|
||||
self.text('IP: %s' % ips[i], 0, i + 1)
|
||||
@@ -64,12 +64,6 @@ class Jog(inevent.JogHandler):
|
||||
self.processor = inevent.InEvent(ctrl.ioloop, self, types = ['js'])
|
||||
|
||||
|
||||
def up(self): self.ctrl.lcd.page_up()
|
||||
def down(self): self.ctrl.lcd.page_down()
|
||||
def left(self): self.ctrl.lcd.page_left()
|
||||
def right(self): self.ctrl.lcd.page_right()
|
||||
|
||||
|
||||
def callback(self):
|
||||
if self.v != self.lastV:
|
||||
self.lastV = self.v
|
||||
|
||||
@@ -1,207 +0,0 @@
|
||||
################################################################################
|
||||
# #
|
||||
# This file is part of the Buildbotics firmware. #
|
||||
# #
|
||||
# Copyright (c) 2015 - 2018, Buildbotics LLC #
|
||||
# All rights reserved. #
|
||||
# #
|
||||
# This file ("the software") is free software: you can redistribute it #
|
||||
# and/or modify it under the terms of the GNU General Public License, #
|
||||
# version 2 as published by the Free Software Foundation. You should #
|
||||
# have received a copy of the GNU General Public License, version 2 #
|
||||
# along with the software. If not, see <http://www.gnu.org/licenses/>. #
|
||||
# #
|
||||
# The software is distributed in the hope that it will be useful, but #
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
|
||||
# Lesser General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU Lesser General Public #
|
||||
# License along with the software. If not, see #
|
||||
# <http://www.gnu.org/licenses/>. #
|
||||
# #
|
||||
# For information regarding this software email: #
|
||||
# "Joseph Coffland" <joseph@buildbotics.com> #
|
||||
# #
|
||||
################################################################################
|
||||
|
||||
import lcd
|
||||
import atexit
|
||||
|
||||
|
||||
class LCDPage:
|
||||
def __init__(self, lcd, text = None):
|
||||
self.lcd = lcd
|
||||
self.data = lcd.new_screen()
|
||||
|
||||
if text is not None:
|
||||
self.text(text, (lcd.width - len(text)) // 2, 1)
|
||||
|
||||
|
||||
def activate(self): pass
|
||||
def deactivate(self): pass
|
||||
|
||||
|
||||
def put(self, c, x, y):
|
||||
y += x // self.lcd.width
|
||||
x %= self.lcd.width
|
||||
y %= self.lcd.height
|
||||
|
||||
if self.data[x][y] != c:
|
||||
self.data[x][y] = c
|
||||
if self == self.lcd.page: self.lcd.update()
|
||||
|
||||
|
||||
def text(self, s, x, y):
|
||||
for c in s:
|
||||
self.put(c, x, y)
|
||||
x += 1
|
||||
|
||||
|
||||
def clear(self):
|
||||
self.data = self.lcd.new_screen()
|
||||
self.lcd.redraw = True
|
||||
|
||||
|
||||
def shift_left(self): pass
|
||||
def shift_right(self): pass
|
||||
def shift_up(self): pass
|
||||
def shift_down(self): pass
|
||||
|
||||
|
||||
class LCD:
|
||||
def __init__(self, ctrl):
|
||||
self.ctrl = ctrl
|
||||
self.log = ctrl.log.get('LCD')
|
||||
|
||||
self.addrs = self.ctrl.args.lcd_addr
|
||||
self.addr = self.addrs[0]
|
||||
self.addr_num = 0
|
||||
|
||||
self.width = 20
|
||||
self.height = 4
|
||||
self.lcd = None
|
||||
self.timeout = None
|
||||
self.reset = False
|
||||
self.page = None
|
||||
self.pages = []
|
||||
self.current_page = 0
|
||||
self.screen = self.new_screen()
|
||||
self.set_message('Loading...')
|
||||
|
||||
self._redraw(False)
|
||||
if not ctrl.args.demo: atexit.register(self.goodbye)
|
||||
|
||||
|
||||
def set_message(self, msg):
|
||||
try:
|
||||
self.load_page(LCDPage(self, msg))
|
||||
self._update()
|
||||
except IOError as e:
|
||||
self.log.warning('LCD communication failed: %s' % e)
|
||||
|
||||
|
||||
def new_screen(self):
|
||||
return [[' ' for y in range(self.height)] for x in range(self.width)]
|
||||
|
||||
|
||||
def new_page(self): return LCDPage(self)
|
||||
def add_page(self, page): self.pages.append(page)
|
||||
|
||||
|
||||
def add_new_page(self, page = None):
|
||||
if page is None: page = self.new_page()
|
||||
page.id = len(self.pages)
|
||||
self.add_page(page)
|
||||
return page
|
||||
|
||||
|
||||
def load_page(self, page):
|
||||
if self.page != page:
|
||||
if self.page is not None: self.page.deactivate()
|
||||
page.activate()
|
||||
self.page = page
|
||||
self.redraw = True
|
||||
self.update()
|
||||
|
||||
|
||||
def set_current_page(self, current_page):
|
||||
self.current_page = current_page % len(self.pages)
|
||||
self.load_page(self.pages[self.current_page])
|
||||
|
||||
|
||||
def page_up(self): pass
|
||||
def page_down(self): pass
|
||||
def page_right(self): self.set_current_page(self.current_page + 1)
|
||||
def page_left(self): self.set_current_page(self.current_page - 1)
|
||||
|
||||
|
||||
def update(self):
|
||||
if self.timeout is None:
|
||||
self.timeout = self.ctrl.ioloop.call_later(0.25, self._update)
|
||||
|
||||
|
||||
def _redraw(self, now = True):
|
||||
if now:
|
||||
self.redraw = True
|
||||
self.update()
|
||||
self.redraw_timer = self.ctrl.ioloop.call_later(5, self._redraw)
|
||||
|
||||
|
||||
def _update(self):
|
||||
self.timeout = None
|
||||
|
||||
try:
|
||||
if self.lcd is None:
|
||||
self.lcd = lcd.LCD(self.ctrl.i2c, self.addr, self.height,
|
||||
self.width)
|
||||
|
||||
if self.reset:
|
||||
self.lcd.reset()
|
||||
self.redraw = True
|
||||
self.reset = False
|
||||
|
||||
cursorX, cursorY = -1, -1
|
||||
|
||||
for y in range(self.height):
|
||||
for x in range(self.width):
|
||||
c = self.page.data[x][y]
|
||||
|
||||
if self.redraw or self.screen[x][y] != c:
|
||||
if cursorX != x or cursorY != y:
|
||||
self.lcd.goto(x, y)
|
||||
cursorX, cursorY = x, y
|
||||
|
||||
self.lcd.put_char(c)
|
||||
cursorX += 1
|
||||
self.screen[x][y] = c
|
||||
|
||||
self.redraw = False
|
||||
|
||||
except IOError as e:
|
||||
# Try next address
|
||||
#self.addr_num += 1
|
||||
#if len(self.addrs) <= self.addr_num: self.addr_num = 0
|
||||
#self.addr = self.addrs[self.addr_num]
|
||||
#self.lcd = None
|
||||
|
||||
#self.log.warning('LCD communication failed, ' +
|
||||
# 'retrying on address 0x%02x: %s' % (self.addr, e))
|
||||
|
||||
#self.log.warning('LCD not present.')
|
||||
|
||||
#self.reset = True
|
||||
self.reset = False
|
||||
#self.timeout = self.ctrl.ioloop.call_later(1, self._update)
|
||||
|
||||
|
||||
def goodbye(self, message = ''):
|
||||
if self.timeout:
|
||||
self.ctrl.ioloop.remove_timeout(self.timeout)
|
||||
self.timeout = None
|
||||
|
||||
if self.redraw_timer:
|
||||
self.ctrl.ioloop.remove_timeout(self.redraw_timer)
|
||||
self.redraw_timer = None
|
||||
|
||||
if self.lcd is not None: self.set_message(message)
|
||||
@@ -1,76 +0,0 @@
|
||||
################################################################################
|
||||
# #
|
||||
# This file is part of the Buildbotics firmware. #
|
||||
# #
|
||||
# Copyright (c) 2015 - 2018, Buildbotics LLC #
|
||||
# All rights reserved. #
|
||||
# #
|
||||
# This file ("the software") is free software: you can redistribute it #
|
||||
# and/or modify it under the terms of the GNU General Public License, #
|
||||
# version 2 as published by the Free Software Foundation. You should #
|
||||
# have received a copy of the GNU General Public License, version 2 #
|
||||
# along with the software. If not, see <http://www.gnu.org/licenses/>. #
|
||||
# #
|
||||
# The software is distributed in the hope that it will be useful, but #
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
|
||||
# Lesser General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU Lesser General Public #
|
||||
# License along with the software. If not, see #
|
||||
# <http://www.gnu.org/licenses/>. #
|
||||
# #
|
||||
# For information regarding this software email: #
|
||||
# "Joseph Coffland" <joseph@buildbotics.com> #
|
||||
# #
|
||||
################################################################################
|
||||
|
||||
import bbctrl
|
||||
|
||||
|
||||
class MainLCDPage(bbctrl.LCDPage):
|
||||
def __init__(self, ctrl):
|
||||
bbctrl.LCDPage.__init__(self, ctrl.lcd)
|
||||
|
||||
self.ctrl = ctrl
|
||||
self.install = True
|
||||
|
||||
ctrl.state.add_listener(self.update)
|
||||
|
||||
|
||||
def update(self, update):
|
||||
state = self.ctrl.state
|
||||
|
||||
# Must be after machine vars have loaded
|
||||
if self.install and hasattr(self, 'id'):
|
||||
self.install = False
|
||||
self.ctrl.lcd.set_current_page(self.id)
|
||||
|
||||
self.text('%-9s' % state.get('xx', ''), 0, 0)
|
||||
|
||||
metric = not state.get('imperial', False)
|
||||
scale = 1 if metric else 25.4
|
||||
|
||||
# Show enabled axes
|
||||
row = 0
|
||||
for axis in 'xyzabc':
|
||||
if state.is_axis_faulted(axis):
|
||||
self.text(' FAULT %s' % axis.upper(), 9, row)
|
||||
row += 1
|
||||
|
||||
elif state.is_axis_enabled(axis):
|
||||
position = state.get(axis + 'p', 0)
|
||||
position += state.get('offset_' + axis, 0)
|
||||
position /= scale
|
||||
self.text('% 10.3f%s' % (position, axis.upper()), 9, row)
|
||||
row += 1
|
||||
|
||||
while row < 4:
|
||||
self.text(' ' * 11, 9, row)
|
||||
row += 1
|
||||
|
||||
# Show tool, units, feed and speed
|
||||
self.text('%2uT' % state.get('tool', 0), 6, 1)
|
||||
self.text('%-6s' % 'MM' if metric else 'INCH', 0, 1)
|
||||
self.text('%8uF' % (state.get('feed', 0) / scale), 0, 2)
|
||||
self.text('%8dS' % state.get('speed', 0), 0, 3)
|
||||
@@ -68,7 +68,6 @@ class Pwr():
|
||||
|
||||
self.i2c_addr = ctrl.args.pwr_addr
|
||||
self.regs = [-1] * 9
|
||||
self.lcd_page = ctrl.lcd.add_new_page()
|
||||
self.failures = 0
|
||||
|
||||
self._update_cb(False)
|
||||
@@ -179,16 +178,6 @@ class Pwr():
|
||||
self.failures = 0
|
||||
return
|
||||
|
||||
self.lcd_page.text('%3dC Tmp' % self.regs[TEMP_REG], 0, 0)
|
||||
self.lcd_page.text('%5.1fV In' % self.regs[VIN_REG], 0, 1)
|
||||
self.lcd_page.text('%5.1fV Out' % self.regs[VOUT_REG], 0, 2)
|
||||
self.lcd_page.text(' %04x Flg' % self.regs[FLAGS_REG], 0, 3)
|
||||
|
||||
self.lcd_page.text('%5.1fA Mot' % self.regs[MOTOR_REG], 10, 0)
|
||||
self.lcd_page.text('%5.1fA Ld1' % self.regs[LOAD1_REG], 10, 1)
|
||||
self.lcd_page.text('%5.1fA Ld2' % self.regs[LOAD2_REG], 10, 2)
|
||||
self.lcd_page.text('%5.1fA Vdd' % self.regs[VDD_REG], 10, 3)
|
||||
|
||||
if len(update): self.ctrl.state.update(update)
|
||||
|
||||
self.failures = 0
|
||||
|
||||
@@ -22,7 +22,6 @@ def call_get_output(cmd):
|
||||
|
||||
class RebootHandler(bbctrl.APIHandler):
|
||||
def put_ok(self):
|
||||
self.get_ctrl().lcd.goodbye('Rebooting...')
|
||||
subprocess.Popen('reboot')
|
||||
|
||||
|
||||
@@ -193,13 +192,11 @@ class FirmwareUpdateHandler(bbctrl.APIHandler):
|
||||
with open('firmware/update.tar.bz2', 'wb') as f:
|
||||
f.write(firmware['body'])
|
||||
|
||||
self.get_ctrl().lcd.goodbye('Upgrading firmware')
|
||||
subprocess.Popen(['/usr/local/bin/update-bbctrl'])
|
||||
|
||||
|
||||
class UpgradeHandler(bbctrl.APIHandler):
|
||||
def put_ok(self):
|
||||
self.get_ctrl().lcd.goodbye('Upgrading firmware')
|
||||
subprocess.Popen(['/usr/local/bin/upgrade-bbctrl'])
|
||||
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@ from bbctrl.RequestHandler import RequestHandler
|
||||
from bbctrl.APIHandler import APIHandler
|
||||
from bbctrl.FileHandler import FileHandler
|
||||
from bbctrl.Config import Config
|
||||
from bbctrl.LCD import LCD, LCDPage
|
||||
from bbctrl.Mach import Mach
|
||||
from bbctrl.Web import Web
|
||||
from bbctrl.Jog import Jog
|
||||
@@ -52,8 +51,6 @@ from bbctrl.Preplanner import Preplanner
|
||||
from bbctrl.State import State
|
||||
from bbctrl.Comm import Comm
|
||||
from bbctrl.CommandQueue import CommandQueue
|
||||
from bbctrl.MainLCDPage import MainLCDPage
|
||||
from bbctrl.IPLCDPage import IPLCDPage
|
||||
from bbctrl.Camera import Camera, VideoHandler
|
||||
from bbctrl.AVR import AVR
|
||||
from bbctrl.AVREmu import AVREmu
|
||||
@@ -132,8 +129,6 @@ def parse_args():
|
||||
help = 'Serial baud rate')
|
||||
parser.add_argument('--i2c-port', default = 1, type = int,
|
||||
help = 'I2C port')
|
||||
parser.add_argument('--lcd-addr', default = [0x27, 0x3f], type = int,
|
||||
help = 'LCD I2C address')
|
||||
parser.add_argument('--avr-addr', default = 0x2b, type = int,
|
||||
help = 'AVR I2C address')
|
||||
parser.add_argument('--pwr-addr', default = 0x60, type = int,
|
||||
|
||||
@@ -72,12 +72,6 @@ class JogHandler:
|
||||
log.info(axes_to_string(self.axes) + ' x {:d}'.format(self.speed))
|
||||
|
||||
|
||||
def up(self): log.debug('up')
|
||||
def down(self): log.debug('down')
|
||||
def left(self): log.debug('left')
|
||||
def right(self): log.debug('right')
|
||||
|
||||
|
||||
def reset(self):
|
||||
self.axes = [0.0, 0.0, 0.0, 0.0]
|
||||
self.speed = 3
|
||||
@@ -105,17 +99,6 @@ class JogHandler:
|
||||
if event.type == EV_ABS and event.code in config['axes']:
|
||||
pass
|
||||
|
||||
elif event.type == EV_ABS and event.code in config['arrows']:
|
||||
axis = config['arrows'].index(event.code)
|
||||
|
||||
if event.value < 0:
|
||||
if axis == 1: self.up()
|
||||
else: self.left()
|
||||
|
||||
elif 0 < event.value:
|
||||
if axis == 1: self.down()
|
||||
else: self.right()
|
||||
|
||||
elif event.type == EV_KEY and event.code in config['speed']:
|
||||
old_speed = self.speed
|
||||
self.speed = config['speed'].index(event.code) + 1
|
||||
|
||||
@@ -1,236 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
################################################################################
|
||||
# #
|
||||
# This file is part of the Buildbotics firmware. #
|
||||
# #
|
||||
# Copyright (c) 2015 - 2018, Buildbotics LLC #
|
||||
# All rights reserved. #
|
||||
# #
|
||||
# This file ("the software") is free software: you can redistribute it #
|
||||
# and/or modify it under the terms of the GNU General Public License, #
|
||||
# version 2 as published by the Free Software Foundation. You should #
|
||||
# have received a copy of the GNU General Public License, version 2 #
|
||||
# along with the software. If not, see <http://www.gnu.org/licenses/>. #
|
||||
# #
|
||||
# The software is distributed in the hope that it will be useful, but #
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
|
||||
# Lesser General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU Lesser General Public #
|
||||
# License along with the software. If not, see #
|
||||
# <http://www.gnu.org/licenses/>. #
|
||||
# #
|
||||
# For information regarding this software email: #
|
||||
# "Joseph Coffland" <joseph@buildbotics.com> #
|
||||
# #
|
||||
################################################################################
|
||||
|
||||
import time
|
||||
import logging
|
||||
|
||||
|
||||
log = logging.getLogger('LCD')
|
||||
|
||||
|
||||
# Control flags
|
||||
REG_SELECT_BIT = 1 << 0
|
||||
READ_BIT = 1 << 1
|
||||
ENABLE_BIT = 1 << 2
|
||||
BACKLIGHT_BIT = 1 << 3
|
||||
|
||||
# Commands
|
||||
LCD_CLEAR_DISPLAY = 1 << 0
|
||||
LCD_RETURN_HOME = 1 << 1
|
||||
LCD_ENTRY_MODE_SET = 1 << 2
|
||||
LCD_DISPLAY_CONTROL = 1 << 3
|
||||
LCD_CURSOR_SHIFT = 1 << 4
|
||||
LCD_FUNCTION_SET = 1 << 5
|
||||
LCD_SET_CGRAM_ADDR = 1 << 6
|
||||
LCD_SET_DDRAM_ADDR = 1 << 7
|
||||
|
||||
# Entry Mode Set flags
|
||||
LCD_ENTRY_SHIFT_DISPLAY = 1 << 0
|
||||
LCD_ENTRY_SHIFT_INC = 1 << 1
|
||||
LCD_ENTRY_SHIFT_DEC = 0 << 1
|
||||
|
||||
# Display Control flags
|
||||
LCD_BLINK_ON = 1 << 0
|
||||
LCD_BLINK_OFF = 0 << 0
|
||||
LCD_CURSOR_ON = 1 << 1
|
||||
LCD_CURSOR_OFF = 0 << 1
|
||||
LCD_DISPLAY_ON = 1 << 2
|
||||
LCD_DISPLAY_OFF = 0 << 2
|
||||
|
||||
# Cursor Shift flags
|
||||
LCD_SHIFT_RIGHT = 1 << 2
|
||||
LCD_SHIFT_LEFT = 0 << 2
|
||||
LCD_SHIFT_DISPLAY = 1 << 3
|
||||
LCD_SHIFT_CURSOR = 0 << 3
|
||||
|
||||
# Function Set flags
|
||||
LCD_5x11_DOTS = 1 << 2
|
||||
LCD_5x8_DOTS = 0 << 2
|
||||
LCD_2_LINE = 1 << 3
|
||||
LCD_1_LINE = 0 << 3
|
||||
LCD_8_BIT_MODE = 1 << 4
|
||||
LCD_4_BIT_MODE = 0 << 4
|
||||
|
||||
# Text justification flags
|
||||
JUSTIFY_LEFT = 0
|
||||
JUSTIFY_RIGHT = 1
|
||||
JUSTIFY_CENTER = 2
|
||||
|
||||
|
||||
|
||||
class LCD:
|
||||
def __init__(self, i2c, addr, height = 4, width = 20):
|
||||
self.addr = addr
|
||||
self.height = height
|
||||
self.width = width
|
||||
self.i2c = i2c
|
||||
self.backlight = True
|
||||
|
||||
self.reset()
|
||||
|
||||
|
||||
def reset(self):
|
||||
self.clear()
|
||||
time.sleep(0.050)
|
||||
self.write_nibble(3 << 4) # Home
|
||||
time.sleep(0.050)
|
||||
self.write_nibble(3 << 4) # Home
|
||||
time.sleep(0.050)
|
||||
self.write_nibble(3 << 4) # Home
|
||||
self.write_nibble(2 << 4) # 4-bit
|
||||
|
||||
self.write(LCD_FUNCTION_SET | LCD_2_LINE | LCD_5x8_DOTS |
|
||||
LCD_4_BIT_MODE)
|
||||
self.write(LCD_DISPLAY_CONTROL | LCD_DISPLAY_ON)
|
||||
self.write(LCD_ENTRY_MODE_SET | LCD_ENTRY_SHIFT_INC)
|
||||
|
||||
|
||||
def write_i2c(self, data):
|
||||
if self.backlight: data |= BACKLIGHT_BIT
|
||||
|
||||
self.i2c.write(self.addr, data)
|
||||
time.sleep(0.0001)
|
||||
|
||||
|
||||
# Write half of a command to LCD
|
||||
def write_nibble(self, data):
|
||||
self.write_i2c(data)
|
||||
|
||||
# Strobe
|
||||
self.write_i2c(data | ENABLE_BIT)
|
||||
time.sleep(0.0005)
|
||||
|
||||
self.write_i2c(data & ~ENABLE_BIT)
|
||||
time.sleep(0.0001)
|
||||
|
||||
|
||||
# Write an 8-bit command to LCD
|
||||
def write(self, cmd, flags = 0):
|
||||
self.write_nibble(flags | (cmd & 0xf0))
|
||||
self.write_nibble(flags | ((cmd << 4) & 0xf0))
|
||||
|
||||
|
||||
def set_cursor(self, on, blink):
|
||||
data = LCD_DISPLAY_CONTROL
|
||||
|
||||
if on: data |= LCD_CURSOR_ON
|
||||
if blink: data |= LCD_BLINK_ON
|
||||
|
||||
self.write(data)
|
||||
|
||||
|
||||
def set_backlight(self, enable):
|
||||
self.backlight = enable
|
||||
self.write_i2c(0)
|
||||
|
||||
|
||||
def program_char(self, addr, data):
|
||||
if addr < 0 or 8 <= addr: return
|
||||
|
||||
self.write(LCD_SET_CGRAM_ADDR | (addr << 3))
|
||||
for x in data:
|
||||
self.write(x, REG_SELECT_BIT)
|
||||
|
||||
|
||||
def goto(self, x, y):
|
||||
if x < 0 or self.width <= x or y < 0 or self.height <= y: return
|
||||
self.write(LCD_SET_DDRAM_ADDR | (0, 64, 20, 84)[y] + int(x))
|
||||
|
||||
|
||||
def put_char(self, c):
|
||||
self.write(ord(c), REG_SELECT_BIT)
|
||||
|
||||
|
||||
def text(self, msg, x = None, y = None):
|
||||
if x is not None and y is not None: self.goto(x, y)
|
||||
|
||||
for c in msg: self.put_char(c)
|
||||
|
||||
|
||||
def display(self, line, msg, justify = JUSTIFY_LEFT):
|
||||
if justify == JUSTIFY_RIGHT: x = self.width - len(msg)
|
||||
elif justify == JUSTIFY_CENTER: x = (self.width - len(msg)) / 2
|
||||
else: x = 0
|
||||
|
||||
if x < 0: x = 0
|
||||
|
||||
self.text(msg, x, line)
|
||||
|
||||
|
||||
def shift(self, count = 1, right = True, display = True):
|
||||
cmd = LCD_CURSOR_SHIFT
|
||||
if right: cmd |= LCD_SHIFT_RIGHT
|
||||
if display: cmd |= LCD_SHIFT_DISPLAY
|
||||
|
||||
for i in range(count): self.write(cmd)
|
||||
|
||||
|
||||
# Clear LCD and move cursor home
|
||||
def clear(self):
|
||||
self.write(LCD_CLEAR_DISPLAY)
|
||||
self.write(LCD_RETURN_HOME)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
lcd = LCD(1, 0x27)
|
||||
|
||||
lcd.clear()
|
||||
|
||||
lcd.program_char(0, (0b11011,
|
||||
0b11011,
|
||||
0b00000,
|
||||
0b01100,
|
||||
0b01100,
|
||||
0b00000,
|
||||
0b11011,
|
||||
0b11011))
|
||||
|
||||
lcd.program_char(1, (0b11000,
|
||||
0b01100,
|
||||
0b00110,
|
||||
0b00011,
|
||||
0b00011,
|
||||
0b00110,
|
||||
0b01100,
|
||||
0b11000))
|
||||
|
||||
lcd.program_char(2, (0b00011,
|
||||
0b00110,
|
||||
0b01100,
|
||||
0b11000,
|
||||
0b11000,
|
||||
0b01100,
|
||||
0b00110,
|
||||
0b00011))
|
||||
|
||||
lcd.display(0, '\0' * lcd.width)
|
||||
lcd.display(1, 'Hello world!', JUSTIFY_CENTER)
|
||||
lcd.display(2, '\1\2' * (lcd.width / 2))
|
||||
lcd.display(3, '12345678901234567890')
|
||||
@@ -1,38 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
################################################################################
|
||||
# #
|
||||
# This file is part of the Buildbotics firmware. #
|
||||
# #
|
||||
# Copyright (c) 2015 - 2018, Buildbotics LLC #
|
||||
# All rights reserved. #
|
||||
# #
|
||||
# This file ("the software") is free software: you can redistribute it #
|
||||
# and/or modify it under the terms of the GNU General Public License, #
|
||||
# version 2 as published by the Free Software Foundation. You should #
|
||||
# have received a copy of the GNU General Public License, version 2 #
|
||||
# along with the software. If not, see <http://www.gnu.org/licenses/>. #
|
||||
# #
|
||||
# The software is distributed in the hope that it will be useful, but #
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
|
||||
# Lesser General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU Lesser General Public #
|
||||
# License along with the software. If not, see #
|
||||
# <http://www.gnu.org/licenses/>. #
|
||||
# #
|
||||
# For information regarding this software email: #
|
||||
# "Joseph Coffland" <joseph@buildbotics.com> #
|
||||
# #
|
||||
################################################################################
|
||||
|
||||
import lcd
|
||||
|
||||
if __name__ == "__main__":
|
||||
screen = lcd.LCD(1, 0x27)
|
||||
|
||||
screen.clear()
|
||||
screen.display(0, 'Buildbotics', lcd.JUSTIFY_CENTER)
|
||||
screen.display(1, 'Controller', lcd.JUSTIFY_CENTER)
|
||||
screen.display(3, 'Booting...', lcd.JUSTIFY_CENTER)
|
||||
Reference in New Issue
Block a user