First test on implementing octoprint.printer.PrinterCallback

This commit is contained in:
Felix Kunsmann 2017-03-14 13:19:02 +00:00
parent 8fc2a739d5
commit a1394af3aa
2 changed files with 57 additions and 1 deletions

View file

@ -1,6 +1,7 @@
# coding=utf-8 # coding=utf-8
import future import future
from builtins import chr
__author__ = "Felix Kunsmann <felix@kunsmann.eu>" __author__ = "Felix Kunsmann <felix@kunsmann.eu>"
__license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html" __license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html"
@ -8,6 +9,8 @@ __copyright__ = "Copyright (C) 2017 Felix Kunsmann - Released under terms of the
import octoprint.plugin import octoprint.plugin
from hd44780_callback import *
import RPi.GPIO as GPIO import RPi.GPIO as GPIO
from RPLCD import CharLCD from RPLCD import CharLCD
@ -35,8 +38,31 @@ class LCD_HD44780(octoprint.plugin.StartupPlugin,
self._lcd = None self._lcd = None
self._custom_heatbed = (
0b00000,
0b11111,
0b10101,
0b10101,
0b10001,
0b10101,
0b10101,
0b11111,
)
self._custom_tool0 = (
0b00000,
0b11111,
0b10001,
0b10111,
0b10011,
0b10111,
0b10001,
0b11111,
)
def on_settings_initialized(self): def on_settings_initialized(self):
self._initialize_lcd() self._initialize_lcd()
self._printer.register_callback(LCD_HD44780_PrinterCallback)
def _gpio_board_to_bcm(self, pin): def _gpio_board_to_bcm(self, pin):
if GPIO.RPI_REVISION == 1: if GPIO.RPI_REVISION == 1:
@ -90,9 +116,12 @@ class LCD_HD44780(octoprint.plugin.StartupPlugin,
self._lcd = CharLCD(pin_rs=pin_rs, pin_rw=pin_rw, pin_e=pin_e, pins_data=[pin_d4, pin_d5, pin_d6, pin_d7], self._lcd = CharLCD(pin_rs=pin_rs, pin_rw=pin_rw, pin_e=pin_e, pins_data=[pin_d4, pin_d5, pin_d6, pin_d7],
numbering_mode=GPIO.getmode(), cols=self.cols, rows=self.rows) numbering_mode=GPIO.getmode(), cols=self.cols, rows=self.rows)
self._lcd.create_char(0, self._custom_heatbed)
self._lcd.create_char(1, self._custom_tool0)
self._lcd.cursor_mode = CursorMode.hide self._lcd.cursor_mode = CursorMode.hide
self._lcd.clear() self._lcd.clear()
self._lcd.write_string('Octoprint-LCD-HD44780\n\rVersion: 0.1') self._lcd.write_string('Octoprint')
__plugin_name__ = "LCD: HD44780-compatible" __plugin_name__ = "LCD: HD44780-compatible"

View file

@ -0,0 +1,27 @@
# coding=utf-8
import future
from builtins import chr
import octoprint.plugin
class LCD_HD44780_PrinterCallback(octoprint.printer.PrinterCallback):
def on_printer_add_log(data):
pass
def on_printer_add_message(data):
pass
def on_printer_add_temperature(data):
LCD_HD44780._lcd.cursor_pos = (3,0)
LCD_HD44780._lcd.write_string(chr(1) + '{:5.1f}/{:3f}'.format(data['tool0']['actual'], data['tool0']['target']) + ' ' + chr(0) + '{:5.1f}/{:3f}'.format(data['tool0']['actual'], data['tool0']['target']))
def on_printer_received_registered_message(name, output):
pass
def on_printer_send_current_data(data):
self._lcd.cursor_pos = (0,0)
self._lcd.write_string(data['state']['text'].center(20))
def on_printer_send_initial_data(data):
self._lcd.clear()