Skip to content

add tm1637 7-segment LED display - #1677

Open
stc1988 wants to merge 2 commits into
Moddable-OpenSource:publicfrom
stc1988:driver/tm1637
Open

add tm1637 7-segment LED display#1677
stc1988 wants to merge 2 commits into
Moddable-OpenSource:publicfrom
stc1988:driver/tm1637

Conversation

@stc1988

@stc1988 stc1988 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

I confirmed with Seed 4-Digit Display.

@stc1988

stc1988 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author
trim.1D3B2A9E-5839-4F0A-8DAC-D4E91ADAFFB2.MOV

@phoddie phoddie left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks really good and follows the ECMA-419 conventions well.

I added some comments for your consideration.

Comment on lines +194 to +195
if (typeof string !== "string")
string = String(string);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The typeof check isn't necessary - faster and smaller to unconditionally call String()

}

#stopScroll() {
if (this.#timer) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is safe to call Timer.clear() on undefined, so this if is unnecessary

}
}
catch (e) {
this.#onError?.(e);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically this is not ECMA-419 style becauseonError() can be invoked from the public write() API. You can just throw here, since write() throwing is normal error behavior. But from the scrolling callback, you cannot throw since there is no one to catch, so your only options is to call onError(). You could do that in your timer callback, by catching errors thrown by #render() and rerouting them to #onError().

Comment on lines +111 to +112
const digits = options.digits ?? 4;
if (!Number.isInteger(digits) || (digits < 1) || (digits > MAX_DIGITS))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaScript builtins that accept a number for an integer generally round the number rather than throwing if there is a fractional part. Maybe change to const digits = Math.round(options.digits) ?? 4 instead.

...ioOptions,
pin: clock,
mode: Digital.OutputOpenDrain,
initialValue: 1

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of new initialValue property!

Comment on lines +116 to +121
if (undefined !== options.rate)
this.#rate = Math.max(50, options.rate | 0);
if (undefined !== options.direction)
this.#direction = (options.direction === -1) ? -1 : 1;
if (undefined !== options.brightness)
this.#brightness = Math.max(0, Math.min(7, options.brightness | 0));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you move this down further in constructor, you might just be able to do this.configure(options); though... arguably these should not be options to the constructor, and the app should call configure() separately. (This guide hints at that, but as an implementation guide, rather than an API design guide, it doesn't go into details).

@stc1988

stc1988 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for the review. I had AI check whether the implementation followed the Guide, but it seems to have missed it. As for onError, the same can be said for qwiic_alphanumeric.js, which I used as a reference.

I have addressed the points you pointed out, so could you please check them?

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.

2 participants