Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: whitequark/glasgow
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d20f0d490a9d
Choose a base ref
...
head repository: whitequark/glasgow
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 44f9b182e953
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Mar 4, 2019

  1. Copy the full SHA
    ab19c43 View commit details
  2. Copy the full SHA
    44f9b18 View commit details
Showing with 39 additions and 17 deletions.
  1. +39 −17 software/glasgow/applet/display/pdi/__init__.py
56 changes: 39 additions & 17 deletions software/glasgow/applet/display/pdi/__init__.py
Original file line number Diff line number Diff line change
@@ -43,6 +43,14 @@
# the odd lines and then even lines leads to ghosting. It appears that the display has some
# logic dependent on scan order, in spite of the scan bytes seemingly implying that the drivers
# can be scanned in any desired order.
#
# * The staging differs from that described in the datasheet in two aspects. First, there is no
# Compensate stage, since the applet can't know what the old image was. Second, the datasheet
# suggests White→Inverse→Normal staging. My experimentation shows that a different staging,
# Black→White→Normal→Normal (with two Normal frames, not one Normal frame that's twice as
# long!), produces significantly higher contrast, and an even longer staging, Black→White→
# Black→White→Normal→Normal has higher contrast and reduced ghosting. I'm guessing these
# would be more unpleasant on something like a ebook reader.

import math
import re
@@ -390,28 +398,42 @@ async def run(self, device, args):

@classmethod
def add_interact_arguments(cls, parser):
parser.add_argument(
"image_file", metavar="IMAGE-FILE", type=argparse.FileType("rb"),
g_pattern = parser.add_mutually_exclusive_group(required=True)
g_pattern.add_argument(
"--checkerboard", default=False, action="store_true",
help="display a checkerboard pattern")
g_pattern.add_argument(
"image_file", metavar="IMAGE-FILE", type=argparse.FileType("rb"), nargs="?",
help="image file to display (format: pbm)")

async def interact(self, device, args, pdi_iface):
image_header = args.image_file.readline()
if image_header != b"P4\n":
raise GlasgowAppletError("image file is not a raw PBM file")
image_comment = args.image_file.readline()
image_size = re.match(rb"^(\d+) (\d+)$", args.image_file.readline())
if not image_size:
raise GlasgowAppletError("image file is corrupt")
image_width, image_height = int(image_size[1]), int(image_size[2])
if image_width != pdi_iface.width or image_height != pdi_iface.height:
raise GlasgowAppletError("image size does not match display size")
image = bitarray()
image.frombytes(args.image_file.read())
if args.checkerboard:
image = bitarray(([0,0,1,1] * (pdi_iface.width // 2) +
[1,1,0,0] * (pdi_iface.width // 2))
* (pdi_iface.height // 4))

if args.image_file:
image_header = args.image_file.readline()
if image_header != b"P4\n":
raise GlasgowAppletError("image file is not a raw PBM file")
image_comment = args.image_file.readline()
image_size = re.match(rb"^(\d+) (\d+)$", args.image_file.readline())
if not image_size:
raise GlasgowAppletError("image file is corrupt")
image_width, image_height = int(image_size[1]), int(image_size[2])
if image_width != pdi_iface.width or image_height != pdi_iface.height:
raise GlasgowAppletError("image size does not match display size")
image = bitarray()
image.frombytes(args.image_file.read())

stage_ms = 300

await pdi_iface.power_on()
await pdi_iface.display_frame(mode="black", time_ms=100)
await pdi_iface.display_frame(mode="white", time_ms=100)
await pdi_iface.display_frame(mode="white", time_ms=100, image=image)
for _ in range(2):
await pdi_iface.display_frame(mode="black", time_ms=stage_ms)
await pdi_iface.display_frame(mode="white", time_ms=stage_ms)
await pdi_iface.display_frame(mode="white", time_ms=stage_ms, image=image)
await pdi_iface.display_frame(mode="white", time_ms=stage_ms, image=image)
await pdi_iface.power_off()

# -------------------------------------------------------------------------------------------------