From 6feb61dfc6b21ec53160d41955658d4a6cfca074 Mon Sep 17 00:00:00 2001 From: STC Date: Sun, 21 Dec 2025 23:51:04 +0900 Subject: [PATCH 1/8] Add typings for neopixel and neostrand --- typings/neopixel.d.ts | 44 ++++++++++++ typings/neostrand.d.ts | 160 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 204 insertions(+) create mode 100644 typings/neopixel.d.ts create mode 100644 typings/neostrand.d.ts diff --git a/typings/neopixel.d.ts b/typings/neopixel.d.ts new file mode 100644 index 000000000..5ae495ee9 --- /dev/null +++ b/typings/neopixel.d.ts @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2025 Satoshi Tanaka +* +* This file is part of the Moddable SDK Tools. +* +* The Moddable SDK Tools is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* The Moddable SDK Tools is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with the Moddable SDK Tools. If not, see . +* +*/ + +declare module "neopixel" { + class NeoPixel { + constructor(optios?: { + pin?: number, + length?: number, + order?: string + }); + + close(): void; + update(): void; + + makeRGB(r: number, g: number, b: number): number; + makeHSB(h: number, s: number, b: number): number; + setPixel(index: number, color: number): void; + fill(color: number, index?: number, count?: number): void; + getPixel(index: number): number; + + get brightness(): number; + set brightness(value: number); + get length(): number; + get byteLength(): number; + } + export default NeoPixel; +} diff --git a/typings/neostrand.d.ts b/typings/neostrand.d.ts new file mode 100644 index 000000000..c78baf595 --- /dev/null +++ b/typings/neostrand.d.ts @@ -0,0 +1,160 @@ +/* +* Copyright (c) 2025 Satoshi Tanaka +* +* This file is part of the Moddable SDK Tools. +* +* The Moddable SDK Tools is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* The Moddable SDK Tools is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with the Moddable SDK Tools. If not, see . +* +*/ + +declare module "neostrand" { + import type NeoPixel from "neopixel"; + + type NeoStrandEffectDictionary = { + strand: NeoStrand; + start?: number; + end?: number; + reverse?: 0 | 1; + duration?: number; + position?: number; + speed?: number; + size?: number; + loop?: 0 | 1; + tickle?: number; + onComplete?: (effect: NeoStrandEffect) => void; + } + + class NeoStrandEffect { + constructor(dictionary: NeoStrandEffectDictionary); + + reset(effect: NeoStrandEffect): void; + loopPrepare(effect: NeoStrandEffect): void; + activate(effect: NeoStrandEffect): void; + idle(effect: NeoStrandEffect, ticks: number): void; + } + + class HueSpan extends NeoStrandEffect { + constructor(dictionary: NeoStrandEffectDictionary & { + position?: number; + saturation?: number; + value?: number; + }); + + set hue(h: number); + } + + class Sine extends NeoStrandEffect { + constructor(dictionary: NeoStrandEffectDictionary & { + amplitude?: number; + offset?: number; + vary?: "r" | "g" | "b" | "h" | "s" | "v"; + }); + + set effectValue(value: number); + } + + interface rgb { + r: number; + g: number; + b: number; + } + class Marquee extends NeoStrandEffect { + constructor(dictionary: NeoStrandEffectDictionary & { + sizeA?: number; + sizeB?: number; + rgbA?: rgb; + rgbB?: rgb; + }); + + set steps(s: number); + } + + class Pulse extends NeoStrandEffect { + constructor(dictionary: NeoStrandEffectDictionary & { + dir?: number; + mode?: -1 | 0 | 1; + fade?: number; + size?: number; + duration?: number; + position?: "random" | number; + rgb?: rgb; + }); + + loopPrepare(effect: NeoStrandEffect): void; + set pulseLoc(px: number); + } + + class Pattern extends NeoStrandEffect { + constructor(dictionary: NeoStrandEffectDictionary & { + pattern?: number[]; + mode?: -1 | 0 | 1; + }); + + loopPrepare(effect: NeoStrandEffect): void; + set effectValue(value: number); + } + + class Dim extends NeoStrandEffect { + constructor(dictionary: NeoStrandEffectDictionary & { + rgb?: rgb; + }); + } + + class Ease extends NeoStrandEffect { + constructor(dictionary: NeoStrandEffectDictionary & { + easing?: number; + size?: number; + rgb?: rgb; + }); + + set steps(s: number); + } + + interface PulseTiming { + level0: 0 | 1; + duration0: number; + level1: 0 | 1; + duration1: number; + } + + class NeoStrand extends NeoPixel { + constructor(optios?: { + pin?: number, + length?: number, + order?: string, + timeings?: { + mark: PulseTiming, + space: PulseTiming, + reset: PulseTiming + } + }); + + add(idx: number, color: number, start?: number, end?: number): void; + sub(idx: number, color: number, start?: number, end?: number): void; + op(idx: number, rgb: number, mode: number, start: number, end: number): void; + setScheme(scheme: NeoStrandEffect[]): void; + start(ms?: number): void; + stop(): void; + hsvToRgb(h: number, s: number, v: number): number; + rgbToHsv(r: number, g: number, b: number): { h: number; s: number; v: number }; + + static HueSpan: HueSpan; + static Sine: Sine; + static Marquee: Marquee; + static Pulse: Pulse; + static Pattern: Pattern; + static Dim: Dim; + static Ease: Ease; + } +} From e89df67be036a096388b37eb6c9a6b10f05345cf Mon Sep 17 00:00:00 2001 From: STC Date: Tue, 23 Dec 2025 08:34:27 +0900 Subject: [PATCH 2/8] fix typo --- typings/neopixel.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/neopixel.d.ts b/typings/neopixel.d.ts index 5ae495ee9..a898ed23a 100644 --- a/typings/neopixel.d.ts +++ b/typings/neopixel.d.ts @@ -20,7 +20,7 @@ declare module "neopixel" { class NeoPixel { - constructor(optios?: { + constructor(options?: { pin?: number, length?: number, order?: string From e7654010500bb2905efd65484fa07e6c35a9f9c6 Mon Sep 17 00:00:00 2001 From: STC Date: Tue, 23 Dec 2025 08:42:31 +0900 Subject: [PATCH 3/8] fix typo --- typings/neostrand.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/neostrand.d.ts b/typings/neostrand.d.ts index c78baf595..0ca57e029 100644 --- a/typings/neostrand.d.ts +++ b/typings/neostrand.d.ts @@ -129,7 +129,7 @@ declare module "neostrand" { } class NeoStrand extends NeoPixel { - constructor(optios?: { + constructor(options?: { pin?: number, length?: number, order?: string, From 96cabeb1e8e8cb39d9d8b8ccc4e6a869e87e88e4 Mon Sep 17 00:00:00 2001 From: STC Date: Tue, 23 Dec 2025 20:52:47 +0900 Subject: [PATCH 4/8] NeoPixel extends HostBuffer --- typings/neopixel.d.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/typings/neopixel.d.ts b/typings/neopixel.d.ts index a898ed23a..2f9f96087 100644 --- a/typings/neopixel.d.ts +++ b/typings/neopixel.d.ts @@ -19,7 +19,7 @@ */ declare module "neopixel" { - class NeoPixel { + class NeoPixel extends HostBuffer { constructor(options?: { pin?: number, length?: number, @@ -38,7 +38,6 @@ declare module "neopixel" { get brightness(): number; set brightness(value: number); get length(): number; - get byteLength(): number; } export default NeoPixel; } From f638fa5da83051cedcc28ea44912876d59b51db2 Mon Sep 17 00:00:00 2001 From: STC Date: Tue, 23 Dec 2025 22:18:44 +0900 Subject: [PATCH 5/8] add set function to NeoStrand --- typings/neostrand.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/typings/neostrand.d.ts b/typings/neostrand.d.ts index 0ca57e029..6f1abba7b 100644 --- a/typings/neostrand.d.ts +++ b/typings/neostrand.d.ts @@ -140,6 +140,7 @@ declare module "neostrand" { } }); + set(idx: number, color: number, start?: number, end?: number): void; add(idx: number, color: number, start?: number, end?: number): void; sub(idx: number, color: number, start?: number, end?: number): void; op(idx: number, rgb: number, mode: number, start: number, end: number): void; From 474281921984d3438b7535fe66304c636e79f4c3 Mon Sep 17 00:00:00 2001 From: STC Date: Wed, 24 Dec 2025 22:01:47 +0900 Subject: [PATCH 6/8] fix typo --- typings/neostrand.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/neostrand.d.ts b/typings/neostrand.d.ts index 6f1abba7b..6c9ca3096 100644 --- a/typings/neostrand.d.ts +++ b/typings/neostrand.d.ts @@ -133,7 +133,7 @@ declare module "neostrand" { pin?: number, length?: number, order?: string, - timeings?: { + timing?: { mark: PulseTiming, space: PulseTiming, reset: PulseTiming From ee62d2da39f227974aa680e66aeb4adbe9461c42 Mon Sep 17 00:00:00 2001 From: STC Date: Wed, 24 Dec 2025 22:14:08 +0900 Subject: [PATCH 7/8] Fix static type declarations --- typings/neostrand.d.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/typings/neostrand.d.ts b/typings/neostrand.d.ts index 6c9ca3096..1fb563c2c 100644 --- a/typings/neostrand.d.ts +++ b/typings/neostrand.d.ts @@ -150,12 +150,12 @@ declare module "neostrand" { hsvToRgb(h: number, s: number, v: number): number; rgbToHsv(r: number, g: number, b: number): { h: number; s: number; v: number }; - static HueSpan: HueSpan; - static Sine: Sine; - static Marquee: Marquee; - static Pulse: Pulse; - static Pattern: Pattern; - static Dim: Dim; - static Ease: Ease; + static HueSpan: typeof HueSpan; + static Sine: typeof Sine; + static Marquee: typeof Marquee; + static Pulse: typeof Pulse; + static Pattern: typeof Pattern; + static Dim: typeof Dim; + static Ease: typeof Ease; } } From 38054a5d3f9059f02dc77e5439679e437d9c2096 Mon Sep 17 00:00:00 2001 From: STC Date: Sun, 28 Dec 2025 20:16:04 +0900 Subject: [PATCH 8/8] add properties to NeoStrandEffect --- typings/neostrand.d.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/typings/neostrand.d.ts b/typings/neostrand.d.ts index 1fb563c2c..ebe1b329e 100644 --- a/typings/neostrand.d.ts +++ b/typings/neostrand.d.ts @@ -20,8 +20,9 @@ declare module "neostrand" { import type NeoPixel from "neopixel"; + import type Timeline from "piu/Timeline"; - type NeoStrandEffectDictionary = { + export type NeoStrandEffectDictionary = { strand: NeoStrand; start?: number; end?: number; @@ -32,10 +33,20 @@ declare module "neostrand" { size?: number; loop?: 0 | 1; tickle?: number; + onComplete?: (effect: NeoStrandEffect) => void; } - class NeoStrandEffect { + export class NeoStrandEffect { + name: string; + strand: NeoStrand; + start: number; + end: number + size: number; + dur: number; + reverse: 0 | 1; + loop: 0 | 1; + timeline: Timeline; constructor(dictionary: NeoStrandEffectDictionary); reset(effect: NeoStrandEffect): void; @@ -128,7 +139,7 @@ declare module "neostrand" { duration1: number; } - class NeoStrand extends NeoPixel { + export class NeoStrand extends NeoPixel { constructor(options?: { pin?: number, length?: number, @@ -158,4 +169,5 @@ declare module "neostrand" { static Dim: typeof Dim; static Ease: typeof Ease; } + }