From 1159205dcc7ec787c40e30b1397f9f6f859e236f Mon Sep 17 00:00:00 2001 From: Peter Hinch Date: Mon, 2 Nov 2020 16:30:46 +0000 Subject: [PATCH] Warn but run normally if framebuf_utils.mpy is for incorrect arch. --- writer/WRITER.md | 9 +++++++-- writer/writer.py | 29 +++++++---------------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/writer/WRITER.md b/writer/WRITER.md index 7e00f38..20e7999 100644 --- a/writer/WRITER.md +++ b/writer/WRITER.md @@ -258,8 +258,10 @@ is a way to improve performance. It was developed by Jim Mussared (@jimmo) and consists of a native C module. On import, `writer.py` attempts to import a module `framebuf_utils`. If this -succeeds (i.e. a file `framebuf_utils.mpy` is found), glyph rendering will be -substantially faster. +succeeds, glyph rendering will be substantially faster. If the file is not +present the class will work using normal rendering. If the file exists but was +compiled for a different architecture a warning message will be printed but the +class will work using normal rendering. The directory `framebuf_utils` contains the source file, the makefile and a version of `framebuf_utils.mpy` for `armv7m` architecture (e.g. Pyboards). @@ -273,6 +275,9 @@ The native module does not support the `CWriter.invert_display` option. If this is used, the presence of the native module will have no effect. The module has no effect on the `Writer` class which uses fast rendering by default. +The module has a `fast_mode` variable which is set `True` on import if the mode +was successfully engaged. User code should treat this as read-only. + # 3. Notes Possible future enhancements: diff --git a/writer/writer.py b/writer/writer.py index 3c7dd8d..9d11189 100644 --- a/writer/writer.py +++ b/writer/writer.py @@ -2,27 +2,8 @@ # V0.35 Peter Hinch Sept 2020 Fast rendering option for color displays # Handles colour, upside down diplays, word wrap and tab stops -# The MIT License (MIT) -# -# Copyright (c) 2016-2020 Peter Hinch -# -# 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 -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. +# Released under the MIT License (MIT). See LICENSE. +# Copyright (c) 2019-2020 Peter Hinch # A Writer supports rendering text to a Display instance in a given font. # Multiple Writer instances may be created, each rendering a font to the @@ -38,11 +19,15 @@ # Slow method 2700μs typical, up to 11ms on larger fonts import framebuf +fast_mode = False try: from framebuf_utils import render fast_mode = True except ImportError: - fast_mode = False + pass +except ValueError: + print('Ignoring framebuf_utils.mpy: it was compiled for an incorrect architecture.') + from uctypes import bytearray_at, addressof class DisplayState():