Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to draw QR codes #156

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

mphasize
Copy link

@mphasize mphasize commented Jan 1, 2023

Hi, this PR attempts to add a new function to draw QR codes on the OLED display. It builds on the external dependency qrlite to generate the QR codes and then draws them with a little frame on the display.

Here's the documentation I added to the README file.

drawQRCode

Draws a QR code with a frame around it on the display. Needs the optional dependency qr-image to be installed for generating the QR code as a bitmap. In testing only the error correction level "Q" produces working QR codes and only strings are accepted as data for the QR code.

Arguments:

  • int x - x of QR code (including margin)
  • int y - y of QR code (including margin)
  • string data - data string to be encoded, i.e. a URL
  • int margin - thickness of the frame/margin around the QR code, default is 4

Optional bool as last argument specifies whether screen updates immediately with result. Default is true.

Usage:

// args: (x, y, data, margin)
oled.drawQRCode(10, 10, "http://example.com", 5);

This PR builds on top of my other PR and is not cleanly isolated. Please consider it as a proposal and, if interesting, I'm happy to clean up the PR. If such a function is considered out of scope, you can also just close the PR.

…ith multiple boards.

When working with multiple boards, Johnny Five can get confused which board to use. By using the optional `board` parameter and passing the board variable used to initialize Oled, we can fix that.
When building the Johnny Fives types, we get the error:

```
node_modules/@types/johnny-five/index.d.ts:663:21 - error TS1005: ',' expected.
663     song: [frequency: string | null, duration: number][];
```

Upgrading to Typescript 4.x solves this issue.
When building with Typescript 4 we get the following build error for all private properties and functions:

```
oled.ts - error TS4094: Property '[all private variables and functions]' of exported class expression may not be private or protected.
```

If I read this issue correctly, the `private` definition is not really supported, so I'm commenting it out for now.
We need the build output in order to reference this branch directly in a package.json file. If the PR is merged and released, these files can be removed again.
Since the most current version of serialport is >10 and the serialport dependency seems to be unused in this repo, let's remove it.
If we want to optimize drawing calls, we can use the sync/immediate flag to turn immediate updates off and then only update changes bytes in the last drawing call. However, instead of always checking the flag on the last call, we could also use the updateDirty method as the last function call which would make fiddling with other draw calls a little easier.
…m on the display

Uses an optional dependency `qrlite` to encode the data string as a QR bitmap.
@mphasize mphasize marked this pull request as draft January 1, 2023 16:45
It seems like qrlite would produce invalid QR codes as not all codes I tried where recognized. The qr-image library seems to work more reliably.
@mphasize mphasize marked this pull request as ready for review January 1, 2023 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant