create-mikrojs 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +0 -9
- package/dist/index.js.map +1 -1
- package/dist/inspect.js +0 -1
- package/dist/inspect.js.map +1 -1
- package/dist/scaffold.d.ts +0 -1
- package/dist/scaffold.d.ts.map +1 -1
- package/dist/scaffold.js +17 -17
- package/dist/scaffold.js.map +1 -1
- package/dist/scaffold.test.js +113 -95
- package/dist/scaffold.test.js.map +1 -1
- package/dist/templates/_common/dependencies.d.ts +1 -0
- package/dist/templates/_common/dependencies.d.ts.map +1 -1
- package/dist/templates/_common/dependencies.js +1 -0
- package/dist/templates/_common/dependencies.js.map +1 -1
- package/dist/templates/_common/eslint-config.d.ts +1 -1
- package/dist/templates/_common/eslint-config.d.ts.map +1 -1
- package/dist/templates/_common/eslint-config.js +10 -4
- package/dist/templates/_common/eslint-config.js.map +1 -1
- package/dist/templates/_common/mikro-config.d.ts +2 -0
- package/dist/templates/_common/mikro-config.d.ts.map +1 -0
- package/dist/templates/_common/mikro-config.js +6 -0
- package/dist/templates/_common/mikro-config.js.map +1 -0
- package/dist/templates/_common/package-json.d.ts +12 -12
- package/dist/templates/_common/package-json.d.ts.map +1 -1
- package/dist/templates/_common/package-json.js +10 -16
- package/dist/templates/_common/package-json.js.map +1 -1
- package/dist/templates/_common/prettier-config.d.ts +2 -0
- package/dist/templates/_common/prettier-config.d.ts.map +1 -0
- package/dist/templates/_common/prettier-config.js +5 -0
- package/dist/templates/_common/prettier-config.js.map +1 -0
- package/dist/templates/_common/tsconfig.d.ts +1 -2
- package/dist/templates/_common/tsconfig.d.ts.map +1 -1
- package/dist/templates/_common/tsconfig.js +32 -25
- package/dist/templates/_common/tsconfig.js.map +1 -1
- package/dist/templates/sntp/mikro.config.d.ts.map +1 -1
- package/dist/templates/sntp/mikro.config.js +3 -2
- package/dist/templates/sntp/mikro.config.js.map +1 -1
- package/dist/templates/wifi-access-point/mikro.config.d.ts.map +1 -1
- package/dist/templates/wifi-access-point/mikro.config.js +3 -2
- package/dist/templates/wifi-access-point/mikro.config.js.map +1 -1
- package/dist/templates/wifi-fetch/mikro.config.d.ts.map +1 -1
- package/dist/templates/wifi-fetch/mikro.config.js +3 -2
- package/dist/templates/wifi-fetch/mikro.config.js.map +1 -1
- package/package.json +6 -2
- package/src/templates/_common/dependencies.ts +1 -0
- package/src/templates/_common/eslint-config.ts +10 -4
- package/src/templates/_common/mikro-config.ts +5 -0
- package/src/templates/_common/package-json.ts +9 -18
- package/src/templates/_common/prettier-config.ts +4 -0
- package/src/templates/_common/tsconfig.ts +31 -25
- package/src/templates/blank/app/main.ts +2 -2
- package/src/templates/blinky/app/main.ts +9 -9
- package/src/templates/neopixel/app/color.ts +11 -11
- package/src/templates/neopixel/app/main.ts +14 -14
- package/src/templates/neopixel/app/patterns/breathe.ts +15 -15
- package/src/templates/neopixel/app/patterns/color-wipe.ts +20 -20
- package/src/templates/neopixel/app/patterns/comet.ts +20 -20
- package/src/templates/neopixel/app/patterns/rainbow.ts +15 -15
- package/src/templates/neopixel/app/patterns/sparkle.ts +16 -16
- package/src/templates/pwm-led/app/main.ts +9 -9
- package/src/templates/rtc-counter/app/main.ts +13 -11
- package/src/templates/sntp/app/main.ts +19 -17
- package/src/templates/sntp/env.d.ts +2 -2
- package/src/templates/sntp/mikro.config.ts +4 -3
- package/src/templates/wifi-access-point/app/main.ts +16 -16
- package/src/templates/wifi-access-point/mikro.config.ts +4 -3
- package/src/templates/wifi-fetch/app/main.ts +17 -17
- package/src/templates/wifi-fetch/env.d.ts +2 -2
- package/src/templates/wifi-fetch/mikro.config.ts +4 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package-json.js","sourceRoot":"","sources":["../../../src/templates/_common/package-json.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,WAAW,CACzB,IAAY,EACZ,EACE,eAAe,EACf,YAAY,
|
|
1
|
+
{"version":3,"file":"package-json.js","sourceRoot":"","sources":["../../../src/templates/_common/package-json.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,WAAW,CACzB,IAAY,EACZ,EACE,eAAe,EACf,YAAY,MAIV,EAAE;IAEN,OAAO;QACL,IAAI;QACJ,OAAO,EAAE,OAAO;QAChB,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,eAAe;QACrB,OAAO,EAAE;YACP,MAAM,EAAE,oBAAoB;YAC5B,cAAc,EAAE,oBAAoB;YACpC,IAAI,EAAE,UAAU;YAChB,SAAS,EAAE,uBAAuB;SACnC;QACD,YAAY,EAAE,YAAkB;QAChC,eAAe,EAAE,eAAqB;QACtC,OAAO,EAAE;YACP,SAAS,EAAE,CAAC,uBAAuB,CAAC;SACrC;KACoB,CAAA;AACzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prettier-config.d.ts","sourceRoot":"","sources":["../../../src/templates/_common/prettier-config.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,kCAG1B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prettier-config.js","sourceRoot":"","sources":["../../../src/templates/_common/prettier-config.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG;;;CAG7B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tsconfig.d.ts","sourceRoot":"","sources":["../../../src/templates/_common/tsconfig.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"tsconfig.d.ts","sourceRoot":"","sources":["../../../src/templates/_common/tsconfig.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CAAC,aAAa,GAAE,SAAS,MAAM,EAAO,GAAG,MAAM,CA4B1E"}
|
|
@@ -1,26 +1,33 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
export function tsconfigJson(extraIncludes = []) {
|
|
2
|
+
const includes = [...extraIncludes, 'mikro.config.ts', 'app/**/*'];
|
|
3
|
+
return `{
|
|
4
|
+
"include": ${inlineStringArray(includes)},
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"module": "nodenext",
|
|
7
|
+
"target": "es2024",
|
|
8
|
+
"lib": ${inlineStringArray(['es2024'])},
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
"types": ${inlineStringArray(['mikrojs/runtime'])},
|
|
11
|
+
"sourceMap": true,
|
|
12
|
+
"noUncheckedIndexedAccess": true,
|
|
13
|
+
"allowUnreachableCode": false,
|
|
14
|
+
"erasableSyntaxOnly": true,
|
|
15
|
+
"strict": true,
|
|
16
|
+
"verbatimModuleSyntax": true,
|
|
17
|
+
"isolatedModules": true,
|
|
18
|
+
"noUncheckedSideEffectImports": true,
|
|
19
|
+
"moduleDetection": "force",
|
|
20
|
+
"jsx": "preserve",
|
|
21
|
+
"skipLibCheck": true,
|
|
22
|
+
"noFallthroughCasesInSwitch": true,
|
|
23
|
+
"noUnusedLocals": true,
|
|
24
|
+
"forceConsistentCasingInFileNames": true,
|
|
25
|
+
"resolveJsonModule": true
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
}
|
|
30
|
+
function inlineStringArray(items) {
|
|
31
|
+
return `[${items.map((s) => JSON.stringify(s)).join(', ')}]`;
|
|
32
|
+
}
|
|
26
33
|
//# sourceMappingURL=tsconfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tsconfig.js","sourceRoot":"","sources":["../../../src/templates/_common/tsconfig.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tsconfig.js","sourceRoot":"","sources":["../../../src/templates/_common/tsconfig.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY,CAAC,gBAAmC,EAAE;IAChE,MAAM,QAAQ,GAAG,CAAC,GAAG,aAAa,EAAE,iBAAiB,EAAE,UAAU,CAAC,CAAA;IAClE,OAAO;eACM,iBAAiB,CAAC,QAAQ,CAAC;;;;aAI7B,iBAAiB,CAAC,CAAC,QAAQ,CAAC,CAAC;;eAE3B,iBAAiB,CAAC,CAAC,iBAAiB,CAAC,CAAC;;;;;;;;;;;;;;;;;;CAkBpD,CAAA;AACD,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAwB;IACjD,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAA;AAC9D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mikro.config.d.ts","sourceRoot":"","sources":["../../../src/templates/sntp/mikro.config.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"mikro.config.d.ts","sourceRoot":"","sources":["../../../src/templates/sntp/mikro.config.ts"],"names":[],"mappings":";;;;;AAGA,wBAGG"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { defineConfig } from
|
|
1
|
+
import { defineConfig } from "mikrojs";
|
|
2
|
+
// Project configuration. See https://mikrojs.dev/config for all options.
|
|
2
3
|
export default defineConfig({
|
|
3
4
|
// Set to your country code so WiFi uses the correct regulatory domain.
|
|
4
|
-
wifi: { country:
|
|
5
|
+
wifi: { country: "NO" },
|
|
5
6
|
});
|
|
6
7
|
//# sourceMappingURL=mikro.config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mikro.config.js","sourceRoot":"","sources":["../../../src/templates/sntp/mikro.config.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"mikro.config.js","sourceRoot":"","sources":["../../../src/templates/sntp/mikro.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,yEAAyE;AACzE,eAAe,YAAY,CAAC;IAC1B,uEAAuE;IACvE,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;CACxB,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mikro.config.d.ts","sourceRoot":"","sources":["../../../src/templates/wifi-access-point/mikro.config.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"mikro.config.d.ts","sourceRoot":"","sources":["../../../src/templates/wifi-access-point/mikro.config.ts"],"names":[],"mappings":";;;;;AAGA,wBAGG"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { defineConfig } from
|
|
1
|
+
import { defineConfig } from "mikrojs";
|
|
2
|
+
// Project configuration. See https://mikrojs.dev/config for all options.
|
|
2
3
|
export default defineConfig({
|
|
3
4
|
// Set to your country code so WiFi uses the correct regulatory domain.
|
|
4
|
-
wifi: { country:
|
|
5
|
+
wifi: { country: "NO" },
|
|
5
6
|
});
|
|
6
7
|
//# sourceMappingURL=mikro.config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mikro.config.js","sourceRoot":"","sources":["../../../src/templates/wifi-access-point/mikro.config.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"mikro.config.js","sourceRoot":"","sources":["../../../src/templates/wifi-access-point/mikro.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,yEAAyE;AACzE,eAAe,YAAY,CAAC;IAC1B,uEAAuE;IACvE,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;CACxB,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mikro.config.d.ts","sourceRoot":"","sources":["../../../src/templates/wifi-fetch/mikro.config.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"mikro.config.d.ts","sourceRoot":"","sources":["../../../src/templates/wifi-fetch/mikro.config.ts"],"names":[],"mappings":";;;;;AAGA,wBAGG"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { defineConfig } from
|
|
1
|
+
import { defineConfig } from "mikrojs";
|
|
2
|
+
// Project configuration. See https://mikrojs.dev/config for all options.
|
|
2
3
|
export default defineConfig({
|
|
3
4
|
// Set to your country code so WiFi uses the correct regulatory domain.
|
|
4
|
-
wifi: { country:
|
|
5
|
+
wifi: { country: "NO" },
|
|
5
6
|
});
|
|
6
7
|
//# sourceMappingURL=mikro.config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mikro.config.js","sourceRoot":"","sources":["../../../src/templates/wifi-fetch/mikro.config.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"mikro.config.js","sourceRoot":"","sources":["../../../src/templates/wifi-fetch/mikro.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,yEAAyE;AACzE,eAAe,YAAY,CAAC;IAC1B,uEAAuE;IACvE,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;CACxB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-mikrojs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Create a new Mikro.js project",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"esp32",
|
|
@@ -41,7 +41,11 @@
|
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/node": "^24.12.2",
|
|
44
|
-
"
|
|
44
|
+
"eslint": "^10.2.1",
|
|
45
|
+
"prettier": "^3.4.0",
|
|
46
|
+
"typescript": "^6.0.3",
|
|
47
|
+
"typescript-eslint": "^8.59.0",
|
|
48
|
+
"@mikrojs/eslint-plugin": "0.7.0"
|
|
45
49
|
},
|
|
46
50
|
"engines": {
|
|
47
51
|
"node": ">=24.0.0"
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
export const eslintConfig = `\
|
|
2
|
-
import js from
|
|
3
|
-
import mikrojs from
|
|
4
|
-
import tseslint from
|
|
2
|
+
import js from "@eslint/js";
|
|
3
|
+
import mikrojs from "@mikrojs/eslint-plugin";
|
|
4
|
+
import tseslint from "typescript-eslint";
|
|
5
5
|
|
|
6
6
|
export default [
|
|
7
7
|
js.configs.recommended,
|
|
8
8
|
...tseslint.configs.recommended,
|
|
9
|
+
{
|
|
10
|
+
files: ["**/*.ts", "**/*.tsx"],
|
|
11
|
+
languageOptions: {
|
|
12
|
+
parserOptions: { projectService: true },
|
|
13
|
+
},
|
|
14
|
+
},
|
|
9
15
|
...mikrojs.configs.recommended,
|
|
10
|
-
]
|
|
16
|
+
];
|
|
11
17
|
`
|
|
@@ -5,12 +5,9 @@ export function packageJson(
|
|
|
5
5
|
{
|
|
6
6
|
devDependencies,
|
|
7
7
|
dependencies,
|
|
8
|
-
typescript,
|
|
9
8
|
}: {
|
|
10
9
|
dependencies?: PackageJson['devDependencies']
|
|
11
10
|
devDependencies?: PackageJson['dependencies']
|
|
12
|
-
/** Include the tsc predeploy hook. */
|
|
13
|
-
typescript?: boolean
|
|
14
11
|
} = {},
|
|
15
12
|
) {
|
|
16
13
|
return {
|
|
@@ -19,22 +16,16 @@ export function packageJson(
|
|
|
19
16
|
private: true,
|
|
20
17
|
type: 'module',
|
|
21
18
|
main: './app/main.ts',
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
: {}),
|
|
19
|
+
scripts: {
|
|
20
|
+
format: 'prettier --write .',
|
|
21
|
+
'format:check': 'prettier --check .',
|
|
22
|
+
lint: 'eslint .',
|
|
23
|
+
typecheck: 'tsc --noEmit --pretty',
|
|
24
|
+
},
|
|
30
25
|
dependencies: dependencies as {},
|
|
31
26
|
devDependencies: devDependencies as {},
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
predeploy: ['tsc --noEmit --pretty'],
|
|
36
|
-
},
|
|
37
|
-
}
|
|
38
|
-
: {}),
|
|
27
|
+
mikrojs: {
|
|
28
|
+
predeploy: ['tsc --noEmit --pretty'],
|
|
29
|
+
},
|
|
39
30
|
} satisfies PackageJson
|
|
40
31
|
}
|
|
@@ -1,27 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
export function tsconfigJson(extraIncludes: readonly string[] = []): string {
|
|
2
|
+
const includes = [...extraIncludes, 'mikro.config.ts', 'app/**/*']
|
|
3
|
+
return `{
|
|
4
|
+
"include": ${inlineStringArray(includes)},
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"module": "nodenext",
|
|
7
|
+
"target": "es2024",
|
|
8
|
+
"lib": ${inlineStringArray(['es2024'])},
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
"types": ${inlineStringArray(['mikrojs/runtime'])},
|
|
11
|
+
"sourceMap": true,
|
|
12
|
+
"noUncheckedIndexedAccess": true,
|
|
13
|
+
"allowUnreachableCode": false,
|
|
14
|
+
"erasableSyntaxOnly": true,
|
|
15
|
+
"strict": true,
|
|
16
|
+
"verbatimModuleSyntax": true,
|
|
17
|
+
"isolatedModules": true,
|
|
18
|
+
"noUncheckedSideEffectImports": true,
|
|
19
|
+
"moduleDetection": "force",
|
|
20
|
+
"jsx": "preserve",
|
|
21
|
+
"skipLibCheck": true,
|
|
22
|
+
"noFallthroughCasesInSwitch": true,
|
|
23
|
+
"noUnusedLocals": true,
|
|
24
|
+
"forceConsistentCasingInFileNames": true,
|
|
25
|
+
"resolveJsonModule": true
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
`
|
|
29
|
+
}
|
|
2
30
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
compilerOptions: {
|
|
6
|
-
module: 'nodenext',
|
|
7
|
-
target: 'es2024',
|
|
8
|
-
lib: ['es2024'],
|
|
9
|
-
noEmit: true,
|
|
10
|
-
types: ['mikrojs/runtime'],
|
|
11
|
-
sourceMap: true,
|
|
12
|
-
noUncheckedIndexedAccess: true,
|
|
13
|
-
allowUnreachableCode: false,
|
|
14
|
-
erasableSyntaxOnly: true,
|
|
15
|
-
strict: true,
|
|
16
|
-
verbatimModuleSyntax: true,
|
|
17
|
-
isolatedModules: true,
|
|
18
|
-
noUncheckedSideEffectImports: true,
|
|
19
|
-
moduleDetection: 'force',
|
|
20
|
-
jsx: 'preserve',
|
|
21
|
-
skipLibCheck: true,
|
|
22
|
-
noFallthroughCasesInSwitch: true,
|
|
23
|
-
noUnusedLocals: true,
|
|
24
|
-
forceConsistentCasingInFileNames: true,
|
|
25
|
-
resolveJsonModule: true,
|
|
26
|
-
},
|
|
31
|
+
function inlineStringArray(items: readonly string[]): string {
|
|
32
|
+
return `[${items.map((s) => JSON.stringify(s)).join(', ')}]`
|
|
27
33
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {board, version} from
|
|
1
|
+
import { board, version } from "mikrojs/sys";
|
|
2
2
|
|
|
3
|
-
console.log(`Hello World from MikroJS v${version} (${board.name}@${board.chip}@${board.revision})`)
|
|
3
|
+
console.log(`Hello World from MikroJS v${version} (${board.name}@${board.chip}@${board.revision})`);
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {digitalWrite, pinMode} from
|
|
2
|
-
import {sleep} from
|
|
1
|
+
import { digitalWrite, pinMode } from "mikrojs/pin";
|
|
2
|
+
import { sleep } from "mikrojs/sleep";
|
|
3
3
|
|
|
4
|
-
let value: 0 | 1 = 0
|
|
4
|
+
let value: 0 | 1 = 0;
|
|
5
5
|
// GPIO 15 is the built-in LED on XIAO ESP32C6. Replace with your board's LED pin.
|
|
6
|
-
const PIN = 15
|
|
6
|
+
const PIN = 15;
|
|
7
7
|
|
|
8
|
-
pinMode(PIN,
|
|
8
|
+
pinMode(PIN, "OUTPUT").orPanic("Failed to configure LED pin");
|
|
9
9
|
|
|
10
10
|
while (true) {
|
|
11
|
-
value = value === 0 ? 1 : 0
|
|
12
|
-
const writeResult = digitalWrite(PIN, value)
|
|
11
|
+
value = value === 0 ? 1 : 0;
|
|
12
|
+
const writeResult = digitalWrite(PIN, value);
|
|
13
13
|
if (!writeResult.ok) {
|
|
14
|
-
console.error(
|
|
14
|
+
console.error("Write pin failed: %s", writeResult.error.name);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
await sleep(1000)
|
|
17
|
+
await sleep(1000);
|
|
18
18
|
}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
/** Convert HSV (h: 0–360, s: 0–1, v: 0–1) to RGB tuple */
|
|
2
2
|
export function hsv(h: number, s: number, v: number): [r: number, g: number, b: number] {
|
|
3
|
-
h = h % 360
|
|
4
|
-
const max = v * 255
|
|
5
|
-
const min = max * (1 - s)
|
|
6
|
-
const sector = Math.floor(h / 60)
|
|
7
|
-
const adj = ((max - min) * (h % 60)) / 60
|
|
3
|
+
h = h % 360;
|
|
4
|
+
const max = v * 255;
|
|
5
|
+
const min = max * (1 - s);
|
|
6
|
+
const sector = Math.floor(h / 60);
|
|
7
|
+
const adj = ((max - min) * (h % 60)) / 60;
|
|
8
8
|
|
|
9
9
|
switch (sector) {
|
|
10
10
|
case 0:
|
|
11
|
-
return [max, min + adj, min]
|
|
11
|
+
return [max, min + adj, min];
|
|
12
12
|
case 1:
|
|
13
|
-
return [max - adj, max, min]
|
|
13
|
+
return [max - adj, max, min];
|
|
14
14
|
case 2:
|
|
15
|
-
return [min, max, min + adj]
|
|
15
|
+
return [min, max, min + adj];
|
|
16
16
|
case 3:
|
|
17
|
-
return [min, max - adj, max]
|
|
17
|
+
return [min, max - adj, max];
|
|
18
18
|
case 4:
|
|
19
|
-
return [min + adj, min, max]
|
|
19
|
+
return [min + adj, min, max];
|
|
20
20
|
default:
|
|
21
|
-
return [max, min, max - adj]
|
|
21
|
+
return [max, min, max - adj];
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import {NeoPixel} from
|
|
1
|
+
import { NeoPixel } from "mikrojs/neopixel";
|
|
2
2
|
|
|
3
|
-
import {breathe} from
|
|
4
|
-
import {colorWipe} from
|
|
5
|
-
import {comet} from
|
|
6
|
-
import {rainbow} from
|
|
7
|
-
import {sparkle} from
|
|
3
|
+
import { breathe } from "./patterns/breathe.js";
|
|
4
|
+
import { colorWipe } from "./patterns/color-wipe.js";
|
|
5
|
+
import { comet } from "./patterns/comet.js";
|
|
6
|
+
import { rainbow } from "./patterns/rainbow.js";
|
|
7
|
+
import { sparkle } from "./patterns/sparkle.js";
|
|
8
8
|
|
|
9
|
-
const PIN = 8
|
|
10
|
-
const NUM_LEDS = 24
|
|
11
|
-
const BRIGHTNESS = 1
|
|
12
|
-
const PATTERN_DURATION = 8000
|
|
9
|
+
const PIN = 8;
|
|
10
|
+
const NUM_LEDS = 24;
|
|
11
|
+
const BRIGHTNESS = 1;
|
|
12
|
+
const PATTERN_DURATION = 8000;
|
|
13
13
|
|
|
14
|
-
const pixels = new NeoPixel(PIN, {count: NUM_LEDS})
|
|
14
|
+
const pixels = new NeoPixel(PIN, { count: NUM_LEDS });
|
|
15
15
|
|
|
16
|
-
const patterns = [rainbow, comet, breathe, sparkle, colorWipe]
|
|
16
|
+
const patterns = [rainbow, comet, breathe, sparkle, colorWipe];
|
|
17
17
|
|
|
18
18
|
while (true) {
|
|
19
19
|
for (const pattern of patterns) {
|
|
20
|
-
|
|
20
|
+
(await pattern(pixels, NUM_LEDS, BRIGHTNESS, PATTERN_DURATION)).orPanic(
|
|
21
21
|
`NeoPixel pattern ${pattern.name} failed`,
|
|
22
|
-
)
|
|
22
|
+
);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import type {NeoPixel} from
|
|
2
|
-
import {ok} from
|
|
3
|
-
import {sleep} from
|
|
1
|
+
import type { NeoPixel } from "mikrojs/neopixel";
|
|
2
|
+
import { ok } from "mikrojs/result";
|
|
3
|
+
import { sleep } from "mikrojs/sleep";
|
|
4
4
|
|
|
5
|
-
import {hsv} from
|
|
5
|
+
import { hsv } from "../color.js";
|
|
6
6
|
|
|
7
7
|
/** Breathe: all LEDs pulse a single color in and out */
|
|
8
8
|
export async function breathe(pixels: NeoPixel, numLeds: number, brightness: number, ms: number) {
|
|
9
|
-
const end = Date.now() + ms
|
|
10
|
-
let t = 0
|
|
9
|
+
const end = Date.now() + ms;
|
|
10
|
+
let t = 0;
|
|
11
11
|
while (Date.now() < end) {
|
|
12
|
-
const v = ((Math.sin(t) + 1) / 2) * brightness
|
|
13
|
-
const [r, g, b] = hsv(30, 1, v)
|
|
14
|
-
const fillResult = pixels.fill(r, g, b)
|
|
15
|
-
if (!fillResult.ok) return fillResult
|
|
16
|
-
const showResult = pixels.show()
|
|
17
|
-
if (!showResult.ok) return showResult
|
|
18
|
-
t += 0.06
|
|
19
|
-
await sleep(20)
|
|
12
|
+
const v = ((Math.sin(t) + 1) / 2) * brightness;
|
|
13
|
+
const [r, g, b] = hsv(30, 1, v);
|
|
14
|
+
const fillResult = pixels.fill(r, g, b);
|
|
15
|
+
if (!fillResult.ok) return fillResult;
|
|
16
|
+
const showResult = pixels.show();
|
|
17
|
+
if (!showResult.ok) return showResult;
|
|
18
|
+
t += 0.06;
|
|
19
|
+
await sleep(20);
|
|
20
20
|
}
|
|
21
|
-
return ok(undefined)
|
|
21
|
+
return ok(undefined);
|
|
22
22
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {NeoPixel} from
|
|
2
|
-
import {ok} from
|
|
3
|
-
import {sleep} from
|
|
1
|
+
import type { NeoPixel } from "mikrojs/neopixel";
|
|
2
|
+
import { ok } from "mikrojs/result";
|
|
3
|
+
import { sleep } from "mikrojs/sleep";
|
|
4
4
|
|
|
5
|
-
import {hsv} from
|
|
5
|
+
import { hsv } from "../color.js";
|
|
6
6
|
|
|
7
7
|
/** Color wipe: fill pixels one by one, then clear one by one */
|
|
8
8
|
export async function colorWipe(pixels: NeoPixel, numLeds: number, brightness: number, ms: number) {
|
|
@@ -10,26 +10,26 @@ export async function colorWipe(pixels: NeoPixel, numLeds: number, brightness: n
|
|
|
10
10
|
hsv(0, 1, brightness),
|
|
11
11
|
hsv(120, 1, brightness),
|
|
12
12
|
hsv(240, 1, brightness),
|
|
13
|
-
]
|
|
14
|
-
const end = Date.now() + ms
|
|
15
|
-
let ci = 0
|
|
13
|
+
];
|
|
14
|
+
const end = Date.now() + ms;
|
|
15
|
+
let ci = 0;
|
|
16
16
|
while (Date.now() < end) {
|
|
17
|
-
const [r, g, b] = colors[ci % colors.length]
|
|
17
|
+
const [r, g, b] = colors[ci % colors.length]!;
|
|
18
18
|
for (let i = 0; i < numLeds; i++) {
|
|
19
|
-
const pixelResult = pixels.setPixel(i, r, g, b)
|
|
20
|
-
if (!pixelResult.ok) return pixelResult
|
|
21
|
-
const showResult = pixels.show()
|
|
22
|
-
if (!showResult.ok) return showResult
|
|
23
|
-
await sleep(25)
|
|
19
|
+
const pixelResult = pixels.setPixel(i, r, g, b);
|
|
20
|
+
if (!pixelResult.ok) return pixelResult;
|
|
21
|
+
const showResult = pixels.show();
|
|
22
|
+
if (!showResult.ok) return showResult;
|
|
23
|
+
await sleep(25);
|
|
24
24
|
}
|
|
25
25
|
for (let i = 0; i < numLeds; i++) {
|
|
26
|
-
const pixelResult = pixels.setPixel(i, 0, 0, 0)
|
|
27
|
-
if (!pixelResult.ok) return pixelResult
|
|
28
|
-
const showResult = pixels.show()
|
|
29
|
-
if (!showResult.ok) return showResult
|
|
30
|
-
await sleep(25)
|
|
26
|
+
const pixelResult = pixels.setPixel(i, 0, 0, 0);
|
|
27
|
+
if (!pixelResult.ok) return pixelResult;
|
|
28
|
+
const showResult = pixels.show();
|
|
29
|
+
if (!showResult.ok) return showResult;
|
|
30
|
+
await sleep(25);
|
|
31
31
|
}
|
|
32
|
-
ci
|
|
32
|
+
ci++;
|
|
33
33
|
}
|
|
34
|
-
return ok(undefined)
|
|
34
|
+
return ok(undefined);
|
|
35
35
|
}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import type {NeoPixel} from
|
|
2
|
-
import {ok} from
|
|
3
|
-
import {sleep} from
|
|
1
|
+
import type { NeoPixel } from "mikrojs/neopixel";
|
|
2
|
+
import { ok } from "mikrojs/result";
|
|
3
|
+
import { sleep } from "mikrojs/sleep";
|
|
4
4
|
|
|
5
|
-
import {hsv} from
|
|
5
|
+
import { hsv } from "../color.js";
|
|
6
6
|
|
|
7
7
|
/** Comet: a bright head with a fading tail orbits the ring */
|
|
8
8
|
export async function comet(pixels: NeoPixel, numLeds: number, brightness: number, ms: number) {
|
|
9
|
-
const TAIL_LEN = 8
|
|
10
|
-
const end = Date.now() + ms
|
|
11
|
-
let pos = 0
|
|
9
|
+
const TAIL_LEN = 8;
|
|
10
|
+
const end = Date.now() + ms;
|
|
11
|
+
let pos = 0;
|
|
12
12
|
while (Date.now() < end) {
|
|
13
|
-
const fillResult = pixels.fill(0, 0, 0)
|
|
14
|
-
if (!fillResult.ok) return fillResult
|
|
13
|
+
const fillResult = pixels.fill(0, 0, 0);
|
|
14
|
+
if (!fillResult.ok) return fillResult;
|
|
15
15
|
for (let i = 0; i < TAIL_LEN; i++) {
|
|
16
|
-
const idx = (pos - i + numLeds) % numLeds
|
|
17
|
-
const fade = 1 - i / TAIL_LEN
|
|
18
|
-
const v = fade * fade * brightness
|
|
19
|
-
const [r, g, b] = hsv(200, 1, v)
|
|
20
|
-
const pixelResult = pixels.setPixel(idx, r, g, b)
|
|
21
|
-
if (!pixelResult.ok) return pixelResult
|
|
16
|
+
const idx = (pos - i + numLeds) % numLeds;
|
|
17
|
+
const fade = 1 - i / TAIL_LEN;
|
|
18
|
+
const v = fade * fade * brightness;
|
|
19
|
+
const [r, g, b] = hsv(200, 1, v);
|
|
20
|
+
const pixelResult = pixels.setPixel(idx, r, g, b);
|
|
21
|
+
if (!pixelResult.ok) return pixelResult;
|
|
22
22
|
}
|
|
23
|
-
const showResult = pixels.show()
|
|
24
|
-
if (!showResult.ok) return showResult
|
|
25
|
-
pos = (pos + 1) % numLeds
|
|
26
|
-
await sleep(40)
|
|
23
|
+
const showResult = pixels.show();
|
|
24
|
+
if (!showResult.ok) return showResult;
|
|
25
|
+
pos = (pos + 1) % numLeds;
|
|
26
|
+
await sleep(40);
|
|
27
27
|
}
|
|
28
|
-
return ok(undefined)
|
|
28
|
+
return ok(undefined);
|
|
29
29
|
}
|