This repository was archived by the owner on Dec 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 131
support for LED driver + simulation #580
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
cfd7a63
some renamings
pelikhan 8667908
Merge remote-tracking branch 'origin/main' into ledserver
pelikhan f561c26
adding led driver
pelikhan 7c96ddb
unused function
pelikhan 08570a1
more led functionalities
pelikhan 8e26d9f
porting some function
pelikhan 654f73c
fixed setall
pelikhan 49369ee
add large number of LEDs example
pelikhan 41ea226
send image buffer if needed
pelikhan 0ec4ec7
add TODO
pelikhan 56e84f1
docs on socket limitations
pelikhan 769b5ab
move display dimmer
pelikhan 8334918
fix weird verif error
pelikhan 7d52c5f
fix samples
pelikhan ea406ab
test verification
pelikhan 7ab1ee0
undo
pelikhan 88b4261
updated jacdac-ts
pelikhan d82d1d4
added LED display
pelikhan 6acabfc
allocate palette auto
pelikhan 0072b8d
move to functions for tree shacking
pelikhan 3f8e12a
add gamma correction
pelikhan 3b1635e
split led display
pelikhan 90ce385
reduce import sizes
pelikhan 6116501
move led to runtime
pelikhan 06c24f7
Merge remote-tracking branch 'origin/main' into ledserver
pelikhan 8fc0c9c
getting started on docs
pelikhan 2c57c90
more docs
pelikhan 3954a1c
more docs
pelikhan 50f9069
more docs
pelikhan 2f8c04a
reorg docs
pelikhan d0956c3
fix sample
pelikhan a0571e2
little disclaimer
pelikhan c0e212d
fix sample
pelikhan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| import * as ds from "@devicescript/core" | ||
| import { | ||
| PixelBuffer, | ||
| fillFade, | ||
| pixelBuffer, | ||
| correctGamma, | ||
| } from "@devicescript/runtime" | ||
| import { Server, ServerOptions, startServer } from "@devicescript/server" | ||
|
|
||
| export interface LedServerOptions { | ||
| /** | ||
| * Number of LEDs | ||
| */ | ||
| length: number | ||
| /** | ||
| * Brightness applied to pixels before being rendered. | ||
| * This allocate twice the memory if less than 1 as an additional buffer is needed to compute the color. | ||
| * @default 1 | ||
| */ | ||
| intensity?: number | ||
| /** | ||
| * Number of columns of a LED matrix | ||
| */ | ||
| columns?: number | ||
| ledsPerPixel?: number | ||
| /** | ||
| * For monochrome LEDs, the LED wavelength | ||
| */ | ||
| waveLength?: number | ||
| /** | ||
| * The luminous power of the LEDs, is it very bright? | ||
| */ | ||
| luminousIntensity?: number | ||
| /** | ||
| * The shape and topology of the LEDs | ||
| */ | ||
| variant?: ds.LedVariant | ||
| /** | ||
| * Specify the amount of gamma correction | ||
| */ | ||
| gamma?: number | ||
| } | ||
|
|
||
| class LedServer extends Server implements ds.LedServerSpec { | ||
| private _intensity: number | ||
| private _columns: number | ||
| private _ledPerPixels: number | ||
| private _waveLength: number | ||
| private _luminousIntensity: number | ||
| private _variant: ds.LedVariant | ||
| private _gamma: number | ||
|
|
||
| readonly buffer: PixelBuffer | ||
|
|
||
| constructor(options: LedServerOptions & ServerOptions) { | ||
| super(ds.Led.spec, options) | ||
| this.buffer = pixelBuffer(options.length) | ||
| this._intensity = options.intensity ?? 1 | ||
| this._columns = options.columns | ||
| this._ledPerPixels = options.ledsPerPixel | ||
| this._waveLength = options.waveLength | ||
| this._luminousIntensity = options.luminousIntensity | ||
| this._variant = options.variant | ||
| this._gamma = options.gamma | ||
| } | ||
|
|
||
| pixels(): ds.Buffer { | ||
| if (this.buffer.length < 64) return this.buffer.buffer | ||
| else return Buffer.alloc(0) | ||
| } | ||
| set_pixels(value: ds.Buffer): void { | ||
| this.buffer.buffer.blitAt(0, value, 0, value.length) | ||
| } | ||
| intensity(): number { | ||
| return this._intensity | ||
| } | ||
| set_intensity(value: number): void { | ||
| this._intensity = Math.clamp(0, value, 1) | ||
| } | ||
| actualBrightness(): number { | ||
| return this._intensity | ||
| } | ||
| numPixels(): number { | ||
| return this.buffer.length | ||
| } | ||
| numColumns(): number { | ||
| return this._columns | ||
| } | ||
| ledsPerPixel(): number { | ||
| return this._ledPerPixels | ||
| } | ||
| waveLength(): number { | ||
| return this._waveLength || 0 | ||
| } | ||
| luminousIntensity(): number { | ||
| return this._luminousIntensity | ||
| } | ||
| variant(): ds.LedVariant { | ||
| return this._variant | ||
| } | ||
|
|
||
| /** | ||
| * Display buffer on hardware | ||
| */ | ||
| async show(): Promise<void> { | ||
| let b = this.buffer | ||
| // full brightness so we can use the buffer as is | ||
| if (this._intensity < 1 || this._gamma) { | ||
| const r = b.allocClone() | ||
| if (this._intensity < 1) fillFade(r, this._intensity) | ||
| if (this._gamma) correctGamma(r, this._gamma) | ||
| b = r | ||
| } | ||
| // TODO: render b to hardware | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Starts a programmable LED server. | ||
| * Simulation is supported for up to 64 LEDs; otherwise only the simulator | ||
| * will reflect the state of LEDs. | ||
| * @param options | ||
| * @returns | ||
| */ | ||
| export async function startLed( | ||
| options: LedServerOptions & ServerOptions | ||
| ): Promise<ds.Led> { | ||
| const { length } = options | ||
| const server = new LedServer(options) | ||
| const client = new ds.Led(startServer(server)) | ||
|
|
||
| ;(client as any)._buffer = server.buffer | ||
| client.show = async function () { | ||
| await server.show() | ||
| if (length <= 64) await client.pixels.write(server.buffer.buffer) | ||
| else if (ds.isSimulator()) { | ||
| // the simulator handles brightness separately | ||
| const topic = `jd/${server.serviceIndex}/leds` | ||
| await ds._twinMessage(topic, server.buffer.buffer) | ||
| } | ||
| } | ||
|
|
||
| return client | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mmoskal this is the part missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not anymore :) https://github.com/microsoft/devicescript/blob/main/packages/drivers/src/ledserver.ts#L159 - added it a couple days ago