diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..292912b --- /dev/null +++ b/.prettierrc @@ -0,0 +1 @@ +{"arrowParens":"avoid","semi":false,"tabWidth":4} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..5074657 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,30 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Launch MakeCode", + "program": "mkc", + "request": "launch", + "skipFiles": [ + "/**" + ], + "type": "node" + }, + { + "type": "pwa-node", + "request": "launch", + "name": "Launch Program", + "skipFiles": [ + "/**" + ], + "program": "${file}", + "preLaunchTask": "tsc: build - tsconfig.json", + "outFiles": [ + "${workspaceFolder}/built/**/*.js" + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 441d7d1..c87d281 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,36 +1,67 @@ // A task runner that calls the PXT compiler and { - "version": "0.1.0", + "version": "2.0.0", // The command is pxt. Assumes that PXT has been installed using npm install -g pxt "command": "pxt", - // The command is a shell script - "isShellCommand": true, - - // Show the output window always. - "showOutput": "always", - - "tasks": [{ - "taskName": "deploy", - "isBuildCommand": true, - "problemMatcher": "$tsc", - "args": [""] - }, { - "taskName": "build", - "isTestCommand": true, - "problemMatcher": "$tsc", - "args": [""] - }, { - "taskName": "clean", - "isTestCommand": true, - "problemMatcher": "$tsc", - "args": [""] - }, { - "taskName": "serial", - "isTestCommand": true, - "problemMatcher": "$tsc", - "args": [""] - }] + "tasks": [ + { + "label": "deploy", + "type": "shell", + "command": "pxt", + "args": [ + "deploy", + "" + ], + "problemMatcher": "$tsc", + "group": { + "_id": "build", + "isDefault": false + } + }, + { + "label": "build", + "type": "shell", + "command": "pxt", + "args": [ + "build", + "" + ], + "problemMatcher": "$tsc", + "group": { + "_id": "test", + "isDefault": false + } + }, + { + "label": "clean", + "type": "shell", + "command": "pxt", + "args": [ + "clean", + "" + ], + "problemMatcher": "$tsc", + "group": { + "_id": "test", + "isDefault": false + } + }, + { + "label": "serial", + "type": "shell", + "command": "pxt", + "args": [ + "serial", + "" + ], + "problemMatcher": "$tsc", + "group": { + "_id": "test", + "isDefault": false + } + } + ] } diff --git a/jacdac/README.md b/jacdac/README.md new file mode 100644 index 0000000..a132cf1 --- /dev/null +++ b/jacdac/README.md @@ -0,0 +1 @@ +# Weather:bit Jacdac Extension \ No newline at end of file diff --git a/jacdac/jacdac.ts b/jacdac/jacdac.ts new file mode 100644 index 0000000..ce32128 --- /dev/null +++ b/jacdac/jacdac.ts @@ -0,0 +1,61 @@ +//% deprecated +namespace weatherbit { } + +namespace modules { + /** + * Rain gauge from the weather:bit + */ + //% fixedInstance whenUsed block="weatherbit rain" + export const weatherbitRain = new modules.RainGaugeClient( + "weatherbit rain?dev=self" + ) + + /** + * Wind speed from weather:bit + */ + //% fixedInstance whenUsed block="weatherbit wind speed" + export const weatherbitWindSpeed = new modules.WindSpeedClient("weatherbit wind speed?dev=self") +} + +namespace servers { + function start() { + jacdac.productIdentifier = 0x36dccd5c + jacdac.deviceDescription = "Sparkfun Weather:bit" + jacdac.startSelfServers(() => { + const servers: jacdac.Server[] = [ + jacdac.createSimpleSensorServer( + jacdac.SRV_RAIN_GAUGE, + jacdac.RainGaugeRegPack.Precipitation, + () => weatherbit.rain() / 25.4, // inches -> mm + { + streamingInterval: 30000, + readingError: () => 25.4, + statusCode: jacdac.SystemStatusCodes.Initializing + } + ), + jacdac.createSimpleSensorServer( + jacdac.SRV_WIND_SPEED, + jacdac.WindSpeedRegPack.WindSpeed, + () => weatherbit.windSpeed() * 1.60934, + { + streamingInterval: 2000, + readingError: () => 3, + statusCode: jacdac.SystemStatusCodes.Initializing + } + ), + ] + + // booting + control.inBackground(() => { + weatherbit.startRainMonitoring() + weatherbit.startWindMonitoring() + for(const server of servers) + server.setStatusCode(jacdac.SystemStatusCodes.Ready) + }) + + // return servers + return servers + }) + } + start() +} diff --git a/jacdac/pxt.json b/jacdac/pxt.json new file mode 100644 index 0000000..1086494 --- /dev/null +++ b/jacdac/pxt.json @@ -0,0 +1,29 @@ +{ + "name": "weather-bit-jacdac", + "version": "0.0.28", + "description": "SparkFun weatherbit Jacdac", + "license": "MIT", + "dependencies": { + "core": "*", + "pxt-weather-bit": "github:sparkfun/pxt-weather-bit", + "jacdac": "github:microsoft/pxt-jacdac#v0.10.41", + "jacdac-wind-speed": "github:microsoft/pxt-jacdac/wind-speed#v0.10.41", + "jacdac-rain-gauge": "github:microsoft/pxt-jacdac/rain-gauge#v0.10.41" + }, + "files": [ + "README.md", + "jacdac.ts" + ], + "testFiles": [ + "tests.ts" + ], + "public": true, + "targetVersions": { + "target": "4.1.44", + "targetId": "microbit" + }, + "supportedTargets": [ + "microbit" + ], + "preferredEditor": "tsprj" +} diff --git a/jacdac/tests.ts b/jacdac/tests.ts new file mode 100644 index 0000000..66192af --- /dev/null +++ b/jacdac/tests.ts @@ -0,0 +1,5 @@ +forever(() => { + console.logValue("rain", modules.weatherbitRain.precipitation()) + console.logValue("wind", modules.weatherbitWindSpeed.windSpeed()) + pause(1000) +}) \ No newline at end of file diff --git a/pxt.json b/pxt.json index 66079bc..bd36622 100644 --- a/pxt.json +++ b/pxt.json @@ -18,4 +18,4 @@ "tests.ts" ], "public": true -} +} \ No newline at end of file