Skip to content

Jacdac Extension #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"arrowParens":"avoid","semi":false,"tabWidth":4}
30 changes: 30 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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": [
"<node_internals>/**"
],
"type": "node"
},
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${file}",
"preLaunchTask": "tsc: build - tsconfig.json",
"outFiles": [
"${workspaceFolder}/built/**/*.js"
]
}
]
}
87 changes: 59 additions & 28 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -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
}
}
]
}
1 change: 1 addition & 0 deletions jacdac/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Weather:bit Jacdac Extension
61 changes: 61 additions & 0 deletions jacdac/jacdac.ts
Original file line number Diff line number Diff line change
@@ -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()
}
29 changes: 29 additions & 0 deletions jacdac/pxt.json
Original file line number Diff line number Diff line change
@@ -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"
}
5 changes: 5 additions & 0 deletions jacdac/tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
forever(() => {
console.logValue("rain", modules.weatherbitRain.precipitation())
console.logValue("wind", modules.weatherbitWindSpeed.windSpeed())
pause(1000)
})
2 changes: 1 addition & 1 deletion pxt.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
"tests.ts"
],
"public": true
}
}