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,24 +1,24 @@
|
|
|
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
|
/** Rainbow: rotate a full spectrum around the ring */
|
|
8
8
|
export async function rainbow(pixels: NeoPixel, numLeds: number, brightness: number, ms: number) {
|
|
9
|
-
const end = Date.now() + ms
|
|
10
|
-
let offset = 0
|
|
9
|
+
const end = Date.now() + ms;
|
|
10
|
+
let offset = 0;
|
|
11
11
|
while (Date.now() < end) {
|
|
12
12
|
for (let i = 0; i < numLeds; i++) {
|
|
13
|
-
const hue = ((i * 360) / numLeds + offset) % 360
|
|
14
|
-
const [r, g, b] = hsv(hue, 1, brightness)
|
|
15
|
-
const pixelResult = pixels.setPixel(i, r, g, b)
|
|
16
|
-
if (!pixelResult.ok) return pixelResult
|
|
13
|
+
const hue = ((i * 360) / numLeds + offset) % 360;
|
|
14
|
+
const [r, g, b] = hsv(hue, 1, brightness);
|
|
15
|
+
const pixelResult = pixels.setPixel(i, r, g, b);
|
|
16
|
+
if (!pixelResult.ok) return pixelResult;
|
|
17
17
|
}
|
|
18
|
-
const showResult = pixels.show()
|
|
19
|
-
if (!showResult.ok) return showResult
|
|
20
|
-
offset = (offset + 5) % 360
|
|
21
|
-
await sleep(30)
|
|
18
|
+
const showResult = pixels.show();
|
|
19
|
+
if (!showResult.ok) return showResult;
|
|
20
|
+
offset = (offset + 5) % 360;
|
|
21
|
+
await sleep(30);
|
|
22
22
|
}
|
|
23
|
-
return ok()
|
|
23
|
+
return ok();
|
|
24
24
|
}
|
|
@@ -1,25 +1,25 @@
|
|
|
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
|
/** Sparkle: random pixels flash white on a dim background */
|
|
8
8
|
export async function sparkle(pixels: NeoPixel, numLeds: number, brightness: number, ms: number) {
|
|
9
|
-
const end = Date.now() + ms
|
|
9
|
+
const end = Date.now() + ms;
|
|
10
10
|
while (Date.now() < end) {
|
|
11
|
-
const [br, bg, bb] = hsv(270, 0.8, brightness * 0.15)
|
|
12
|
-
const fillResult = pixels.fill(br, bg, bb)
|
|
13
|
-
if (!fillResult.ok) return fillResult
|
|
11
|
+
const [br, bg, bb] = hsv(270, 0.8, brightness * 0.15);
|
|
12
|
+
const fillResult = pixels.fill(br, bg, bb);
|
|
13
|
+
if (!fillResult.ok) return fillResult;
|
|
14
14
|
for (let s = 0; s < 3; s++) {
|
|
15
|
-
const idx = Math.floor(Math.random() * numLeds)
|
|
16
|
-
const v = brightness * (0.5 + Math.random() * 0.5) * 255
|
|
17
|
-
const pixelResult = pixels.setPixel(idx, v, v, v)
|
|
18
|
-
if (!pixelResult.ok) return pixelResult
|
|
15
|
+
const idx = Math.floor(Math.random() * numLeds);
|
|
16
|
+
const v = brightness * (0.5 + Math.random() * 0.5) * 255;
|
|
17
|
+
const pixelResult = pixels.setPixel(idx, v, v, v);
|
|
18
|
+
if (!pixelResult.ok) return pixelResult;
|
|
19
19
|
}
|
|
20
|
-
const showResult = pixels.show()
|
|
21
|
-
if (!showResult.ok) return showResult
|
|
22
|
-
await sleep(60)
|
|
20
|
+
const showResult = pixels.show();
|
|
21
|
+
if (!showResult.ok) return showResult;
|
|
22
|
+
await sleep(60);
|
|
23
23
|
}
|
|
24
|
-
return ok()
|
|
24
|
+
return ok();
|
|
25
25
|
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import {Pwm} from
|
|
1
|
+
import { Pwm } from "mikrojs/pwm";
|
|
2
2
|
|
|
3
3
|
// GPIO 15 is the built-in LED on XIAO ESP32C6. Replace with your board's LED pin.
|
|
4
|
-
const LED_PIN = 15
|
|
4
|
+
const LED_PIN = 15;
|
|
5
5
|
|
|
6
|
-
const led = new Pwm(LED_PIN, {freq: 50, duty: 0})
|
|
6
|
+
const led = new Pwm(LED_PIN, { freq: 50, duty: 0 });
|
|
7
7
|
|
|
8
8
|
// Breathe: smoothly fade in and out forever
|
|
9
9
|
while (true) {
|
|
10
|
-
const fadeIn = await led.fade(1.0, 1000)
|
|
10
|
+
const fadeIn = await led.fade(1.0, 1000);
|
|
11
11
|
if (!fadeIn.ok) {
|
|
12
|
-
console.error(
|
|
13
|
-
break
|
|
12
|
+
console.error("Fade in failed: %s", fadeIn.error.name);
|
|
13
|
+
break;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
const fadeOut = await led.fade(0.0, 1000)
|
|
16
|
+
const fadeOut = await led.fade(0.0, 1000);
|
|
17
17
|
if (!fadeOut.ok) {
|
|
18
|
-
console.error(
|
|
19
|
-
break
|
|
18
|
+
console.error("Fade out failed: %s", fadeOut.error.name);
|
|
19
|
+
break;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import {rtcStorage} from
|
|
2
|
-
import * as s from
|
|
3
|
-
import {deepSleep, sleep} from
|
|
1
|
+
import { rtcStorage } from "mikrojs/kv/rtc";
|
|
2
|
+
import * as s from "mikrojs/schema";
|
|
3
|
+
import { deepSleep, sleep } from "mikrojs/sleep";
|
|
4
4
|
|
|
5
5
|
// Read the wake counter from RTC memory (survives deep sleep).
|
|
6
6
|
// optional() because the key may not exist on first boot.
|
|
7
|
-
const count = rtcStorage.createValue(
|
|
7
|
+
const count = rtcStorage.createValue("count", {
|
|
8
|
+
schema: s.optional(s.number()),
|
|
9
|
+
});
|
|
8
10
|
|
|
9
|
-
console.log(`Wake #${count.get() ?? 0}`)
|
|
10
|
-
console.log(`RTC memory: ${rtcStorage.info().used}/${rtcStorage.info().total} bytes used`)
|
|
11
|
+
console.log(`Wake #${count.get() ?? 0}`);
|
|
12
|
+
console.log(`RTC memory: ${rtcStorage.info().used}/${rtcStorage.info().total} bytes used`);
|
|
11
13
|
|
|
12
14
|
// Increment and store back
|
|
13
|
-
count.update((n) => (n ?? 0) + 1).orPanic(
|
|
15
|
+
count.update((n) => (n ?? 0) + 1).orPanic("failed to store count");
|
|
14
16
|
|
|
15
|
-
console.log(
|
|
16
|
-
await sleep(5000)
|
|
17
|
+
console.log("Waiting for a few seconds before going to deep sleep...");
|
|
18
|
+
await sleep(5000);
|
|
17
19
|
|
|
18
20
|
// Sleep for 15 seconds, then wake up again
|
|
19
|
-
console.log(
|
|
20
|
-
deepSleep(15000)
|
|
21
|
+
console.log("Going to deep sleep for 15s...");
|
|
22
|
+
deepSleep(15000);
|
|
@@ -1,30 +1,32 @@
|
|
|
1
|
-
import {env} from
|
|
2
|
-
import {sleep} from
|
|
3
|
-
import {sntp} from
|
|
4
|
-
import {wifi} from
|
|
1
|
+
import { env } from "mikrojs/env";
|
|
2
|
+
import { sleep } from "mikrojs/sleep";
|
|
3
|
+
import { sntp } from "mikrojs/sntp";
|
|
4
|
+
import { wifi } from "mikrojs/wifi";
|
|
5
5
|
|
|
6
|
-
await sleep(2000)
|
|
7
|
-
console.log(
|
|
6
|
+
await sleep(2000);
|
|
7
|
+
console.log("Current time at startup: %s", new Date());
|
|
8
8
|
|
|
9
|
-
const ssid = env.require(
|
|
10
|
-
const passphrase = env.require(
|
|
9
|
+
const ssid = env.require("WIFI_SSID");
|
|
10
|
+
const passphrase = env.require("WIFI_PASSPHRASE");
|
|
11
11
|
|
|
12
12
|
// Connect to WiFi
|
|
13
|
-
console.log(`Connecting to ${ssid}...`)
|
|
14
|
-
const connectResult = await wifi.connect(ssid, passphrase)
|
|
13
|
+
console.log(`Connecting to ${ssid}...`);
|
|
14
|
+
const connectResult = await wifi.connect(ssid, passphrase);
|
|
15
15
|
if (!connectResult.ok) {
|
|
16
|
-
console.error(
|
|
16
|
+
console.error("WiFi connect failed: %s", connectResult.error.name);
|
|
17
17
|
} else {
|
|
18
|
-
console.log(
|
|
18
|
+
console.log("Connected! IP: %s", connectResult.value.ip);
|
|
19
19
|
|
|
20
20
|
// One-shot time sync
|
|
21
|
-
console.log(
|
|
22
|
-
const syncResult = await sntp.sync({
|
|
21
|
+
console.log("Syncing time...");
|
|
22
|
+
const syncResult = await sntp.sync({
|
|
23
|
+
timezone: "CET-1CEST,M3.5.0,M10.5.0/3",
|
|
24
|
+
});
|
|
23
25
|
if (!syncResult.ok) {
|
|
24
|
-
console.error(
|
|
26
|
+
console.error("SNTP sync failed: %s", syncResult.error.name);
|
|
25
27
|
} else {
|
|
26
|
-
console.log(
|
|
27
|
-
console.log(
|
|
28
|
+
console.log("Time synced: %s", syncResult.value.time);
|
|
29
|
+
console.log("Current time: %s", new Date());
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
32
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {defineConfig} from
|
|
1
|
+
import { defineConfig } from "mikrojs";
|
|
2
2
|
|
|
3
|
+
// Project configuration. See https://mikrojs.dev/config for all options.
|
|
3
4
|
export default defineConfig({
|
|
4
5
|
// Set to your country code so WiFi uses the correct regulatory domain.
|
|
5
|
-
wifi: {country:
|
|
6
|
-
})
|
|
6
|
+
wifi: { country: "NO" },
|
|
7
|
+
});
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import {sleep} from
|
|
2
|
-
import {wifi} from
|
|
1
|
+
import { sleep } from "mikrojs/sleep";
|
|
2
|
+
import { wifi } from "mikrojs/wifi";
|
|
3
3
|
|
|
4
4
|
// Start the access point
|
|
5
5
|
wifi.ap
|
|
6
6
|
.start({
|
|
7
|
-
ssid:
|
|
8
|
-
passphrase:
|
|
7
|
+
ssid: "MikroJS-AP",
|
|
8
|
+
passphrase: "hello1234",
|
|
9
9
|
channel: 6,
|
|
10
10
|
maxConnections: 4,
|
|
11
11
|
})
|
|
12
|
-
.orPanic(
|
|
12
|
+
.orPanic("Failed to start access point");
|
|
13
13
|
|
|
14
|
-
console.log(
|
|
15
|
-
console.log(
|
|
16
|
-
console.log(
|
|
14
|
+
console.log("Access point started");
|
|
15
|
+
console.log("SSID: MikroJS-AP");
|
|
16
|
+
console.log("IP: %s", wifi.ap.ip);
|
|
17
17
|
|
|
18
18
|
// Log when stations connect/disconnect
|
|
19
19
|
wifi.ap.onStationConnect.subscribe((info) => {
|
|
20
|
-
console.log(
|
|
21
|
-
})
|
|
20
|
+
console.log("Station connected: %s", info.mac);
|
|
21
|
+
});
|
|
22
22
|
|
|
23
23
|
wifi.ap.onStationDisconnect.subscribe((info) => {
|
|
24
|
-
console.log(
|
|
25
|
-
})
|
|
24
|
+
console.log("Station disconnected: %s", info.mac);
|
|
25
|
+
});
|
|
26
26
|
|
|
27
27
|
// Periodically print connected stations
|
|
28
28
|
while (true) {
|
|
29
|
-
await sleep(10000)
|
|
30
|
-
const stations = wifi.ap.stations
|
|
29
|
+
await sleep(10000);
|
|
30
|
+
const stations = wifi.ap.stations;
|
|
31
31
|
if (stations.length > 0) {
|
|
32
|
-
console.log(`Connected stations (${stations.length}):`)
|
|
32
|
+
console.log(`Connected stations (${stations.length}):`);
|
|
33
33
|
for (const sta of stations) {
|
|
34
|
-
console.log(` ${sta.mac} (RSSI: ${sta.rssi})`)
|
|
34
|
+
console.log(` ${sta.mac} (RSSI: ${sta.rssi})`);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {defineConfig} from
|
|
1
|
+
import { defineConfig } from "mikrojs";
|
|
2
2
|
|
|
3
|
+
// Project configuration. See https://mikrojs.dev/config for all options.
|
|
3
4
|
export default defineConfig({
|
|
4
5
|
// Set to your country code so WiFi uses the correct regulatory domain.
|
|
5
|
-
wifi: {country:
|
|
6
|
-
})
|
|
6
|
+
wifi: { country: "NO" },
|
|
7
|
+
});
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import {env} from
|
|
2
|
-
import {request} from
|
|
3
|
-
import {memoryUsage} from
|
|
4
|
-
import {wifi} from
|
|
1
|
+
import { env } from "mikrojs/env";
|
|
2
|
+
import { request } from "mikrojs/http/request";
|
|
3
|
+
import { memoryUsage } from "mikrojs/sys";
|
|
4
|
+
import { wifi } from "mikrojs/wifi";
|
|
5
5
|
|
|
6
|
-
const ssid = env.require(
|
|
7
|
-
const passphrase = env.require(
|
|
6
|
+
const ssid = env.require("WIFI_SSID");
|
|
7
|
+
const passphrase = env.require("WIFI_PASSPHRASE");
|
|
8
8
|
|
|
9
9
|
// Connect to WiFi
|
|
10
|
-
console.log(`Connecting to ${ssid}...`)
|
|
11
|
-
const connectResult = await wifi.connect(ssid, passphrase)
|
|
10
|
+
console.log(`Connecting to ${ssid}...`);
|
|
11
|
+
const connectResult = await wifi.connect(ssid, passphrase);
|
|
12
12
|
if (!connectResult.ok) {
|
|
13
|
-
console.error(
|
|
13
|
+
console.error("WiFi connect failed: %s", connectResult.error.name);
|
|
14
14
|
} else {
|
|
15
|
-
console.log(
|
|
15
|
+
console.log("Connected! IP: %s", connectResult.value.ip);
|
|
16
16
|
|
|
17
17
|
// Request JSON from an API
|
|
18
|
-
const result = await request(
|
|
18
|
+
const result = await request("https://jsonplaceholder.typicode.com/posts/1");
|
|
19
19
|
if (result.ok) {
|
|
20
20
|
if (!result.value.ok) {
|
|
21
|
-
console.error(`HTTP error: ${result.value.status}`)
|
|
21
|
+
console.error(`HTTP error: ${result.value.status}`);
|
|
22
22
|
} else {
|
|
23
|
-
const data = await result.value.json()
|
|
24
|
-
console.log(
|
|
23
|
+
const data = await result.value.json();
|
|
24
|
+
console.log("Fetched post: %o", data);
|
|
25
25
|
}
|
|
26
26
|
} else {
|
|
27
|
-
console.error(
|
|
27
|
+
console.error("Request failed: %s", result.error.name);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
const mem = memoryUsage()
|
|
32
|
-
console.log(
|
|
31
|
+
const mem = memoryUsage();
|
|
32
|
+
console.log("free heap: %dKB", (mem.heapTotal - mem.heapUsed) / 1000);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {defineConfig} from
|
|
1
|
+
import { defineConfig } from "mikrojs";
|
|
2
2
|
|
|
3
|
+
// Project configuration. See https://mikrojs.dev/config for all options.
|
|
3
4
|
export default defineConfig({
|
|
4
5
|
// Set to your country code so WiFi uses the correct regulatory domain.
|
|
5
|
-
wifi: {country:
|
|
6
|
-
})
|
|
6
|
+
wifi: { country: "NO" },
|
|
7
|
+
});
|