Compare commits
72 Commits
Author | SHA1 | Date | |
---|---|---|---|
e31279938b | |||
2655843b74 | |||
527d323ea7 | |||
5d40a48477 | |||
850fb54f52 | |||
6bb35c1a72 | |||
6569231ba6 | |||
a3a1c8a480 | |||
c90dfaa6e7 | |||
02cd0e1da3 | |||
0f9dde0c4e | |||
1e0cd48316 | |||
d959282c68 | |||
d513ad7713 | |||
b7da28285e | |||
dbaf406703 | |||
2cb467f22b | |||
9585e2276d | |||
a591d9f072 | |||
471a30ca3d | |||
205b94afe8 | |||
18caf554e9 | |||
67cdf16fe4 | |||
bdbe8371dd | |||
21a36eb9ee | |||
376b20b035 | |||
7ce41b52aa | |||
46f7831e7c | |||
dda29a5cb6 | |||
6e4f4595a2 | |||
cdbe1e513b | |||
ae15c9a656 | |||
d993ff3a9d | |||
13785a2438 | |||
4dfb77fcd7 | |||
70deffb665 | |||
41a148de28 | |||
886e071d7f | |||
8a58d664c3 | |||
71d1155f21 | |||
167c1d8fce | |||
e59ae37954 | |||
72a621ec8b | |||
d6ff930333 | |||
54a7ac81ea | |||
e5d985dbf1 | |||
9db91d89d6 | |||
1fa9bf12d5 | |||
61bab257eb | |||
2e90b351da | |||
801bd6c7a0 | |||
777ba40899 | |||
0d11c16ecf | |||
9c1628b977 | |||
953b362b34 | |||
8b40850a94 | |||
fc3a02cc41 | |||
80f2ff6757 | |||
6f790d167c | |||
ac7502074a | |||
50473255a8 | |||
910772d54e | |||
33f12f9ecc | |||
01fa4ef53a | |||
3858b0a0a0 | |||
da30afb121 | |||
086bcf372f | |||
236e7337e2 | |||
4cf223271f | |||
10180f4729 | |||
618dd33221 | |||
7356e5e52e |
2
clients/electron/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
projects
|
5
clients/electron/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# PXT micro:bit Electron app
|
||||
|
||||
A very basic wrapper around the web app. To install, copy the contents of this
|
||||
directory to somewhere outside the main `pxt-microbit` repository. Then run `npm
|
||||
install && npm start`.
|
15
clients/electron/index.html
Normal file
@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>code the micro:bit</title>
|
||||
</head>
|
||||
<body>
|
||||
<webview id="webview" style="position:absolute; left:0; top:0; right:0; bottom:0"/>
|
||||
<script>
|
||||
const webview = document.getElementById("webview")
|
||||
const url = `http://localhost:3232/${window.location.hash}`
|
||||
webview.src = url
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,67 +1,39 @@
|
||||
const electron = require('electron')
|
||||
// Module to control application life.
|
||||
const app = electron.app
|
||||
// Module to create native browser window.
|
||||
const BrowserWindow = electron.BrowserWindow
|
||||
// pxt toolchain
|
||||
const {app, BrowserWindow, Menu} = require('electron')
|
||||
const pxt = require('pxt-core')
|
||||
const path = require('path')
|
||||
|
||||
// Keep a global reference of the window object, if you don't, the window will
|
||||
// be closed automatically when the JavaScript object is garbage collected.
|
||||
let mainWindow
|
||||
let win
|
||||
|
||||
function createWindow() {
|
||||
console.log('starting app...')
|
||||
// Create the browser window.
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 800, height: 600,
|
||||
webPreferences: {
|
||||
nodeIntegration: false,
|
||||
}
|
||||
const cliPath = path.join(process.cwd(), "node_modules/pxt-microbit")
|
||||
|
||||
function startServerAndCreateWindow() {
|
||||
pxt.mainCli(cliPath, ["serve", "-no-browser"])
|
||||
createWindow()
|
||||
}
|
||||
|
||||
function createWindow () {
|
||||
win = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
title: "code the micro:bit"
|
||||
})
|
||||
|
||||
ts.pxt.Util.debug = true;
|
||||
pxt.mainCli("C:/gh/pxt-microbit/clients/electron/node_modules/pxt-microbit", ["serve", "-just"]);
|
||||
|
||||
// no menu
|
||||
mainWindow.setMenu(null);
|
||||
|
||||
// and load the index.html of the app.
|
||||
mainWindow.loadURL(`http://localhost:3232/#local_token=08ba9b8f-6ccb-4202-296d-28fac7a553d9`)
|
||||
|
||||
// Open the DevTools.
|
||||
mainWindow.webContents.openDevTools()
|
||||
|
||||
// Emitted when the window is closed.
|
||||
mainWindow.on('closed', function () {
|
||||
// Dereference the window object, usually you would store windows
|
||||
// in an array if your app supports multi windows, this is the time
|
||||
// when you should delete the corresponding element.
|
||||
mainWindow = null
|
||||
Menu.setApplicationMenu(null)
|
||||
win.loadURL(`file://${__dirname}/index.html#local_token=${pxt.globalConfig.localToken}`)
|
||||
win.on('closed', () => {
|
||||
win = null
|
||||
})
|
||||
}
|
||||
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
app.on('ready', createWindow)
|
||||
app.on('ready', startServerAndCreateWindow)
|
||||
|
||||
// Quit when all windows are closed.
|
||||
app.on('window-all-closed', function () {
|
||||
// On OS X it is common for applications and their menu bar
|
||||
// to stay active until the user quits explicitly with Cmd + Q
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
|
||||
app.on('activate', function () {
|
||||
// On OS X it's common to re-create a window in the app when the
|
||||
// dock icon is clicked and there are no other windows open.
|
||||
if (mainWindow === null) {
|
||||
app.on('activate', () => {
|
||||
if (win === null) {
|
||||
createWindow()
|
||||
}
|
||||
})
|
||||
|
||||
// In this file you can include the rest of your app's specific main process
|
||||
// code. You can also put them in separate files and require them here.
|
@ -1,19 +1,14 @@
|
||||
{
|
||||
"name": "codethemicrobit",
|
||||
"version": "0.1.0",
|
||||
"description": "A Blocks / JavaScript editor for the micro:bit",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"start": "electron ."
|
||||
},
|
||||
"name" : "code-the-microbit",
|
||||
"version" : "1.0.0",
|
||||
"description": "Blocks / Javascript editor",
|
||||
"author": "Microsoft",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"electron-prebuilt": "^1.2.0"
|
||||
"main" : "main.js",
|
||||
"scripts": {
|
||||
"start": "node_modules/.bin/electron ."
|
||||
},
|
||||
"dependencies": {
|
||||
"typescript": "1.8.7",
|
||||
"pxt-core": "*",
|
||||
"pxt-microbit": "*"
|
||||
"devDependencies": {
|
||||
"electron": "*",
|
||||
"pxt-microbit": "*"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
137
clients/macuploader/.gitignore
vendored
Normal file
@ -0,0 +1,137 @@
|
||||
|
||||
# Created by https://www.gitignore.io/api/osx,xcode,objective-c,vim
|
||||
|
||||
### OSX ###
|
||||
*.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
|
||||
### Xcode ###
|
||||
# Xcode
|
||||
#
|
||||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
|
||||
|
||||
## Build generated
|
||||
build/
|
||||
DerivedData/
|
||||
|
||||
## Various settings
|
||||
*.pbxuser
|
||||
!default.pbxuser
|
||||
*.mode1v3
|
||||
!default.mode1v3
|
||||
*.mode2v3
|
||||
!default.mode2v3
|
||||
*.perspectivev3
|
||||
!default.perspectivev3
|
||||
xcuserdata/
|
||||
|
||||
## Other
|
||||
*.moved-aside
|
||||
*.xccheckout
|
||||
*.xcscmblueprint
|
||||
|
||||
|
||||
### Objective-C ###
|
||||
# Xcode
|
||||
#
|
||||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
|
||||
|
||||
## Build generated
|
||||
build/
|
||||
DerivedData/
|
||||
|
||||
## Various settings
|
||||
*.pbxuser
|
||||
!default.pbxuser
|
||||
*.mode1v3
|
||||
!default.mode1v3
|
||||
*.mode2v3
|
||||
!default.mode2v3
|
||||
*.perspectivev3
|
||||
!default.perspectivev3
|
||||
xcuserdata/
|
||||
|
||||
## Other
|
||||
*.moved-aside
|
||||
*.xcuserstate
|
||||
|
||||
## Obj-C/Swift specific
|
||||
*.hmap
|
||||
*.ipa
|
||||
*.dSYM.zip
|
||||
*.dSYM
|
||||
|
||||
# CocoaPods
|
||||
#
|
||||
# We recommend against adding the Pods directory to your .gitignore. However
|
||||
# you should judge for yourself, the pros and cons are mentioned at:
|
||||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
||||
#
|
||||
# Pods/
|
||||
|
||||
# Carthage
|
||||
#
|
||||
# Add this line if you want to avoid checking in source code from Carthage dependencies.
|
||||
# Carthage/Checkouts
|
||||
|
||||
Carthage/Build
|
||||
|
||||
# fastlane
|
||||
#
|
||||
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
|
||||
# screenshots whenever they are needed.
|
||||
# For more information about the recommended setup visit:
|
||||
# https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md
|
||||
|
||||
fastlane/report.xml
|
||||
fastlane/Preview.html
|
||||
fastlane/screenshots
|
||||
fastlane/test_output
|
||||
|
||||
# Code Injection
|
||||
#
|
||||
# After new code Injection tools there's a generated folder /iOSInjectionProject
|
||||
# https://github.com/johnno1962/injectionforxcode
|
||||
|
||||
iOSInjectionProject/
|
||||
|
||||
### Objective-C Patch ###
|
||||
*.xcscmblueprint
|
||||
|
||||
|
||||
### Vim ###
|
||||
# swap
|
||||
[._]*.s[a-w][a-z]
|
||||
[._]s[a-w][a-z]
|
||||
# session
|
||||
Session.vim
|
||||
# temporary
|
||||
.netrwhist
|
||||
*~
|
||||
# auto-generated tag files
|
||||
tags
|
BIN
clients/macuploader/Graphics/appicon.sketch
Normal file
BIN
clients/macuploader/Graphics/export.png
Normal file
After Width: | Height: | Size: 40 KiB |
BIN
clients/macuploader/Graphics/menubar.sketch
Normal file
307
clients/macuploader/Microbit Uploader.xcodeproj/project.pbxproj
Normal file
@ -0,0 +1,307 @@
|
||||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 46;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
E93040071D895D1F00D931CA /* DirectoryWatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = E93040061D895D1F00D931CA /* DirectoryWatcher.m */; };
|
||||
E930400A1D89620900D931CA /* Uploader.m in Sources */ = {isa = PBXBuildFile; fileRef = E93040091D89620900D931CA /* Uploader.m */; };
|
||||
E9F4FEE21D8709980071D783 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E9F4FEE11D8709980071D783 /* AppDelegate.m */; };
|
||||
E9F4FEE51D8709980071D783 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E9F4FEE41D8709980071D783 /* main.m */; };
|
||||
E9F4FEE71D8709980071D783 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E9F4FEE61D8709980071D783 /* Assets.xcassets */; };
|
||||
E9F4FEEA1D8709980071D783 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = E9F4FEE81D8709980071D783 /* MainMenu.xib */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
E93040051D895D1F00D931CA /* DirectoryWatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DirectoryWatcher.h; sourceTree = "<group>"; };
|
||||
E93040061D895D1F00D931CA /* DirectoryWatcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DirectoryWatcher.m; sourceTree = "<group>"; };
|
||||
E93040081D89620900D931CA /* Uploader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Uploader.h; sourceTree = "<group>"; };
|
||||
E93040091D89620900D931CA /* Uploader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Uploader.m; sourceTree = "<group>"; };
|
||||
E9F4FEDD1D8709980071D783 /* Microbit Uploader.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Microbit Uploader.app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
E9F4FEE01D8709980071D783 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
|
||||
E9F4FEE11D8709980071D783 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
|
||||
E9F4FEE41D8709980071D783 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
|
||||
E9F4FEE61D8709980071D783 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
E9F4FEE91D8709980071D783 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = "<group>"; };
|
||||
E9F4FEEB1D8709980071D783 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
E9F4FEDA1D8709980071D783 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
E9F4FED41D8709980071D783 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E9F4FEDF1D8709980071D783 /* Microbit Uploader */,
|
||||
E9F4FEDE1D8709980071D783 /* Products */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
E9F4FEDE1D8709980071D783 /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E9F4FEDD1D8709980071D783 /* Microbit Uploader.app */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
E9F4FEDF1D8709980071D783 /* Microbit Uploader */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E9F4FEE01D8709980071D783 /* AppDelegate.h */,
|
||||
E9F4FEE11D8709980071D783 /* AppDelegate.m */,
|
||||
E9F4FEE61D8709980071D783 /* Assets.xcassets */,
|
||||
E9F4FEE81D8709980071D783 /* MainMenu.xib */,
|
||||
E9F4FEEB1D8709980071D783 /* Info.plist */,
|
||||
E9F4FEE31D8709980071D783 /* Supporting Files */,
|
||||
E93040051D895D1F00D931CA /* DirectoryWatcher.h */,
|
||||
E93040061D895D1F00D931CA /* DirectoryWatcher.m */,
|
||||
E93040081D89620900D931CA /* Uploader.h */,
|
||||
E93040091D89620900D931CA /* Uploader.m */,
|
||||
);
|
||||
path = "Microbit Uploader";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
E9F4FEE31D8709980071D783 /* Supporting Files */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E9F4FEE41D8709980071D783 /* main.m */,
|
||||
);
|
||||
name = "Supporting Files";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
E9F4FEDC1D8709980071D783 /* Microbit Uploader */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = E9F4FEEE1D8709980071D783 /* Build configuration list for PBXNativeTarget "Microbit Uploader" */;
|
||||
buildPhases = (
|
||||
E9F4FED91D8709980071D783 /* Sources */,
|
||||
E9F4FEDA1D8709980071D783 /* Frameworks */,
|
||||
E9F4FEDB1D8709980071D783 /* Resources */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = "Microbit Uploader";
|
||||
productName = "Microbit Uploader";
|
||||
productReference = E9F4FEDD1D8709980071D783 /* Microbit Uploader.app */;
|
||||
productType = "com.apple.product-type.application";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
E9F4FED51D8709980071D783 /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastUpgradeCheck = 0800;
|
||||
ORGANIZATIONNAME = thomasdenney;
|
||||
TargetAttributes = {
|
||||
E9F4FEDC1D8709980071D783 = {
|
||||
CreatedOnToolsVersion = 7.3.1;
|
||||
};
|
||||
};
|
||||
};
|
||||
buildConfigurationList = E9F4FED81D8709980071D783 /* Build configuration list for PBXProject "Microbit Uploader" */;
|
||||
compatibilityVersion = "Xcode 3.2";
|
||||
developmentRegion = English;
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
en,
|
||||
Base,
|
||||
);
|
||||
mainGroup = E9F4FED41D8709980071D783;
|
||||
productRefGroup = E9F4FEDE1D8709980071D783 /* Products */;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
E9F4FEDC1D8709980071D783 /* Microbit Uploader */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXResourcesBuildPhase section */
|
||||
E9F4FEDB1D8709980071D783 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
E9F4FEE71D8709980071D783 /* Assets.xcassets in Resources */,
|
||||
E9F4FEEA1D8709980071D783 /* MainMenu.xib in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
E9F4FED91D8709980071D783 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
E9F4FEE51D8709980071D783 /* main.m in Sources */,
|
||||
E930400A1D89620900D931CA /* Uploader.m in Sources */,
|
||||
E9F4FEE21D8709980071D783 /* AppDelegate.m in Sources */,
|
||||
E93040071D895D1F00D931CA /* DirectoryWatcher.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXVariantGroup section */
|
||||
E9F4FEE81D8709980071D783 /* MainMenu.xib */ = {
|
||||
isa = PBXVariantGroup;
|
||||
children = (
|
||||
E9F4FEE91D8709980071D783 /* Base */,
|
||||
);
|
||||
name = MainMenu.xib;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXVariantGroup section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
E9F4FEEC1D8709980071D783 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
CODE_SIGN_IDENTITY = "-";
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_TESTABILITY = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"DEBUG=1",
|
||||
"$(inherited)",
|
||||
);
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = macosx;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
E9F4FEED1D8709980071D783 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
CODE_SIGN_IDENTITY = "-";
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
ENABLE_NS_ASSERTIONS = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = macosx;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
E9F4FEEF1D8709980071D783 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
INFOPLIST_FILE = "Microbit Uploader/Info.plist";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "org.thomasdenney.Microbit-Uploader";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
E9F4FEF01D8709980071D783 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
INFOPLIST_FILE = "Microbit Uploader/Info.plist";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "org.thomasdenney.Microbit-Uploader";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
E9F4FED81D8709980071D783 /* Build configuration list for PBXProject "Microbit Uploader" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
E9F4FEEC1D8709980071D783 /* Debug */,
|
||||
E9F4FEED1D8709980071D783 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
E9F4FEEE1D8709980071D783 /* Build configuration list for PBXNativeTarget "Microbit Uploader" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
E9F4FEEF1D8709980071D783 /* Debug */,
|
||||
E9F4FEF01D8709980071D783 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = E9F4FED51D8709980071D783 /* Project object */;
|
||||
}
|
7
clients/macuploader/Microbit Uploader.xcodeproj/project.xcworkspace/contents.xcworkspacedata
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "self:Microbit Uploader.xcodeproj">
|
||||
</FileRef>
|
||||
</Workspace>
|
6
clients/macuploader/Microbit Uploader/AppDelegate.h
Normal file
@ -0,0 +1,6 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface AppDelegate : NSObject <NSApplicationDelegate>
|
||||
|
||||
@end
|
||||
|
130
clients/macuploader/Microbit Uploader/AppDelegate.m
Normal file
@ -0,0 +1,130 @@
|
||||
#import "AppDelegate.h"
|
||||
#import "DirectoryWatcher.h"
|
||||
#import "Uploader.h"
|
||||
|
||||
@interface AppDelegate ()<DirectoryWatcherDelegate, UploaderDelegate, NSUserNotificationCenterDelegate>
|
||||
|
||||
@property DirectoryWatcher * watcher;
|
||||
@property Uploader * uploader;
|
||||
@property NSStatusItem * menubarItem;
|
||||
|
||||
@end
|
||||
|
||||
@implementation AppDelegate
|
||||
|
||||
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
||||
// Insert code here to initialize your application
|
||||
self.watcher = [[DirectoryWatcher alloc] initWithPath:[self downloadsDirectory]];
|
||||
self.watcher.delegate = self;
|
||||
[self.watcher startWatching];
|
||||
|
||||
self.uploader = [[Uploader alloc] init];
|
||||
self.uploader.delegate = self;
|
||||
|
||||
[NSUserNotificationCenter defaultUserNotificationCenter].delegate = self;
|
||||
|
||||
[self createMenuBarIcon];
|
||||
[self configureVolumeMountNotifications];
|
||||
[self showActiveMicroBits];
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(NSNotification *)aNotification {
|
||||
// Insert code here to tear down your application
|
||||
[self.watcher stopWatching];
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[[NSWorkspace sharedWorkspace].notificationCenter removeObserver:self];
|
||||
}
|
||||
|
||||
#pragma mark - Directory
|
||||
|
||||
- (void)watcher:(DirectoryWatcher *)watcher observedNewFileAtPath:(NSString *)path {
|
||||
NSString * fullPath = [watcher.path stringByAppendingPathComponent:path];
|
||||
if ([self.uploader shouldUploadFileAtPath:fullPath]) {
|
||||
[self.uploader uploadFile:fullPath];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString*)downloadsDirectory {
|
||||
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDownloadsDirectory, NSUserDomainMask, YES);
|
||||
return paths.firstObject;
|
||||
}
|
||||
|
||||
#pragma mark - Uploader delegate
|
||||
|
||||
- (void)uploader:(Uploader *)uploader transferredFile:(NSString *)file toMicroBit:(NSString *)microbit {
|
||||
[self showNotification:@"micro:bit upload" withDescription:[NSString stringWithFormat:@"%@ uploaded to %@", file.lastPathComponent, microbit]];
|
||||
}
|
||||
|
||||
- (void)uploader:(Uploader *)uploader failedToTransferFile:(NSString *)file toMicroBit:(NSString *)microbit {
|
||||
[self showNotification:@"micro:bit upload failed" withDescription:[NSString stringWithFormat:@"Couldn't transfer %@ to %@", file.lastPathComponent, microbit]];
|
||||
}
|
||||
|
||||
- (void)showNotification:(NSString*)title withDescription:(NSString*)description {
|
||||
NSUserNotification * notification = [NSUserNotification new];
|
||||
notification.title = title;
|
||||
notification.informativeText = description;
|
||||
notification.soundName = NSUserNotificationDefaultSoundName;
|
||||
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
|
||||
}
|
||||
|
||||
#pragma mark - NSUserNotificationCenterDelegate
|
||||
|
||||
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification {
|
||||
return YES;
|
||||
}
|
||||
|
||||
#pragma mark - Volume mount/unmount notification
|
||||
|
||||
- (void)configureVolumeMountNotifications {
|
||||
[[NSWorkspace sharedWorkspace].notificationCenter addObserver:self selector:@selector(volumeMountNotification:) name:NSWorkspaceDidRenameVolumeNotification object:nil];
|
||||
[[NSWorkspace sharedWorkspace].notificationCenter addObserver:self selector:@selector(volumeMountNotification:) name:NSWorkspaceDidMountNotification object:nil];
|
||||
[[NSWorkspace sharedWorkspace].notificationCenter addObserver:self selector:@selector(volumeMountNotification:) name:NSWorkspaceDidUnmountNotification object:nil];
|
||||
}
|
||||
|
||||
- (void)volumeMountNotification:(NSNotification*)sender {
|
||||
//Delay upadting the menu to give the chance for the disk to fully mount or unmount
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[self showActiveMicroBits];
|
||||
});
|
||||
}
|
||||
|
||||
#pragma mark - Menu bar app
|
||||
|
||||
- (void)createMenuBarIcon {
|
||||
self.menubarItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
|
||||
self.menubarItem.button.image = [NSImage imageNamed:@"menubar"];
|
||||
}
|
||||
|
||||
- (void)showActiveMicroBits {
|
||||
NSMenu * menu = [NSMenu new];
|
||||
NSString * countString;
|
||||
NSUInteger count = self.uploader.microBitPaths.count;
|
||||
if (count == 0) {
|
||||
countString = @"No connect micro:bits";
|
||||
}
|
||||
else if (count == 1) {
|
||||
countString = @"1 connected micro:bit";
|
||||
}
|
||||
else {
|
||||
countString = [NSString stringWithFormat:@"%lu connected micro:bits", count];
|
||||
}
|
||||
NSMenuItem * microBitCount = [[NSMenuItem alloc] initWithTitle:countString action:nil keyEquivalent:@""];
|
||||
microBitCount.enabled = NO;
|
||||
[menu addItem:microBitCount];
|
||||
|
||||
NSMenuItem * websiteItem = [[NSMenuItem alloc] initWithTitle:@"Editor" action:@selector(launchEditor:) keyEquivalent:@"e"];
|
||||
[menu addItem:websiteItem];
|
||||
|
||||
NSMenuItem * quitItem = [[NSMenuItem alloc] initWithTitle:@"Quit" action:@selector(terminate:) keyEquivalent:@"q"];
|
||||
[menu addItem:quitItem];
|
||||
|
||||
self.menubarItem.menu = menu;
|
||||
}
|
||||
|
||||
- (void)launchEditor:(id)sender {
|
||||
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://codethemicrobit.com/"]];
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,68 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"size" : "16x16",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_16x16.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "16x16",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_16x16@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "32x32",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_32x32.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "32x32",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_32x32@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "128x128",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_128x128.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "128x128",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_128x128@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "256x256",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_256x256.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "256x256",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_256x256@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "512x512",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_512x512.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "512x512",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_512x512@2x.png",
|
||||
"scale" : "2x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 574 B |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 55 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 55 KiB |
After Width: | Height: | Size: 136 KiB |
@ -0,0 +1,6 @@
|
||||
{
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
15
clients/macuploader/Microbit Uploader/Assets.xcassets/menubar.imageset/Contents.json
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"filename" : "menubar.pdf"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
},
|
||||
"properties" : {
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
BIN
clients/macuploader/Microbit Uploader/Assets.xcassets/menubar.imageset/menubar.pdf
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11201" systemVersion="15G1004" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11201"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
|
||||
<connections>
|
||||
<outlet property="delegate" destination="Voe-Tx-rLC" id="GzC-gU-4Uq"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
|
||||
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
|
||||
<customObject id="Voe-Tx-rLC" customClass="AppDelegate"/>
|
||||
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
|
||||
</objects>
|
||||
</document>
|
24
clients/macuploader/Microbit Uploader/DirectoryWatcher.h
Normal file
@ -0,0 +1,24 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class DirectoryWatcher;
|
||||
|
||||
@protocol DirectoryWatcherDelegate <NSObject>
|
||||
|
||||
- (void)watcher:(DirectoryWatcher*)watcher observedNewFileAtPath:(NSString*)path;
|
||||
|
||||
@end
|
||||
|
||||
@interface DirectoryWatcher : NSObject
|
||||
|
||||
- (instancetype)initWithPath:(NSString*)path;
|
||||
|
||||
@property (readonly) NSString * path;
|
||||
|
||||
@property id<DirectoryWatcherDelegate> delegate;
|
||||
|
||||
- (void)startWatching;
|
||||
|
||||
//Automatically called when deallocated
|
||||
- (void)stopWatching;
|
||||
|
||||
@end
|
75
clients/macuploader/Microbit Uploader/DirectoryWatcher.m
Normal file
@ -0,0 +1,75 @@
|
||||
#import "DirectoryWatcher.h"
|
||||
#import <CoreServices/CoreServices.h>
|
||||
|
||||
void callback(ConstFSEventStreamRef streamRef, void * info, size_t numEvents, void * eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[]);
|
||||
|
||||
@interface DirectoryWatcher ()
|
||||
|
||||
@property NSString * path;
|
||||
@property NSMutableSet<NSString*>* knownFiles;
|
||||
@property FSEventStreamRef stream;
|
||||
|
||||
- (void)rescanPathWithEvents:(BOOL)sendEvents;
|
||||
|
||||
@end
|
||||
|
||||
@implementation DirectoryWatcher
|
||||
|
||||
- (instancetype)initWithPath:(NSString *)path {
|
||||
if (!path) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.path = path;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[self stopWatching];
|
||||
}
|
||||
|
||||
- (void)startWatching {
|
||||
self.knownFiles = [NSMutableSet new];
|
||||
[self rescanPathWithEvents:NO];
|
||||
|
||||
CFStringRef path = (__bridge CFStringRef)(self.path);
|
||||
CFArrayRef pathsToWatch = CFArrayCreate(NULL, (const void**)&path, 1, NULL);
|
||||
CFAbsoluteTime latency = 1;
|
||||
FSEventStreamContext context = { 0, (__bridge void * _Nullable)(self), NULL, NULL, NULL };
|
||||
self.stream = FSEventStreamCreate(NULL, &callback, &context, pathsToWatch, kFSEventStreamEventIdSinceNow, latency, kFSEventStreamCreateFlagNone);
|
||||
FSEventStreamScheduleWithRunLoop(self.stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
|
||||
FSEventStreamStart(self.stream);
|
||||
}
|
||||
|
||||
- (void)stopWatching {
|
||||
if (self.stream) {
|
||||
FSEventStreamStop(self.stream);
|
||||
FSEventStreamInvalidate(self.stream);
|
||||
FSEventStreamRelease(self.stream);
|
||||
self.stream = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)rescanPathWithEvents:(BOOL)sendEvents {
|
||||
NSArray<NSString*>* downloadFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:self.path error:nil];
|
||||
NSMutableSet<NSString*>* fullSet = [NSMutableSet new];
|
||||
for (NSString * file in downloadFiles) {
|
||||
[fullSet addObject:file];
|
||||
if (![self.knownFiles containsObject:file]) {
|
||||
if (sendEvents) {
|
||||
[self.delegate watcher:self observedNewFileAtPath:file];
|
||||
}
|
||||
}
|
||||
}
|
||||
self.knownFiles = fullSet;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
void callback(ConstFSEventStreamRef streamRef, void * info, size_t numEvents, void * eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[]) {
|
||||
DirectoryWatcher * watcher = (__bridge DirectoryWatcher*)info;
|
||||
[watcher rescanPathWithEvents:YES];
|
||||
}
|
36
clients/macuploader/Microbit Uploader/Info.plist
Normal file
@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string></string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.01</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>2</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
|
||||
<key>LSUIElement</key>
|
||||
<true/>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2016 Thomas Denney. All rights reserved.</string>
|
||||
<key>NSMainNibFile</key>
|
||||
<string>MainMenu</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
</dict>
|
||||
</plist>
|
21
clients/macuploader/Microbit Uploader/Uploader.h
Normal file
@ -0,0 +1,21 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class Uploader;
|
||||
|
||||
@protocol UploaderDelegate <NSObject>
|
||||
|
||||
- (void)uploader:(Uploader*)uploader transferredFile:(NSString*)file toMicroBit:(NSString*)microbit;
|
||||
- (void)uploader:(Uploader*)uploader failedToTransferFile:(NSString*)file toMicroBit:(NSString*)microbit;
|
||||
|
||||
@end
|
||||
|
||||
@interface Uploader : NSObject
|
||||
|
||||
@property id<UploaderDelegate> delegate;
|
||||
|
||||
- (BOOL)shouldUploadFileAtPath:(NSString*)path;
|
||||
- (NSArray<NSString*>*)microBitPaths;
|
||||
- (void)uploadFile:(NSString*)file;
|
||||
- (void)uploadFile:(NSString*)file toMicroBit:(NSString*)path;
|
||||
|
||||
@end
|
74
clients/macuploader/Microbit Uploader/Uploader.m
Normal file
@ -0,0 +1,74 @@
|
||||
#import "Uploader.h"
|
||||
|
||||
@interface Uploader ()
|
||||
|
||||
@property NSOperationQueue * backgroundCopyQueue;
|
||||
|
||||
@end
|
||||
|
||||
@implementation Uploader
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.backgroundCopyQueue = [NSOperationQueue new];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)shouldUploadFileAtPath:(NSString *)path {
|
||||
//Whilst Safari is downloading the file it appends .download to the name
|
||||
NSRegularExpression * ignoreDownload = [NSRegularExpression regularExpressionWithPattern:@".download$" options:NSRegularExpressionCaseInsensitive error:nil];
|
||||
if ([ignoreDownload numberOfMatchesInString:path.lastPathComponent options:0 range:NSMakeRange(0, path.lastPathComponent.length)] > 0) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
//Chrome and Firefox create .hex files
|
||||
NSRegularExpression * hexFiles = [NSRegularExpression regularExpressionWithPattern:@".hex$" options:NSRegularExpressionCaseInsensitive error:nil];
|
||||
if ([hexFiles numberOfMatchesInString:path.lastPathComponent options:0 range:NSMakeRange(0, path.lastPathComponent.length)] > 0) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
//Safari tends to just name files 'Unknown X'
|
||||
NSRegularExpression * unknownFiles = [NSRegularExpression regularExpressionWithPattern:@"^Unknown(( |-)[0-9]+)?" options:NSRegularExpressionCaseInsensitive error:nil];
|
||||
if ([unknownFiles numberOfMatchesInString:path.lastPathComponent options:0 range:NSMakeRange(0, path.lastPathComponent.length)]) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSArray<NSString*>*)microBitPaths {
|
||||
NSArray<NSURL*>* allVolumes = [[NSFileManager defaultManager] mountedVolumeURLsIncludingResourceValuesForKeys:nil options:NSVolumeEnumerationSkipHiddenVolumes];
|
||||
NSMutableArray<NSString*>* microbitPaths = [NSMutableArray new];
|
||||
NSRegularExpression * microbitRegex = [NSRegularExpression regularExpressionWithPattern:@"^MICROBIT" options:NSRegularExpressionCaseInsensitive error:nil];
|
||||
for (NSURL * volume in allVolumes) {
|
||||
NSString * lastPathComponent = volume.lastPathComponent;
|
||||
if ([microbitRegex numberOfMatchesInString:lastPathComponent options:0 range:NSMakeRange(0, lastPathComponent.length)] > 0) {
|
||||
[microbitPaths addObject:volume.path];
|
||||
}
|
||||
}
|
||||
|
||||
return microbitPaths;
|
||||
}
|
||||
|
||||
- (void)uploadFile:(NSString *)file {
|
||||
for (NSString * microbit in [self microBitPaths]) {
|
||||
[self uploadFile:file toMicroBit:microbit];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)uploadFile:(NSString *)file toMicroBit:(NSString *)path {
|
||||
[self.backgroundCopyQueue addOperationWithBlock:^{
|
||||
NSError * copyError;
|
||||
NSString * destination = [path stringByAppendingPathComponent:file.lastPathComponent];
|
||||
if (![[NSFileManager defaultManager] copyItemAtPath:file toPath:destination error:©Error]) {
|
||||
[self.delegate uploader:self failedToTransferFile:file toMicroBit:path.lastPathComponent];
|
||||
}
|
||||
else {
|
||||
[self.delegate uploader:self transferredFile:file toMicroBit:path.lastPathComponent];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
5
clients/macuploader/Microbit Uploader/main.m
Normal file
@ -0,0 +1,5 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
int main(int argc, const char * argv[]) {
|
||||
return NSApplicationMain(argc, argv);
|
||||
}
|
40
clients/macuploader/README.md
Normal file
@ -0,0 +1,40 @@
|
||||
# micro:bit uploader for OS X
|
||||
|
||||

|
||||
|
||||
This project is a clone of the [Windows
|
||||
uploader](https://codethemicrobit.com/uploader), but for OS X. Once launched,
|
||||
the app runs in your menu bar and will automatically deploy any HEX files to
|
||||
your `micro:bit`. Like the Windows version, it is compatible with any browser
|
||||
that can run [codethemicrobit.com](http://codethemicrobit.com).
|
||||
|
||||
## Install the built version
|
||||
|
||||
1. Download the latest `.zip` release from the `Release` directory
|
||||
2. Unzip it
|
||||
3. Drag `Microbit Uploader` to your Applications folder and launch it
|
||||
|
||||
## Building
|
||||
|
||||
To build the project you'll need a copy of OS X 10.11 or higher and Xcode 8 or
|
||||
higher (you may be able to build on earlier OSes or versions of Xcode, but this
|
||||
remains untested). Once you have a development environment set up, just build
|
||||
and run `Microbit Uploader.xcodeproj`.
|
||||
|
||||
## Distributing
|
||||
|
||||
1. Open the Xcode project
|
||||
2. Product > Archive
|
||||
3. Export:
|
||||
|
||||

|
||||
|
||||
4. You will then have the option of either signing or not-signing the
|
||||
application:
|
||||
|
||||
a) If you have an Apple developer account, select 'Export a Developer
|
||||
ID-signed Application'
|
||||
|
||||
b) If you don't have a developer ID, select 'Export as a macOS App'
|
||||
|
||||
5. Zip the produced app and upload to CDN or equivalent
|
BIN
clients/macuploader/Release/Microbit Uploader v1.0.zip
Normal file
BIN
clients/macuploader/Release/Microbit Uploader v1.01.zip
Normal file
@ -19,10 +19,3 @@
|
||||
<link rel="shortcut icon" href="@appLogo@">
|
||||
<meta name="theme-color" content="@accentColor@">
|
||||
|
||||
<style>
|
||||
#root .avatar .avatar-image {
|
||||
background-image: url(https://az851932.vo.msecnd.net/pub/jovrytni/microbit.simplified.svg);
|
||||
background-size: contain;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
</style>
|
5
docfiles/target.css
Normal file
@ -0,0 +1,5 @@
|
||||
#root .avatar .avatar-image {
|
||||
background-image: url(https://az851932.vo.msecnd.net/pub/jovrytni/microbit.simplified.svg);
|
||||
background-size: contain;
|
||||
background-repeat: no-repeat;
|
||||
}
|
@ -1,3 +1,50 @@
|
||||

|
||||
|
||||
# About
|
||||
|
||||
### @description A Blocks / Javascript code editor for the micro:bit, a pocket-size computer with 5x5 display, sensors and Bluetooth.
|
||||
|
||||
The [BBC micro:bit](https://www.microbit.co.uk) is a [pocket-size computer](/device) with a 5x5 display of 25 LEDs, Bluetooth and sensors that can be programmed by anyone.
|
||||
The BBC micro:bit was made possible by many [partners](https://www.microbit.co.uk/partners).
|
||||
|
||||
The micro:bit provides an easy and fun introduction to programming and making – switch on, program it to do something fun – wear it, customize it.
|
||||
Just like Arduino, the micro:bit can be connected to and interact with sensors, displays, and other devices.
|
||||
|
||||
* [Read the docs](/docs)
|
||||
|
||||
## [Hardware: The Device](/device)
|
||||
|
||||
The BBC micro:bit is packaged with sensors, radio and other goodies. Learn about the [hardware components](/device) of the micro:bit to make the most of it!
|
||||
|
||||
## Programming: [Blocks](/blocks) or [JavaScript](/javascript)
|
||||
|
||||
You can program the micro:bit using [Blocks](/blocks) or [JavaScript](/javascript) in your web browser via the [micro:bit APIs](/reference):
|
||||
|
||||
```block
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showString("Hi!");
|
||||
})
|
||||
```
|
||||
```typescript
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showString("Hi!");
|
||||
})
|
||||
```
|
||||
|
||||
The editor work in [most modern browsers](/browsers), work [offline](/offline) once loaded and do not require any installation.
|
||||
|
||||
## [Compile and Flash: Your Program!](/device/usb)
|
||||
|
||||
When you have your code ready, you connect your micro:bit to a computer via a USB cable, so it appears as a mounted drive (named MICROBIT).
|
||||
|
||||
Compilation to ARM thumb machine code from [Blocks](/blocks) or [JavaScript](/javascript) happens in the browser. You save the ARM binary
|
||||
program to a file, which you then copy to the micro:bit drive, which flashes the micro:bit device with the new program.
|
||||
|
||||
## Simulator: Test Your Code
|
||||
|
||||
You can run your code using the micro:bit simulator, all within the confines of a web browser.
|
||||
The simulator has support for the LED screen, buttons, as well as compass, accelerometer, and digital I/O pins.
|
||||
|
||||
```sim
|
||||
basic.forever(() => {
|
||||
basic.showString("Hi!");
|
||||
@ -20,43 +67,8 @@ input.onButtonPressed(Button.B, () => {
|
||||
. # . # .
|
||||
. . # . .`);
|
||||
});
|
||||
```
|
||||
# About
|
||||
|
||||
### @description A Blocks / Javascript code editor for the micro:bit, a pocket-size computer with 5x5 display, sensors and Bluetooth.
|
||||
|
||||
The [BBC micro:bit](https://www.microbit.co.uk) is a [pocket-size computer](/device) with a 5x5 display of 25 LEDs, Bluetooth and sensors that can be programmed by anyone.
|
||||
The BBC micro:bit was made possible by many [partners](https://www.microbit.co.uk/partners).
|
||||
|
||||
The micro:bit provides an easy and fun introduction to programming and making – switch on, program it to do something fun – wear it, customize it.
|
||||
Just like Arduino, the micro:bit can be connected to and interact with sensors, displays, and other devices.
|
||||
|
||||
## Hardware: The Device
|
||||
|
||||
Learn about the [hardware components](/device) of the micro:bit to make the most of it!
|
||||
|
||||
## Programming: Blocks or JavaScript
|
||||
|
||||
You can program the micro:bit using [Blocks](/blocks) or [JavaScript](/javascript), via the [micro:bit APIs](/reference):
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showString("Hi!");
|
||||
})
|
||||
```
|
||||
|
||||
## Compile and Flash: Your Program!
|
||||
|
||||
When you have your code ready, you connect your micro:bit to a computer via a USB cable, so it appears as a mounted drive (named MICROBIT).
|
||||
|
||||
Compilation to ARM thumb machine code from [Blocks](/blocks) or [JavaScript](/javascript) happens in the browser. You save the ARM binary
|
||||
program to a file, which you then copy to the micro:bit drive, which flashes the micro:bit device with the new program.
|
||||
|
||||
## Simulator: Test Your Code
|
||||
|
||||
You can run your code using the micro:bit simulator, all within the confines of a web browser.
|
||||
The simulator has support for the LED screen, buttons, as well as compass, accelerometer, and digital I/O pins.
|
||||
|
||||
## C++ Runtime
|
||||
|
||||
The [C++ micro:bit runtime](http://lancaster-university.github.io/microbit-docs/), created at [Lancaster University](http://www.lancaster.ac.uk/), provides access to the hardware functions of the micro:bit,
|
||||
@ -65,6 +77,15 @@ as well as a set of helper functions (such as displaying a number/image/string o
|
||||
The [micro:bit library](/reference) mirrors the functions of the C++ library.
|
||||
When code is compiled to ARM machine code, the calls to JavaScript micro:bit functions are replaced with calls to the corresponding C++ functions.
|
||||
|
||||
## Open Source
|
||||
## [Command Line Tools](/cli)
|
||||
|
||||
Looking to use codethemicrobit.com in your favorite editor? Install the [command line tools](/cli) and get rolling!
|
||||
|
||||
## [Packages](/packages)
|
||||
|
||||
Create, edit and distribute your own blocks and JavaScript using [packages](/packages). Packages are hosted on GitHub and may be written
|
||||
using C++, JavaScript and/or ARM thumb.
|
||||
|
||||
## [Open Source](/open-source)
|
||||
|
||||
The code for the micro:bit is [open source](/open-source) on GitHub. Contributors are welcome!
|
||||
|
104
docs/browsers.md
Normal file
@ -0,0 +1,104 @@
|
||||
# Unsupported configuration
|
||||
|
||||
[codethemicrobit.com](https://codethemicrobit.com) doesn't currently support
|
||||
your browser or operating system. The following configurations are supported:
|
||||
|
||||
## Windows
|
||||
|
||||
You need one of these browsers running on Windows 7, Windows 8, Windows 8.1, or
|
||||
Windows 10:
|
||||
|
||||
* Internet Explorer 11
|
||||
* Microsoft Edge
|
||||
* Google Chrome
|
||||
* Mozilla Firefox
|
||||
|
||||
## Mac
|
||||
|
||||
You need one of these browsers running on OS X 10.9 Mavericks, OS X 10.10
|
||||
Yosemite, OS X 10.11 El Capitan, or macOS 10.12 Sierra:
|
||||
|
||||
* Safari
|
||||
* Google Chrome
|
||||
* Mozilla Firefox
|
||||
|
||||
## Linux
|
||||
|
||||
If you're using a Raspberry Pi, please see [the documentation
|
||||
here](/raspberry-pi).
|
||||
|
||||
You need to be running a Linux distribution recent enough to run the most recent
|
||||
version of one of the following:
|
||||
|
||||
* Google Chrome, or Chromium
|
||||
* Mozilla Firefox, Iceweasel, or Seamonkey
|
||||
|
||||
## How to check your OS or browser
|
||||
|
||||
### Windows
|
||||
|
||||
* Click on the Start menu
|
||||
* Type 'System'
|
||||
* Click on the app called 'System'
|
||||
* The version of Windows you are using will be displayed:
|
||||
|
||||

|
||||
|
||||
### Mac
|
||||
|
||||
* Click on the Apple icon in the top left
|
||||
* Click on 'About this Mac'
|
||||
* This window will be displayed:
|
||||
|
||||

|
||||
|
||||
### Internet Explorer
|
||||
|
||||
* Click on the Settings icon in the top right
|
||||
* Click 'About Internet Explorer'
|
||||
* This window will be displayed:
|
||||
|
||||

|
||||
|
||||
### Edge
|
||||
|
||||
Edge automatically updates, so you should always be using the latest version
|
||||
|
||||
* Click on the menu icon in the top right (three dots)
|
||||
* Scroll to the bottom
|
||||
* Information similar to the following will be displayed:
|
||||
|
||||

|
||||
|
||||
### Google Chrome
|
||||
|
||||
Google Chrome automatically updates, so you should always be using the latest version
|
||||
|
||||
* Click on the menu icon in the top right (three dots)
|
||||
* Click Help, and About Google Chrome
|
||||
* Information similar to the following will be displayed:
|
||||
|
||||

|
||||
|
||||
### Firefox
|
||||
|
||||
Firefox automatically updates, so you should always be using the latest version
|
||||
|
||||
* Click on the menu icon in the top right (three horizontal lines)
|
||||
* Click the question mark icon (help button)
|
||||
* Click 'About Firefox'
|
||||
|
||||

|
||||
|
||||
### Safari
|
||||
|
||||
Safari updates when your operating system updates, so if you are using the
|
||||
latest version of OS X then you'll be using the latest version of Safari.
|
||||
|
||||
* Click on the Safari menu in the top left
|
||||
* Click 'About Safari'
|
||||
|
||||

|
||||
|
||||
IT administrators should check which browser versions are supported
|
||||
[here](/browsers/technical).
|
16
docs/browsers/linux.md
Normal file
@ -0,0 +1,16 @@
|
||||
# Recommended browser for Linux
|
||||
|
||||
As you are using Linux, it is recommended that you use [Mozilla
|
||||
Firefox][firefox] or [Google Chrome][chrome].
|
||||
|
||||
Please see [here][technical] for technical information on which browsers are
|
||||
supported, or [here][versions] to check which version you are using.
|
||||
|
||||
[edge]: https://www.microsoft.com/en-us/windows/microsoft-edge
|
||||
[ie]: https://www.microsoft.com/en-us/download/internet-explorer.aspx
|
||||
[firefox]: https://www.mozilla.org/en-US/firefox/new/
|
||||
[chrome]: https://www.google.com/chrome/
|
||||
[opera]: https://www.opera.com
|
||||
[safari]: http://www.apple.com/safari/
|
||||
[technical]: /browsers/technical
|
||||
[versions]: /browsers
|
16
docs/browsers/mac.md
Normal file
@ -0,0 +1,16 @@
|
||||
# Recommended browser for Mac
|
||||
|
||||
As you are using a Mac, it is recommended that you use [Safari][]. Alternatively,
|
||||
[Google Chrome][chrome] and [Mozilla Firefox][firefox] are also supported.
|
||||
|
||||
Please see [here][technical] for technical information on which browsers are
|
||||
supported, or [here][versions] to check which version you are using.
|
||||
|
||||
[edge]: https://www.microsoft.com/en-us/windows/microsoft-edge
|
||||
[ie]: https://www.microsoft.com/en-us/download/internet-explorer.aspx
|
||||
[firefox]: https://www.mozilla.org/en-US/firefox/new/
|
||||
[chrome]: https://www.google.com/chrome/
|
||||
[opera]: https://www.opera.com
|
||||
[safari]: http://www.apple.com/safari/
|
||||
[technical]: /browsers/technical
|
||||
[versions]: /browsers
|
36
docs/browsers/technical.md
Normal file
@ -0,0 +1,36 @@
|
||||
# Technical information about browser support
|
||||
|
||||
[codethemicrobit.com][] requires that you use a recent version of a modern
|
||||
browser, such as Microsoft Edge, Google Chrome, Mozilla Firefox, Safari, Opera,
|
||||
or IE11. This is because the editor uses modern web technologies such as [web
|
||||
workers][] to enable compiling [TypeScript][] in the browser, or the using the
|
||||
same [Monaco][] editor that powers [Visual Studio Code][].
|
||||
|
||||
[codethemicrobit.com]: https://codethemicrobit.com
|
||||
[web workers]: http://www.w3.org/TR/workers/
|
||||
[typescript]: http://www.typescriptlang.org
|
||||
[monaco]: https://microsoft.github.io/monaco-editor/
|
||||
[visual studio code]: http://code.visualstudio.com
|
||||
|
||||
Most modern browsers automatically update themselves, but in some environments
|
||||
such as schools these automatic updates are disabled for security. **We
|
||||
strongly recommend that you use the most recent version of any of these
|
||||
browsers**, but if you can't then you must use at least:
|
||||
|
||||
| Browser | Minimum version | Release date | Windows | Mac |
|
||||
| ----------------- | --------------- | -------------- | ----------- | ---------- |
|
||||
| Edge | 12 | March 2015 | Windows 10+ | N/A |
|
||||
| Internet Explorer | 11 | October 2013 | Windows 7+ | N/A |
|
||||
| Mozilla Firefox | 31 ESR | July 2014 | Windows XP+ | OS X 10.6+ |
|
||||
| Google Chrome | 38 | October 2014 | Windows XP+ | OS X 10.6+ |
|
||||
| Safari | 9 | September 2015 | N/A | OS X 10.9+ |
|
||||
| Opera | 21 | May 2014 | Windows 7+ | OS X 10.9+ |
|
||||
|
||||
|
||||
Please see our information for which browsers are recommended for [Windows][],
|
||||
[Mac][], [Linux][], or [Raspberry Pi][].
|
||||
|
||||
[Windows]: /browsers/windows
|
||||
[Mac]: /browsers/mac
|
||||
[Linux]: /browsers/linux
|
||||
[Raspberry Pi]: /raspberry-pi
|
18
docs/browsers/windows.md
Normal file
@ -0,0 +1,18 @@
|
||||
# Recommended browser for Windows
|
||||
|
||||
We recommend [Microsoft Edge][edge] if you are running Windows 10, but users on
|
||||
Windows 7 or higher can use [Internet Explorer 11][ie] or recent versions of
|
||||
[Mozilla Firefox][firefox], [Google Chrome][chrome], or [Opera][opera].
|
||||
|
||||
|
||||
Please see [here][technical] for technical information on which browsers are
|
||||
supported, or [here][versions] to check which version you are using.
|
||||
|
||||
[edge]: https://www.microsoft.com/en-us/windows/microsoft-edge
|
||||
[ie]: https://www.microsoft.com/en-us/download/internet-explorer.aspx
|
||||
[firefox]: https://www.mozilla.org/en-US/firefox/new/
|
||||
[chrome]: https://www.google.com/chrome/
|
||||
[opera]: https://www.opera.com
|
||||
[safari]: http://www.apple.com/safari/
|
||||
[technical]: /browsers/technical
|
||||
[versions]: /browsers
|
@ -1,6 +1,4 @@
|
||||
# Running programs on your micro:bit
|
||||
|
||||
How to compile, transfer, and run a program on your micro:bit.
|
||||
# Uploading programs on your micro:bit
|
||||
|
||||
While you're writing and testing your programs, you'll mostly be [running them
|
||||
in the simulator](/device/simulator), but once you've finished your program you
|
||||
@ -12,169 +10,22 @@ The basic steps are:
|
||||
2. Click **Download** and download the `.hex` file
|
||||
3. Copy the `.hex` file from your computer onto the micro:bit drive
|
||||
|
||||
## Requirements
|
||||

|
||||
|
||||
You need the following things to transfer and run a script on your micro:bit:
|
||||
## Instructions
|
||||
|
||||
* A-Male to Micro USB cable to connect your computer to your micro:bit. This is
|
||||
the same cable that is commonly used to connect a smart phone to a computer.
|
||||
* A PC running Windows 7 or later, or a Mac running OS X 10.6 or later
|
||||
Pick the instructions for your operating system and browser:
|
||||
|
||||
## Step 1: Connect your micro:bit to your computer
|
||||
* [Windows - Microsoft Edge](/device/usb/windows-edge)
|
||||
* [Windows - Internet Explorer](/device/usb/windows-ie)
|
||||
* [Windows - Chrome](/device/usb/windows-chrome)
|
||||
* [Windows - Firefox](/device/usb/windows-firefox)
|
||||
* [Mac - Safari](/device/usb/mac-safari)
|
||||
* [Mac - Chrome](/device/usb/mac-chrome)
|
||||
* [Mac - Firefox](/device/usb/mac-firefox)
|
||||
|
||||
First, connect the micro:bit:
|
||||
### ~hint
|
||||
|
||||
1. Connect the small end of the USB cable to the micro USB port on your micro:bit.
|
||||
|
||||
2. Connect the other end of the USB cable to a USB port on your computer.
|
||||
|
||||
Your computer should recognise your micro:bit as a new drive. On computers
|
||||
running Windows, `MICROBIT` appears as a drive under Devices and drives. On a Mac
|
||||
it appears as a new drive under Devices.
|
||||
|
||||
**Windows**
|
||||
|
||||

|
||||
|
||||
**Mac**
|
||||
|
||||

|
||||
|
||||
## Step 2: Download your program
|
||||
|
||||
1. Open your project on [codethemicrobit.com](https://codethemicrobit.com)
|
||||
2. Click **Download**
|
||||
3. When prompted, choose to **save** the compiled file onto your computer. The
|
||||
prompt will be different depending on which browser you are using, or
|
||||
whether you are using a Windows computer or a Mac
|
||||
|
||||
### Windows
|
||||
|
||||
#### Chrome
|
||||
|
||||
Your `.hex` file appears as a download at the bottom of the browser. Click on
|
||||
the arrow next to the name of the file and then click **Show in folder**.
|
||||
|
||||

|
||||
|
||||
Drag and drop the `.hex` file from the download folder onto the `MICROBIT` drive.
|
||||
|
||||
#### Firefox
|
||||
|
||||
A window will appear asking whether you want to save or open the `.hex` file.
|
||||
Select **Save File** and then select **OK**.
|
||||
|
||||

|
||||
|
||||
The file will then appear in your downloads in the top right of your browser.
|
||||
Click the **folder icon** next to the filename to open it in Windows Explorer.
|
||||
|
||||

|
||||
|
||||
Drag and drop the `.hex` file from the download folder onto the `MICROBIT` drive.
|
||||
|
||||
#### Microsoft Edge
|
||||
|
||||
A message will appear at the bottom of the browser asking what you want to do
|
||||
with the file. Click **Save**:
|
||||
|
||||

|
||||
|
||||
Then click **Open folder** and drag and drop the file from your Downloads to
|
||||
your `MICROBIT` drive.
|
||||
|
||||

|
||||
|
||||
#### Internet Explorer
|
||||
|
||||
A message will appear at the bottom of the browser asking what you want to do
|
||||
with the file. Click **Save**:
|
||||
|
||||

|
||||
|
||||
Then click **Open folder** and drag and drop the file from your Downloads to
|
||||
your `MICROBIT` drive.
|
||||
|
||||

|
||||
|
||||
### Mac
|
||||
|
||||
#### Safari
|
||||
|
||||
When you select **Download** in Safari a file called `Unknown` will be
|
||||
downloaded into your Downloads folder. Open your Downloads folder and drag and
|
||||
drop the file onto your `MICROBIT` drive, under Devices:
|
||||
|
||||

|
||||
|
||||
#### Firefox
|
||||
|
||||
A dialogue box will appear, asking whether you would like to open or save your
|
||||
hex file. Select **Save file** and click **OK** and the file will then appear in
|
||||
your downloads in the top right of your browser. Right click on the file and
|
||||
click on **Show in Finder** and the file will appear in your downloads folder.
|
||||
Select the file and drag and drop it onto your `MICROBIT` drive.
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
#### Chrome
|
||||
|
||||
When you select **Download** in Chrome, the file will appear at the bottom of
|
||||
the browser. Click on the small arrow and select **Show in Finder**. This will
|
||||
show the file in your download folder. Drag and drop the file onto your
|
||||
`MICROBIT` drive.
|
||||
|
||||

|
||||
|
||||
## Step 3: Transfer the file to your micro:bit
|
||||
|
||||
* Once you've found the folder containing your `.hex` file, drag and drop it
|
||||
onto your `MICROBIT` drive
|
||||
* If you're using Windows, you can use **Send to** as described below
|
||||
* The LED on the back of your micro:bit flashes during the transfer (which
|
||||
should only take a few seconds).
|
||||
* Once transferred, the code will run automatically on your micro:bit. To rerun
|
||||
your program, press the reset button on the back of your micro:bit. The reset
|
||||
button automatically runs the newest file on the micro:bit.
|
||||
|
||||
**Send to**: If you're using Windows you use *Send to* in File Explorer:
|
||||
|
||||
- In File Explorer, right-click on the hex file (created in Step 2 above), choose **Send to**, and then **MICROBIT**.
|
||||
|
||||

|
||||
|
||||
By copying the script onto the `MICROBIT` drive, you have programmed it into the
|
||||
flash memory on the micro:bit, which means even after you unplug the micro:bit,
|
||||
your program will still run if the micro:bit is powered by battery.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
You can’t drag and drop more than one hex file at once onto your micro:bit. If
|
||||
you try to drag and drop a second hex file onto your micro:bit before the first
|
||||
file has finished downloading, then the second file may fail in different ways.
|
||||
|
||||
When the first program has been written to the micro:bit, the drive will
|
||||
disengage. If you drag and drop a second file at this point it may not find the
|
||||
drive and the second write will fail.
|
||||
|
||||
The errors may look like this:
|
||||
|
||||
**Windows**
|
||||
|
||||

|
||||
|
||||
**Mac**
|
||||
|
||||

|
||||
|
||||
Or it may appear that there are two hex files on your micro:bit so the micro:bit
|
||||
won’t be able to run multiple files. To rectify this, unplug your micro:bit and
|
||||
plug it in again. Make sure that your micro:bit appears as `MICROBIT` and not
|
||||
`MAINTENANCE`.
|
||||
|
||||
### See also
|
||||
|
||||
[Run code in a browser](/device/simulator)
|
||||
Transfer not working? See some [troubleshooting tips](/device/usb/troubleshooting).
|
||||
|
||||
### ~
|
||||
|
69
docs/device/usb/mac-chrome.md
Normal file
@ -0,0 +1,69 @@
|
||||
# Uploading from Chrome for Mac
|
||||
|
||||
While you're writing and testing your programs, you'll mostly be [running them
|
||||
in the simulator](/device/simulator), but once you've finished your program you
|
||||
can **compile** it and run it on your micro:bit.
|
||||
|
||||
The basic steps are:
|
||||
|
||||
1. Connect your micro:bit to your computer via USB
|
||||
2. Click **Download** and download the `.hex` file
|
||||
3. Copy the `.hex` file from your computer onto the micro:bit drive
|
||||
|
||||
## Requirements
|
||||
|
||||
You need the following things to transfer and run a script on your micro:bit:
|
||||
|
||||
* A-Male to Micro USB cable to connect your computer to your micro:bit. This is
|
||||
the same cable that is commonly used to connect a smart phone to a computer.
|
||||
* A PC running Windows 7 or later, or a Mac running OS X 10.6 or later
|
||||
|
||||
## Step 1: Connect your micro:bit to your computer
|
||||
|
||||
First, connect the micro:bit:
|
||||
|
||||
1. Connect the small end of the USB cable to the micro USB port on your micro:bit.
|
||||
|
||||
2. Connect the other end of the USB cable to a USB port on your computer.
|
||||
|
||||
Your computer should recognise your micro:bit as a new drive. On computers
|
||||
running Windows, `MICROBIT` appears as a drive under Devices and drives. On a Mac
|
||||
it appears as a new drive under Devices.
|
||||
|
||||

|
||||
|
||||
## Step 2: Download your program
|
||||
|
||||
1. Open your project on [codethemicrobit.com](https://codethemicrobit.com)
|
||||
2. Click **Download**
|
||||
3. When prompted, choose to **save** the compiled file onto your computer. The
|
||||
prompt will be different depending on which browser you are using, or
|
||||
whether you are using a Windows computer or a Mac
|
||||
|
||||
When you select **Download** in Chrome, the file will appear at the bottom of
|
||||
the browser. Click on the small arrow and select **Show in Finder**. This will
|
||||
show the file in your download folder. Drag and drop the file onto your
|
||||
`MICROBIT` drive.
|
||||
|
||||

|
||||
|
||||
## Step 3: Transfer the file to your micro:bit
|
||||
|
||||
* Once you've found the folder containing your `.hex` file, drag and drop it
|
||||
onto your `MICROBIT` drive
|
||||
* The LED on the back of your micro:bit flashes during the transfer (which
|
||||
should only take a few seconds).
|
||||
* Once transferred, the code will run automatically on your micro:bit. To rerun
|
||||
your program, press the reset button on the back of your micro:bit. The reset
|
||||
button automatically runs the newest file on the micro:bit.
|
||||
|
||||
By copying the script onto the `MICROBIT` drive, you have programmed it into the
|
||||
flash memory on the micro:bit, which means even after you unplug the micro:bit,
|
||||
your program will still run if the micro:bit is powered by battery.
|
||||
|
||||
|
||||
### ~hint
|
||||
|
||||
Transfer not working? See some [troubleshooting tips](/device/usb/troubleshooting).
|
||||
|
||||
### ~
|
71
docs/device/usb/mac-firefox.md
Normal file
@ -0,0 +1,71 @@
|
||||
# Uploading from Firefox for Mac
|
||||
|
||||
While you're writing and testing your programs, you'll mostly be [running them
|
||||
in the simulator](/device/simulator), but once you've finished your program you
|
||||
can **compile** it and run it on your micro:bit.
|
||||
|
||||
The basic steps are:
|
||||
|
||||
1. Connect your micro:bit to your computer via USB
|
||||
2. Click **Download** and download the `.hex` file
|
||||
3. Copy the `.hex` file from your computer onto the micro:bit drive
|
||||
|
||||
## Requirements
|
||||
|
||||
You need the following things to transfer and run a script on your micro:bit:
|
||||
|
||||
* A-Male to Micro USB cable to connect your computer to your micro:bit. This is
|
||||
the same cable that is commonly used to connect a smart phone to a computer.
|
||||
* A PC running Windows 7 or later, or a Mac running OS X 10.6 or later
|
||||
|
||||
## Step 1: Connect your micro:bit to your computer
|
||||
|
||||
First, connect the micro:bit:
|
||||
|
||||
1. Connect the small end of the USB cable to the micro USB port on your micro:bit.
|
||||
|
||||
2. Connect the other end of the USB cable to a USB port on your computer.
|
||||
|
||||
Your computer should recognise your micro:bit as a new drive. On computers
|
||||
running Windows, `MICROBIT` appears as a drive under Devices and drives. On a Mac
|
||||
it appears as a new drive under Devices.
|
||||
|
||||

|
||||
|
||||
## Step 2: Download your program
|
||||
|
||||
1. Open your project on [codethemicrobit.com](https://codethemicrobit.com)
|
||||
2. Click **Download**
|
||||
3. When prompted, choose to **save** the compiled file onto your computer. The
|
||||
prompt will be different depending on which browser you are using, or
|
||||
whether you are using a Windows computer or a Mac
|
||||
|
||||
A dialogue box will appear, asking whether you would like to open or save your
|
||||
hex file. Select **Save file** and click **OK** and the file will then appear in
|
||||
your downloads in the top right of your browser. Right click on the file and
|
||||
click on **Show in Finder** and the file will appear in your downloads folder.
|
||||
Select the file and drag and drop it onto your `MICROBIT` drive.
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
## Step 3: Transfer the file to your micro:bit
|
||||
|
||||
* Once you've found the folder containing your `.hex` file, drag and drop it
|
||||
onto your `MICROBIT` drive
|
||||
* The LED on the back of your micro:bit flashes during the transfer (which
|
||||
should only take a few seconds).
|
||||
* Once transferred, the code will run automatically on your micro:bit. To rerun
|
||||
your program, press the reset button on the back of your micro:bit. The reset
|
||||
button automatically runs the newest file on the micro:bit.
|
||||
|
||||
By copying the script onto the `MICROBIT` drive, you have programmed it into the
|
||||
flash memory on the micro:bit, which means even after you unplug the micro:bit,
|
||||
your program will still run if the micro:bit is powered by battery.
|
||||
|
||||
### ~hint
|
||||
|
||||
Transfer not working? See some [troubleshooting tips](/device/usb/troubleshooting).
|
||||
|
||||
### ~
|
68
docs/device/usb/mac-safari.md
Normal file
@ -0,0 +1,68 @@
|
||||
# Uploading from Safari for Mac
|
||||
|
||||
While you're writing and testing your programs, you'll mostly be [running them
|
||||
in the simulator](/device/simulator), but once you've finished your program you
|
||||
can **compile** it and run it on your micro:bit.
|
||||
|
||||
The basic steps are:
|
||||
|
||||
1. Connect your micro:bit to your computer via USB
|
||||
2. Click **Download** and download the `.hex` file
|
||||
3. Copy the `.hex` file from your computer onto the micro:bit drive
|
||||
|
||||
## Requirements
|
||||
|
||||
You need the following things to transfer and run a script on your micro:bit:
|
||||
|
||||
* A-Male to Micro USB cable to connect your computer to your micro:bit. This is
|
||||
the same cable that is commonly used to connect a smart phone to a computer.
|
||||
* A PC running Windows 7 or later, or a Mac running OS X 10.6 or later
|
||||
|
||||
## Step 1: Connect your micro:bit to your computer
|
||||
|
||||
First, connect the micro:bit:
|
||||
|
||||
1. Connect the small end of the USB cable to the micro USB port on your micro:bit.
|
||||
|
||||
2. Connect the other end of the USB cable to a USB port on your computer.
|
||||
|
||||
Your computer should recognise your micro:bit as a new drive. On computers
|
||||
running Windows, `MICROBIT` appears as a drive under Devices and drives. On a Mac
|
||||
it appears as a new drive under Devices.
|
||||
|
||||

|
||||
|
||||
## Step 2: Download your program
|
||||
|
||||
1. Open your project on [codethemicrobit.com](https://codethemicrobit.com)
|
||||
2. Click **Download**
|
||||
3. When prompted, choose to **save** the compiled file onto your computer. The
|
||||
prompt will be different depending on which browser you are using, or
|
||||
whether you are using a Windows computer or a Mac
|
||||
|
||||
When you select **Download** in Safari a file called `Unknown` will be
|
||||
downloaded into your Downloads folder. Open your Downloads folder and drag and
|
||||
drop the file onto your `MICROBIT` drive, under Devices:
|
||||
|
||||

|
||||
|
||||
## Step 3: Transfer the file to your micro:bit
|
||||
|
||||
* Once you've found the folder containing your `.hex` file, drag and drop it
|
||||
onto your `MICROBIT` drive
|
||||
* The LED on the back of your micro:bit flashes during the transfer (which
|
||||
should only take a few seconds).
|
||||
* Once transferred, the code will run automatically on your micro:bit. To rerun
|
||||
your program, press the reset button on the back of your micro:bit. The reset
|
||||
button automatically runs the newest file on the micro:bit.
|
||||
|
||||
By copying the script onto the `MICROBIT` drive, you have programmed it into the
|
||||
flash memory on the micro:bit, which means even after you unplug the micro:bit,
|
||||
your program will still run if the micro:bit is powered by battery.
|
||||
|
||||
|
||||
### ~hint
|
||||
|
||||
Transfer not working? See some [troubleshooting tips](/device/usb/troubleshooting).
|
||||
|
||||
### ~
|
24
docs/device/usb/troubleshooting.md
Normal file
@ -0,0 +1,24 @@
|
||||
# Troubleshooting Transfer
|
||||
|
||||
You can’t drag and drop more than one hex file at once onto your micro:bit. If
|
||||
you try to drag and drop a second hex file onto your micro:bit before the first
|
||||
file has finished downloading, then the second file may fail in different ways.
|
||||
|
||||
When the first program has been written to the micro:bit, the drive will
|
||||
disengage. If you drag and drop a second file at this point it may not find the
|
||||
drive and the second write will fail.
|
||||
|
||||
The errors may look like this:
|
||||
|
||||
**Windows**
|
||||
|
||||

|
||||
|
||||
**Mac**
|
||||
|
||||

|
||||
|
||||
Or it may appear that there are two hex files on your micro:bit so the micro:bit
|
||||
won’t be able to run multiple files. To rectify this, unplug your micro:bit and
|
||||
plug it in again. Make sure that your micro:bit appears as `MICROBIT` and not
|
||||
`MAINTENANCE`.
|
79
docs/device/usb/windows-chrome.md
Normal file
@ -0,0 +1,79 @@
|
||||
# Uploading from Chrome for Windows
|
||||
|
||||
While you're writing and testing your programs, you'll mostly be [running them
|
||||
in the simulator](/device/simulator), but once you've finished your program you
|
||||
can **compile** it and run it on your micro:bit.
|
||||
|
||||
The basic steps are:
|
||||
|
||||
1. Connect your micro:bit to your computer via USB
|
||||
2. Click **Download** and download the `.hex` file
|
||||
3. Copy the `.hex` file from your computer onto the micro:bit drive
|
||||
|
||||
### ~hint
|
||||
|
||||
You can use the [micro:bit uploader](/uploader) to automatically deploy ``.hex`` files to your micro:bit!
|
||||

|
||||
|
||||
### ~
|
||||
|
||||
## Requirements
|
||||
|
||||
You need the following things to transfer and run a script on your micro:bit:
|
||||
|
||||
* A-Male to Micro USB cable to connect your computer to your micro:bit. This is
|
||||
the same cable that is commonly used to connect a smart phone to a computer.
|
||||
* A PC running Windows 7 or later, or a Mac running OS X 10.6 or later
|
||||
|
||||
## Step 1: Connect your micro:bit to your computer
|
||||
|
||||
First, connect the micro:bit:
|
||||
|
||||
1. Connect the small end of the USB cable to the micro USB port on your micro:bit.
|
||||
|
||||
2. Connect the other end of the USB cable to a USB port on your computer.
|
||||
|
||||
Your computer should recognise your micro:bit as a new drive. On computers
|
||||
running Windows, `MICROBIT` appears as a drive under Devices and drives. On a Mac
|
||||
it appears as a new drive under Devices.
|
||||
|
||||

|
||||
|
||||
## Step 2: Download your program
|
||||
|
||||
1. Open your project on [codethemicrobit.com](https://codethemicrobit.com)
|
||||
2. Click **Download**
|
||||
3. When prompted, choose to **save** the compiled file onto your computer. The
|
||||
prompt will be different depending on which browser you are using, or
|
||||
whether you are using a Windows computer or a Mac
|
||||
|
||||
Your `.hex` file appears as a download at the bottom of the browser. Click on
|
||||
the arrow next to the name of the file and then click **Show in folder**.
|
||||
|
||||

|
||||
|
||||
Drag and drop the `.hex` file from the download folder onto the `MICROBIT` drive.
|
||||
|
||||
## Step 3: Transfer the file to your micro:bit
|
||||
|
||||
* Once you've found the folder containing your `.hex` file, drag and drop it
|
||||
onto your `MICROBIT` drive
|
||||
* The LED on the back of your micro:bit flashes during the transfer (which
|
||||
should only take a few seconds).
|
||||
* Once transferred, the code will run automatically on your micro:bit. To rerun
|
||||
your program, press the reset button on the back of your micro:bit. The reset
|
||||
button automatically runs the newest file on the micro:bit.
|
||||
|
||||
In File Explorer, right-click on the hex file (created in Step 2 above), choose **Send to**, and then **MICROBIT**.
|
||||
|
||||

|
||||
|
||||
By copying the script onto the `MICROBIT` drive, you have programmed it into the
|
||||
flash memory on the micro:bit, which means even after you unplug the micro:bit,
|
||||
your program will still run if the micro:bit is powered by battery.
|
||||
|
||||
### ~hint
|
||||
|
||||
Transfer not working? See some [troubleshooting tips](/device/usb/troubleshooting).
|
||||
|
||||
### ~
|
89
docs/device/usb/windows-edge.md
Normal file
@ -0,0 +1,89 @@
|
||||
# Uploading from Edge on Windows
|
||||
|
||||
How to compile, transfer, and run a program on your micro:bit on **Microsoft Edge**.
|
||||
|
||||
While you're writing and testing your programs, you'll mostly be [running them
|
||||
in the simulator](/device/simulator), but once you've finished your program you
|
||||
can **compile** it and run it on your micro:bit.
|
||||
|
||||
The basic steps are:
|
||||
|
||||
1. Connect your micro:bit to your computer via USB
|
||||
2. Click **Download** and download the `.hex` file
|
||||
3. Copy the `.hex` file from your computer onto the micro:bit drive
|
||||
|
||||
### ~hint
|
||||
|
||||
You can use the [micro:bit uploader](/uploader) to automatically deploy ``.hex`` files to your micro:bit!
|
||||

|
||||
|
||||
### ~
|
||||
|
||||
## Requirements
|
||||
|
||||
You need the following things to transfer and run a script on your micro:bit:
|
||||
|
||||
* A-Male to Micro USB cable to connect your computer to your micro:bit. This is
|
||||
the same cable that is commonly used to connect a smart phone to a computer.
|
||||
* A PC running Windows 7 or later, or a Mac running OS X 10.6 or later
|
||||
|
||||
## Step 1: Connect your micro:bit to your computer
|
||||
|
||||
First, connect the micro:bit:
|
||||
|
||||
1. Connect the small end of the USB cable to the micro USB port on your micro:bit.
|
||||
|
||||
2. Connect the other end of the USB cable to a USB port on your computer.
|
||||
|
||||
Your computer should recognise your micro:bit as a new drive. On computers
|
||||
running Windows, `MICROBIT` appears as a drive under Devices and drives. On a Mac
|
||||
it appears as a new drive under Devices.
|
||||
|
||||

|
||||
|
||||
## Step 2: Download your program
|
||||
|
||||
1. Open your project on [codethemicrobit.com](https://codethemicrobit.com)
|
||||
2. Click **Download**
|
||||
3. When prompted, choose to **save** the compiled file onto your computer. The
|
||||
prompt will be different depending on which browser you are using, or
|
||||
whether you are using a Windows computer or a Mac
|
||||
|
||||
A message will appear at the bottom of the browser asking what you want to do
|
||||
with the file. Click **Save**:
|
||||
|
||||

|
||||
|
||||
Then click **Open folder** and drag and drop the file from your Downloads to
|
||||
your `MICROBIT` drive.
|
||||
|
||||

|
||||
|
||||
## Step 3: Transfer the file to your micro:bit
|
||||
|
||||
* Once you've found the folder containing your `.hex` file, drag and drop it
|
||||
onto your `MICROBIT` drive
|
||||
* If you're using Windows, you can use **Send to** as described below
|
||||
* The LED on the back of your micro:bit flashes during the transfer (which
|
||||
should only take a few seconds).
|
||||
* Once transferred, the code will run automatically on your micro:bit. To rerun
|
||||
your program, press the reset button on the back of your micro:bit. The reset
|
||||
button automatically runs the newest file on the micro:bit.
|
||||
|
||||
In File Explorer, right-click on the hex file (created in Step 2 above), choose **Send to**, and then **MICROBIT**.
|
||||
|
||||

|
||||
|
||||
By copying the script onto the `MICROBIT` drive, you have programmed it into the
|
||||
flash memory on the micro:bit, which means even after you unplug the micro:bit,
|
||||
your program will still run if the micro:bit is powered by battery.
|
||||
|
||||
If you want to save time, you can use the [micro:bit uploader](/uploader) to
|
||||
automatically deploy hex files to your micro:bit. It works on Windows and is
|
||||
compatible with any browser.
|
||||
|
||||
### ~hint
|
||||
|
||||
Transfer not working? See some [troubleshooting tips](/device/usb/troubleshooting).
|
||||
|
||||
### ~
|
86
docs/device/usb/windows-firefox.md
Normal file
@ -0,0 +1,86 @@
|
||||
# Uploading from Firefox on Windows
|
||||
|
||||
How to compile, transfer, and run a program on your micro:bit on **Firefox for Windows**.
|
||||
|
||||
While you're writing and testing your programs, you'll mostly be [running them
|
||||
in the simulator](/device/simulator), but once you've finished your program you
|
||||
can **compile** it and run it on your micro:bit.
|
||||
|
||||
The basic steps are:
|
||||
|
||||
1. Connect your micro:bit to your computer via USB
|
||||
2. Click **Download** and download the `.hex` file
|
||||
3. Copy the `.hex` file from your computer onto the micro:bit drive
|
||||
|
||||
### ~hint
|
||||
|
||||
You can use the [micro:bit uploader](/uploader) to automatically deploy ``.hex`` files to your micro:bit!
|
||||

|
||||
|
||||
### ~
|
||||
|
||||
## Requirements
|
||||
|
||||
You need the following things to transfer and run a script on your micro:bit:
|
||||
|
||||
* A-Male to Micro USB cable to connect your computer to your micro:bit. This is
|
||||
the same cable that is commonly used to connect a smart phone to a computer.
|
||||
* A PC running Windows 7 or later, or a Mac running OS X 10.6 or later
|
||||
|
||||
## Step 1: Connect your micro:bit to your computer
|
||||
|
||||
First, connect the micro:bit:
|
||||
|
||||
1. Connect the small end of the USB cable to the micro USB port on your micro:bit.
|
||||
|
||||
2. Connect the other end of the USB cable to a USB port on your computer.
|
||||
|
||||
Your computer should recognise your micro:bit as a new drive. On computers
|
||||
running Windows, `MICROBIT` appears as a drive under Devices and drives. On a Mac
|
||||
it appears as a new drive under Devices.
|
||||
|
||||

|
||||
|
||||
## Step 2: Download your program
|
||||
|
||||
1. Open your project on [codethemicrobit.com](https://codethemicrobit.com)
|
||||
2. Click **Download**
|
||||
3. When prompted, choose to **save** the compiled file onto your computer. The
|
||||
prompt will be different depending on which browser you are using, or
|
||||
whether you are using a Windows computer or a Mac
|
||||
|
||||
A window will appear asking whether you want to save or open the `.hex` file.
|
||||
Select **Save File** and then select **OK**.
|
||||
|
||||

|
||||
|
||||
The file will then appear in your downloads in the top right of your browser.
|
||||
Click the **folder icon** next to the filename to open it in Windows Explorer.
|
||||
|
||||

|
||||
|
||||
Drag and drop the `.hex` file from the download folder onto the `MICROBIT` drive.
|
||||
## Step 3: Transfer the file to your micro:bit
|
||||
|
||||
* Once you've found the folder containing your `.hex` file, drag and drop it
|
||||
onto your `MICROBIT` drive
|
||||
* If you're using Windows, you can use **Send to** as described below
|
||||
* The LED on the back of your micro:bit flashes during the transfer (which
|
||||
should only take a few seconds).
|
||||
* Once transferred, the code will run automatically on your micro:bit. To rerun
|
||||
your program, press the reset button on the back of your micro:bit. The reset
|
||||
button automatically runs the newest file on the micro:bit.
|
||||
|
||||
In File Explorer, right-click on the hex file (created in Step 2 above), choose **Send to**, and then **MICROBIT**.
|
||||
|
||||

|
||||
|
||||
By copying the script onto the `MICROBIT` drive, you have programmed it into the
|
||||
flash memory on the micro:bit, which means even after you unplug the micro:bit,
|
||||
your program will still run if the micro:bit is powered by battery.
|
||||
|
||||
### ~hint
|
||||
|
||||
Transfer not working? See some [troubleshooting tips](/device/usb/troubleshooting).
|
||||
|
||||
### ~
|
86
docs/device/usb/windows-ie.md
Normal file
@ -0,0 +1,86 @@
|
||||
# Uploading from Internet Explorer on Windows
|
||||
|
||||
While you're writing and testing your programs, you'll mostly be [running them
|
||||
in the simulator](/device/simulator), but once you've finished your program you
|
||||
can **compile** it and run it on your micro:bit.
|
||||
|
||||
The basic steps are:
|
||||
|
||||
1. Connect your micro:bit to your computer via USB
|
||||
2. Click **Download** and download the `.hex` file
|
||||
3. Copy the `.hex` file from your computer onto the micro:bit drive
|
||||
|
||||
### ~hint
|
||||
|
||||
You can use the [micro:bit uploader](/uploader) to automatically deploy ``.hex`` files to your micro:bit!
|
||||

|
||||
|
||||
### ~
|
||||
|
||||
## Requirements
|
||||
|
||||
You need the following things to transfer and run a script on your micro:bit:
|
||||
|
||||
* A-Male to Micro USB cable to connect your computer to your micro:bit. This is
|
||||
the same cable that is commonly used to connect a smart phone to a computer.
|
||||
* A PC running Windows 7 or later, or a Mac running OS X 10.6 or later
|
||||
|
||||
## Step 1: Connect your micro:bit to your computer
|
||||
|
||||
First, connect the micro:bit:
|
||||
|
||||
1. Connect the small end of the USB cable to the micro USB port on your micro:bit.
|
||||
|
||||
2. Connect the other end of the USB cable to a USB port on your computer.
|
||||
|
||||
Your computer should recognise your micro:bit as a new drive. On computers
|
||||
running Windows, `MICROBIT` appears as a drive under Devices and drives. On a Mac
|
||||
it appears as a new drive under Devices.
|
||||
|
||||

|
||||
|
||||
## Step 2: Download your program
|
||||
|
||||
1. Open your project on [codethemicrobit.com](https://codethemicrobit.com)
|
||||
2. Click **Download**
|
||||
3. When prompted, choose to **save** the compiled file onto your computer. The
|
||||
prompt will be different depending on which browser you are using, or
|
||||
whether you are using a Windows computer or a Mac
|
||||
|
||||
A message will appear at the bottom of the browser asking what you want to do
|
||||
with the file. Click **Save**:
|
||||
|
||||

|
||||
|
||||
Then click **Open folder** and drag and drop the file from your Downloads to
|
||||
your `MICROBIT` drive.
|
||||
|
||||

|
||||
|
||||
## Step 3: Transfer the file to your micro:bit
|
||||
|
||||
* Once you've found the folder containing your `.hex` file, drag and drop it
|
||||
onto your `MICROBIT` drive
|
||||
* If you're using Windows, you can use **Send to** as described below
|
||||
* The LED on the back of your micro:bit flashes during the transfer (which
|
||||
should only take a few seconds).
|
||||
* Once transferred, the code will run automatically on your micro:bit. To rerun
|
||||
your program, press the reset button on the back of your micro:bit. The reset
|
||||
button automatically runs the newest file on the micro:bit.
|
||||
|
||||
**Send to**: If you're using Windows you use *Send to* in File Explorer:
|
||||
|
||||
In File Explorer, right-click on the hex file (created in Step 2 above), choose **Send to**, and then **MICROBIT**.
|
||||
|
||||

|
||||
|
||||
By copying the script onto the `MICROBIT` drive, you have programmed it into the
|
||||
flash memory on the micro:bit, which means even after you unplug the micro:bit,
|
||||
your program will still run if the micro:bit is powered by battery.
|
||||
|
||||
|
||||
### ~hint
|
||||
|
||||
Transfer not working? See some [troubleshooting tips](/device/usb/troubleshooting).
|
||||
|
||||
### ~
|
BIN
docs/static/configurations/chrome-version.png
vendored
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
docs/static/configurations/edge-version.png
vendored
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
docs/static/configurations/firefox-version.png
vendored
Normal file
After Width: | Height: | Size: 47 KiB |
BIN
docs/static/configurations/ie-version.png
vendored
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
docs/static/configurations/osx-version.png
vendored
Normal file
After Width: | Height: | Size: 128 KiB |
BIN
docs/static/configurations/safari-version.png
vendored
Normal file
After Width: | Height: | Size: 44 KiB |
BIN
docs/static/configurations/windows-version.png
vendored
Normal file
After Width: | Height: | Size: 82 KiB |
BIN
docs/static/mb/device/pano.jpg
vendored
Normal file
After Width: | Height: | Size: 90 KiB |
BIN
docs/static/mb/device/usb-generic.jpg
vendored
Normal file
After Width: | Height: | Size: 66 KiB |
BIN
docs/static/mb/device/usb-mac.jpg
vendored
Normal file
After Width: | Height: | Size: 65 KiB |
BIN
docs/static/mb/device/usb-osx-chrome.png
vendored
Before Width: | Height: | Size: 186 KiB After Width: | Height: | Size: 30 KiB |
BIN
docs/static/mb/device/usb-osx-firefox-1.jpg
vendored
Normal file
After Width: | Height: | Size: 40 KiB |
BIN
docs/static/mb/device/usb-osx-firefox-1.png
vendored
Before Width: | Height: | Size: 102 KiB |
BIN
docs/static/mb/device/usb-thin.jpg
vendored
Normal file
After Width: | Height: | Size: 41 KiB |
BIN
docs/static/mb/device/usb-windows-chrome.png
vendored
Before Width: | Height: | Size: 162 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 164 KiB After Width: | Height: | Size: 54 KiB |
BIN
docs/static/mb/device/usb-windows-edge-1.png
vendored
Before Width: | Height: | Size: 156 KiB After Width: | Height: | Size: 24 KiB |
BIN
docs/static/mb/device/usb-windows-edge-2.png
vendored
Before Width: | Height: | Size: 135 KiB After Width: | Height: | Size: 18 KiB |
BIN
docs/static/mb/device/usb-windows-firefox-1.png
vendored
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 6.9 KiB |
BIN
docs/static/mb/device/usb-windows-firefox-2.jpg
vendored
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
docs/static/mb/device/usb-windows-firefox-2.png
vendored
Before Width: | Height: | Size: 120 KiB |
BIN
docs/static/mb/device/usb-windows-ie11-1.png
vendored
Before Width: | Height: | Size: 164 KiB After Width: | Height: | Size: 10 KiB |
BIN
docs/static/mb/device/usb-windows-ie11-2.png
vendored
Before Width: | Height: | Size: 159 KiB After Width: | Height: | Size: 10 KiB |
BIN
docs/static/mb/device/usb-windows-sendto.jpg
vendored
Before Width: | Height: | Size: 160 KiB After Width: | Height: | Size: 50 KiB |
@ -1,28 +0,0 @@
|
||||
<meta name="twitter:card" content="summary" />
|
||||
<meta name="twitter:site" content="@codethemicrobit" />
|
||||
<meta name="twitter:title" content="@name@" />
|
||||
<meta name="twitter:description" content="@description@" />
|
||||
<meta name="twitter:image" content="@cardLogo@" />
|
||||
|
||||
<meta property="og:title" content="@name@" />
|
||||
<meta property="og:site_name" content="code the micro:bit" />
|
||||
<meta property="og:description" content="@description@" />
|
||||
<meta property="og:image" content="@cardLogo@" />
|
||||
<!--
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="fb:app_id" content="" />
|
||||
-->
|
||||
|
||||
<link rel="apple-touch-icon" href="@appLogo@">
|
||||
<link rel="icon" type="image/png" href="@appLogo@">
|
||||
<link rel="mask-icon" href="https://az851932.vo.msecnd.net/pub/zwxazere/safari-pinned-tab.svg" color="#000000">
|
||||
<link rel="shortcut icon" href="@appLogo@">
|
||||
<meta name="theme-color" content="@accentColor@">
|
||||
|
||||
<style>
|
||||
#root .avatar .avatar-image {
|
||||
background-image: url(https://az851932.vo.msecnd.net/pub/jovrytni/microbit.simplified.svg);
|
||||
background-size: contain;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
</style>
|
@ -141,7 +141,6 @@ namespace radio {
|
||||
*/
|
||||
//% help=radio/received-number-at
|
||||
//% weight=45 debug=true
|
||||
//% blockId=radio_datagram_received_number_at block="radio receive number|at %VALUE" blockGap=8
|
||||
int receivedNumberAt(int index) {
|
||||
if (radioEnable() != MICROBIT_OK) return 0;
|
||||
if (0 <= index && index < packet.length() / 4) {
|
||||
|
3
libs/microbit-radio/shims.d.ts
vendored
@ -46,8 +46,7 @@ declare namespace radio {
|
||||
* @param index index of the number to read from 0 to 3. 1 eg
|
||||
*/
|
||||
//% help=radio/received-number-at
|
||||
//% weight=45 debug=true
|
||||
//% blockId=radio_datagram_received_number_at block="radio receive number|at %VALUE" blockGap=8 shim=radio::receivedNumberAt
|
||||
//% weight=45 debug=true shim=radio::receivedNumberAt
|
||||
function receivedNumberAt(index: number): number;
|
||||
|
||||
/**
|
||||
|
@ -8,6 +8,7 @@ namespace control {
|
||||
* Returns the value of a C++ runtime constant
|
||||
*/
|
||||
//% weight=2 weight=19 blockId="control_event_source_id" block="%id" blockGap=8
|
||||
//% shim=TD_ID
|
||||
export function eventSourceId(id: EventBusSource): number {
|
||||
return id;
|
||||
}
|
||||
@ -15,6 +16,7 @@ namespace control {
|
||||
* Returns the value of a C++ runtime constant
|
||||
*/
|
||||
//% weight=1 weight=19 blockId="control_event_value_id" block="%id"
|
||||
//% shim=TD_ID
|
||||
export function eventValueId(id: EventBusValue): number {
|
||||
return id;
|
||||
}
|
||||
@ -42,6 +44,5 @@ namespace control {
|
||||
* Display warning in the simulator.
|
||||
*/
|
||||
//% shim=pxtrt::runtimeWarning
|
||||
export function runtimeWarning(message: string) {
|
||||
}
|
||||
export function runtimeWarning(message: string) { }
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ namespace music {
|
||||
*/
|
||||
//% help=music/play-tone weight=90
|
||||
//% blockId=device_play_note block="play|tone %note=device_note|for %duration=device_beat" icon="\uf025" blockGap=8
|
||||
//% parts="speaker"
|
||||
//% parts="headphone"
|
||||
export function playTone(frequency: number, ms: number): void {
|
||||
pins.analogSetPitchPin(AnalogPin.P0);
|
||||
pins.analogPitch(frequency, ms);
|
||||
@ -147,7 +147,7 @@ namespace music {
|
||||
*/
|
||||
//% help=music/ring-tone weight=80
|
||||
//% blockId=device_ring block="ring tone (Hz)|%note=device_note" icon="\uf025" blockGap=8
|
||||
//% parts="speaker"
|
||||
//% parts="headphone"
|
||||
export function ringTone(frequency: number): void {
|
||||
pins.analogSetPitchPin(AnalogPin.P0);
|
||||
pins.analogPitch(frequency, 0);
|
||||
@ -159,7 +159,7 @@ namespace music {
|
||||
*/
|
||||
//% help=music/rest weight=79
|
||||
//% blockId=device_rest block="rest(ms)|%duration=device_beat"
|
||||
//% parts="speaker"
|
||||
//% parts="headphone"
|
||||
export function rest(ms: number): void {
|
||||
playTone(0, ms);
|
||||
}
|
||||
@ -171,7 +171,6 @@ namespace music {
|
||||
*/
|
||||
//% weight=50 help=music/note-frequency
|
||||
//% blockId=device_note block="%note"
|
||||
//% parts="speaker"
|
||||
//% shim=TD_ID
|
||||
export function noteFrequency(name: Note): number {
|
||||
return name;
|
||||
@ -186,7 +185,6 @@ namespace music {
|
||||
*/
|
||||
//% help=music/beat weight=49
|
||||
//% blockId=device_beat block="%fraction|beat"
|
||||
//% parts="speaker"
|
||||
export function beat(fraction?: BeatFraction): number {
|
||||
init();
|
||||
if (fraction == null) fraction = BeatFraction.Whole;
|
||||
@ -203,7 +201,6 @@ namespace music {
|
||||
*/
|
||||
//% help=music/tempo weight=40
|
||||
//% blockId=device_tempo block="tempo (bpm)" blockGap=8
|
||||
//% parts="speaker"
|
||||
export function tempo(): number {
|
||||
init();
|
||||
return beatsPerMinute;
|
||||
@ -215,7 +212,6 @@ namespace music {
|
||||
*/
|
||||
//% help=music/change-tempo weight=39
|
||||
//% blockId=device_change_tempo block="change tempo by (bpm)|%value" blockGap=8
|
||||
//% parts="speaker"
|
||||
export function changeTempoBy(bpm: number): void {
|
||||
init();
|
||||
setTempo(beatsPerMinute + bpm);
|
||||
@ -227,7 +223,6 @@ namespace music {
|
||||
*/
|
||||
//% help=music/set-tempo weight=38
|
||||
//% blockId=device_set_tempo block="set tempo to (bpm)|%value"
|
||||
//% parts="speaker"
|
||||
export function setTempo(bpm: number): void {
|
||||
init();
|
||||
if (bpm > 0) {
|
||||
|
1
libs/microbit/parts/headphone.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="142" height="180" viewBox="0 0 142 180"><rect ry=".3" rx="1" y="58.615" x="-8.878" height="23.571" width="17.143" transform="rotate(-45)" fill="#b3b3b3"/><rect ry=".3" rx="1" y="32.043" x="-8.878" height="23.571" width="17.143" transform="rotate(-45)" fill="#b3b3b3"/><path d="M.346 7.296c-.394.39-.31 4.797-.18 4.898l13.404 10.18c.117.12.337 4.76.73 4.368l5.506-5.56.01.01 6.51-6.444c.39-.392-4.25-.614-4.366-.73L11.777.612c-.1-.132-4.51-.215-4.898.18L4.087 3.636l-.01-.01-3.73 3.67z" fill="#b3b3b3"/><rect ry="6.85" rx="4.571" y="84.758" x="-20.128" height="75.571" width="39.643" transform="rotate(-45)"/><rect ry=".374" rx="1.038" y="29.442" x="-8.925" height="2.228" width="17.238" transform="rotate(-45)" fill="#fff"/><rect ry=".374" rx="1.038" y="55.939" x="-8.925" height="2.228" width="17.238" transform="rotate(-45)" fill="#fff"/><rect ry=".374" rx="1.038" y="82.392" x="-8.925" height="2.228" width="17.238" transform="rotate(-45)" fill="#fff"/><rect ry="2.317" rx="2.183" y="158.876" x="-9.774" height="25.568" width="18.935" transform="rotate(-45)"/><path d="M128.588 128.82s14.97 11.165 7.547 26.35c-8.426 17.24-25.57 20.653-25.57 20.653" fill="none" stroke="#000" stroke-width="6.6" stroke-linecap="round" stroke-linejoin="round"/></svg>
|
After Width: | Height: | Size: 1.3 KiB |
@ -29,6 +29,7 @@
|
||||
"buffer.cpp",
|
||||
"pxtparts.json",
|
||||
"parts/speaker.svg",
|
||||
"parts/headphone.svg",
|
||||
"_locales/fr/microbit-jsdoc-strings.json"
|
||||
],
|
||||
"public": true,
|
||||
|
@ -101,10 +101,32 @@
|
||||
{"pinIndices": [5, 6, 7, 8, 9]}
|
||||
]
|
||||
},
|
||||
"headphone": {
|
||||
"numberOfPins": 2,
|
||||
"visual": {
|
||||
"image": "parts/headphone.svg",
|
||||
"width": 142,
|
||||
"height": 180,
|
||||
"pinDistance": 20,
|
||||
"pinLocations": [
|
||||
{"x": 17, "y": 11},
|
||||
{"x": 55, "y": 50}
|
||||
]
|
||||
},
|
||||
"pinDefinitions": [
|
||||
{"target": "P0", "style": "croc", "orientation": "Y"},
|
||||
{"target": "ground", "style": "croc", "orientation": "Y"}
|
||||
],
|
||||
"instantiation": {"kind": "singleton"},
|
||||
"assembly": [
|
||||
{"part": true, "pinIndices": [0]},
|
||||
{"pinIndices": [1]}
|
||||
]
|
||||
},
|
||||
"speaker": {
|
||||
"numberOfPins": 2,
|
||||
"visual": {
|
||||
"image": "/parts/speaker.svg",
|
||||
"image": "parts/speaker.svg",
|
||||
"width": 500,
|
||||
"height": 500,
|
||||
"pinDistance": 70,
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-microbit",
|
||||
"version": "0.3.86",
|
||||
"version": "0.4.13",
|
||||
"description": "micro:bit target for PXT",
|
||||
"keywords": [
|
||||
"JavaScript",
|
||||
@ -29,6 +29,6 @@
|
||||
"typescript": "^1.8.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"pxt-core": "0.3.98"
|
||||
"pxt-core": "0.4.17"
|
||||
}
|
||||
}
|
||||
|
181
pxtarget.json
@ -87,6 +87,95 @@
|
||||
"bluetooth": true,
|
||||
"thermometer": true,
|
||||
"compass": true
|
||||
},
|
||||
"boardDefinition": {
|
||||
"visual": "microbit",
|
||||
"gpioPinBlocks": [
|
||||
[
|
||||
"P0"
|
||||
],
|
||||
[
|
||||
"P1"
|
||||
],
|
||||
[
|
||||
"P2"
|
||||
],
|
||||
[
|
||||
"P3"
|
||||
],
|
||||
[
|
||||
"P4",
|
||||
"P5",
|
||||
"P6",
|
||||
"P7"
|
||||
],
|
||||
[
|
||||
"P8",
|
||||
"P9",
|
||||
"P10",
|
||||
"P11",
|
||||
"P12"
|
||||
],
|
||||
[
|
||||
"P16"
|
||||
]
|
||||
],
|
||||
"gpioPinMap": {
|
||||
"P0": "P0",
|
||||
"P1": "P1",
|
||||
"P2": "P2",
|
||||
"P3": "P3",
|
||||
"P4": "P4",
|
||||
"P5": "P5",
|
||||
"P6": "P6",
|
||||
"P7": "P7",
|
||||
"P8": "P8",
|
||||
"P9": "P9",
|
||||
"P10": "P10",
|
||||
"P11": "P11",
|
||||
"P12": "P12",
|
||||
"P13": "P13",
|
||||
"P14": "P14",
|
||||
"P15": "P15",
|
||||
"P16": "P16",
|
||||
"P19": "P19",
|
||||
"P20": "P20"
|
||||
},
|
||||
"spiPins": {
|
||||
"MOSI": "P15",
|
||||
"MISO": "P14",
|
||||
"SCK": "P13"
|
||||
},
|
||||
"i2cPins": {
|
||||
"SDA": "P20",
|
||||
"SCL": "P19"
|
||||
},
|
||||
"analogInPins": [
|
||||
"P0",
|
||||
"P1",
|
||||
"P2",
|
||||
"P3",
|
||||
"P10"
|
||||
],
|
||||
"groundPins": [
|
||||
"GND"
|
||||
],
|
||||
"threeVoltPins": [
|
||||
"+3v3"
|
||||
],
|
||||
"attachPowerOnRight": true,
|
||||
"onboardComponents": [
|
||||
"buttonpair",
|
||||
"ledmatrix",
|
||||
"speaker"
|
||||
],
|
||||
"useCrocClips": true,
|
||||
"marginWhenBreadboarding": [
|
||||
0,
|
||||
0,
|
||||
80,
|
||||
0
|
||||
]
|
||||
}
|
||||
},
|
||||
"compileService": {
|
||||
@ -116,6 +205,33 @@
|
||||
"privacyUrl": "https://go.microsoft.com/fwlink/?LinkId=521839",
|
||||
"termsOfUseUrl": "https://go.microsoft.com/fwlink/?LinkID=206977",
|
||||
"githubUrl": "https://github.com/Microsoft/pxt-microbit",
|
||||
"browserSupport": [
|
||||
{
|
||||
"name": "unsupported",
|
||||
"os": "*",
|
||||
"path": "/browsers"
|
||||
},
|
||||
{
|
||||
"name": "unsupported",
|
||||
"os": "mac",
|
||||
"path": "/browsers/mac"
|
||||
},
|
||||
{
|
||||
"name": "unsupported",
|
||||
"os": "linux",
|
||||
"path": "browsers/linux"
|
||||
},
|
||||
{
|
||||
"name": "unsupported",
|
||||
"os": "rpi",
|
||||
"path": "/raspberry-pi"
|
||||
},
|
||||
{
|
||||
"name": "unsupported",
|
||||
"os": "windows",
|
||||
"path": "/browsers/windows"
|
||||
}
|
||||
],
|
||||
"boardName": "BBC micro:bit",
|
||||
"docMenu": [
|
||||
{
|
||||
@ -143,7 +259,70 @@
|
||||
"path": "/device"
|
||||
}
|
||||
],
|
||||
"sideDoc": "getting-started"
|
||||
"sideDoc": "getting-started",
|
||||
"usbDocs": "/device/usb",
|
||||
"usbHelp": [
|
||||
{
|
||||
"name": "connection",
|
||||
"os": "*",
|
||||
"browser": "*",
|
||||
"path": "/static/mb/device/usb-generic.jpg"
|
||||
},
|
||||
{
|
||||
"name": "connection",
|
||||
"os": "mac",
|
||||
"browser": "*",
|
||||
"path": "/static/mb/device/usb-mac.jpg"
|
||||
},
|
||||
{
|
||||
"name": "save",
|
||||
"os": "windows",
|
||||
"browser": "firefox",
|
||||
"path": "/static/mb/device/usb-windows-firefox-1.png"
|
||||
},
|
||||
{
|
||||
"name": "save",
|
||||
"os": "mac",
|
||||
"browser": "firefox",
|
||||
"path": "/static/mb/device/usb-osx-firefox-1.jpg"
|
||||
},
|
||||
{
|
||||
"name": "save",
|
||||
"os": "mac",
|
||||
"browser": "chrome",
|
||||
"path": "/static/mb/device/usb-osx-chrome.png"
|
||||
},
|
||||
{
|
||||
"name": "save",
|
||||
"os": "windows",
|
||||
"browser": "edge",
|
||||
"path": "/static/mb/device/usb-windows-edge-1.png"
|
||||
},
|
||||
{
|
||||
"name": "save",
|
||||
"os": "windows",
|
||||
"browser": "ie",
|
||||
"path": "/static/mb/device/usb-windows-ie11-1.png"
|
||||
},
|
||||
{
|
||||
"name": "save",
|
||||
"os": "windows",
|
||||
"browser": "chrome",
|
||||
"path": "/static/mb/device/usb-windows-chrome.png"
|
||||
},
|
||||
{
|
||||
"name": "copy",
|
||||
"os": "mac",
|
||||
"browser": "*",
|
||||
"path": "/static/mb/device/usb-osx-dnd.png"
|
||||
},
|
||||
{
|
||||
"name": "copy",
|
||||
"os": "windows",
|
||||
"browser": "*",
|
||||
"path": "/static/mb/device/usb-windows-sendto.jpg"
|
||||
}
|
||||
]
|
||||
},
|
||||
"analytics": {
|
||||
"userVoiceApiKey": "WEkkIGaj1WtJnSUF59iwaA",
|
||||
|
672
sim/allocator.ts
@ -1,672 +0,0 @@
|
||||
namespace pxsim {
|
||||
const GROUND_COLOR = "blue";
|
||||
const POWER_COLOR = "red";
|
||||
|
||||
export interface AllocatorOpts {
|
||||
boardDef: BoardDefinition,
|
||||
partDefs: Map<PartDefinition>,
|
||||
partsList: string[]
|
||||
fnArgs: any,
|
||||
// Used for finding the nearest available power pins
|
||||
getBBCoord: (loc: BBLoc) => visuals.Coord,
|
||||
};
|
||||
export interface AllocatorResult {
|
||||
partsAndWires: PartAndWiresInst[],
|
||||
}
|
||||
export interface PartInst {
|
||||
name: string,
|
||||
simulationBehavior?: string,
|
||||
visual: PartVisualDefinition,
|
||||
bbFit: PartBBFit,
|
||||
startColumnIdx: number,
|
||||
startRowIdx: number,
|
||||
breadboardConnections: BBLoc[],
|
||||
params: Map<string>,
|
||||
}
|
||||
export interface WireInst {
|
||||
start: Loc,
|
||||
end: Loc,
|
||||
color: string,
|
||||
};
|
||||
export interface AssemblyStep {
|
||||
part?: boolean,
|
||||
wireIndices?: number[],
|
||||
}
|
||||
export interface PartAndWiresInst {
|
||||
part?: PartInst,
|
||||
wires?: WireInst[],
|
||||
assembly: AssemblyStep[],
|
||||
}
|
||||
export interface PartBBFit {
|
||||
xOffset: number,
|
||||
yOffset: number,
|
||||
rowCount: number,
|
||||
colCount: number,
|
||||
}
|
||||
interface PinBBFit {
|
||||
partRelativeColIdx: number,
|
||||
partRelativeRowIdx: number,
|
||||
xOffset: number,
|
||||
yOffset: number,
|
||||
}
|
||||
interface PinIR {
|
||||
loc: XY,
|
||||
def: PartPinDefinition,
|
||||
target: PinTarget,
|
||||
bbFit: PinBBFit,
|
||||
}
|
||||
interface PartIR {
|
||||
name: string,
|
||||
def: PartDefinition,
|
||||
partParams: Map<string>,
|
||||
pins: PinIR[],
|
||||
bbFit: PartBBFit,
|
||||
};
|
||||
interface PartPlacement extends PartIR {
|
||||
startColumnIdx: number,
|
||||
startRowIdx: number,
|
||||
};
|
||||
type WireIRLoc = PinTarget | BBLoc;
|
||||
interface WireIR {
|
||||
pinIdx: number,
|
||||
start: WireIRLoc,
|
||||
end: WireIRLoc,
|
||||
color: string,
|
||||
}
|
||||
interface PartIRAndWireIRs extends PartPlacement {
|
||||
wires: WireIR[],
|
||||
};
|
||||
interface PowerUsage {
|
||||
topGround: boolean,
|
||||
topThreeVolt: boolean,
|
||||
bottomGround: boolean,
|
||||
bottomThreeVolt: boolean,
|
||||
singleGround: boolean,
|
||||
singleThreeVolt: boolean,
|
||||
}
|
||||
interface AllocLocOpts {
|
||||
referenceBBPin?: BBLoc,
|
||||
};
|
||||
interface AllocWireOpts {
|
||||
//TODO: port
|
||||
startColumn: number,
|
||||
partGPIOPins: string[],
|
||||
}
|
||||
function isOnBreadboardBottom(location: WireIRLoc) {
|
||||
let isBot = false;
|
||||
if (typeof location !== "string" && (<BBLoc>location).type === "breadboard") {
|
||||
let bbLoc = <BBLoc>location;
|
||||
let row = bbLoc.row;
|
||||
isBot = 0 <= ["a", "b", "c", "d", "e"].indexOf(row);
|
||||
}
|
||||
return isBot;
|
||||
}
|
||||
const arrCount = (a: boolean[]) => a.reduce((p, n) => p + (n ? 1 : 0), 0);
|
||||
const arrAny = (a: boolean[]) => arrCount(a) > 0;
|
||||
function computePowerUsage(wire: WireIR): PowerUsage {
|
||||
let ends = [wire.start, wire.end];
|
||||
let endIsGround = ends.map(e => e === "ground");
|
||||
let endIsThreeVolt = ends.map(e => e === "threeVolt");
|
||||
let endIsBot = ends.map(e => isOnBreadboardBottom(e));
|
||||
let hasGround = arrAny(endIsGround);
|
||||
let hasThreeVolt = arrAny(endIsThreeVolt);
|
||||
let hasBot = arrAny(endIsBot);
|
||||
return {
|
||||
topGround: hasGround && !hasBot,
|
||||
topThreeVolt: hasThreeVolt && !hasBot,
|
||||
bottomGround: hasGround && hasBot,
|
||||
bottomThreeVolt: hasThreeVolt && hasBot,
|
||||
singleGround: hasGround,
|
||||
singleThreeVolt: hasThreeVolt
|
||||
};
|
||||
}
|
||||
function mergePowerUsage(powerUsages: PowerUsage[]) {
|
||||
let finalPowerUsage = powerUsages.reduce((p, n) => ({
|
||||
topGround: p.topGround || n.topGround,
|
||||
topThreeVolt: p.topThreeVolt || n.topThreeVolt,
|
||||
bottomGround: p.bottomGround || n.bottomGround,
|
||||
bottomThreeVolt: p.bottomThreeVolt || n.bottomThreeVolt,
|
||||
singleGround: n.singleGround ? p.singleGround === null : p.singleGround,
|
||||
singleThreeVolt: n.singleThreeVolt ? p.singleThreeVolt === null : p.singleThreeVolt,
|
||||
}), {
|
||||
topGround: false,
|
||||
topThreeVolt: false,
|
||||
bottomGround: false,
|
||||
bottomThreeVolt: false,
|
||||
singleGround: null,
|
||||
singleThreeVolt: null,
|
||||
});
|
||||
if (finalPowerUsage.singleGround)
|
||||
finalPowerUsage.topGround = finalPowerUsage.bottomGround = false;
|
||||
if (finalPowerUsage.singleThreeVolt)
|
||||
finalPowerUsage.topThreeVolt = finalPowerUsage.bottomThreeVolt = false;
|
||||
return finalPowerUsage;
|
||||
}
|
||||
function copyDoubleArray(a: string[][]) {
|
||||
return a.map(b => b.map(p => p));
|
||||
}
|
||||
function merge2<A, B>(a: A, b: B): A & B {
|
||||
let res: any = {};
|
||||
for (let aKey in a)
|
||||
res[aKey] = (<any>a)[aKey];
|
||||
for (let bKey in b)
|
||||
res[bKey] = (<any>b)[bKey];
|
||||
return <A & B>res;
|
||||
}
|
||||
function merge3<A, B, C>(a: A, b: B, c: C): A & B & C {
|
||||
return merge2(merge2(a, b), c);
|
||||
}
|
||||
function readPin(arg: string): MicrobitPin {
|
||||
U.assert(!!arg, "Invalid pin: " + arg);
|
||||
let pin = arg.split("DigitalPin.")[1];
|
||||
return <MicrobitPin>pin;
|
||||
}
|
||||
function mkReverseMap(map: {[key: string]: string}) {
|
||||
let origKeys: string[] = [];
|
||||
let origVals: string[] = [];
|
||||
for (let key in map) {
|
||||
origKeys.push(key);
|
||||
origVals.push(map[key]);
|
||||
}
|
||||
let newMap: {[key: string]: string} = {};
|
||||
for (let i = 0; i < origKeys.length; i++) {
|
||||
let newKey = origVals[i];
|
||||
let newVal = origKeys[i];
|
||||
newMap[newKey] = newVal;
|
||||
}
|
||||
return newMap;
|
||||
}
|
||||
function isConnectedToBB(pin: PartPinDefinition): boolean {
|
||||
return pin.orientation === "-Z" && pin.style === "male";
|
||||
}
|
||||
class Allocator {
|
||||
//TODO: better handling of allocation errors
|
||||
private opts: AllocatorOpts;
|
||||
private availablePowerPins = {
|
||||
top: {
|
||||
threeVolt: mkRange(26, 51).map(n => <BBLoc>{type: "breadboard", row: "+", col: `${n}`}),
|
||||
ground: mkRange(26, 51).map(n => <BBLoc>{type: "breadboard", row: "-", col: `${n}`}),
|
||||
},
|
||||
bottom: {
|
||||
threeVolt: mkRange(1, 26).map(n => <BBLoc>{type: "breadboard", row: "+", col: `${n}`}),
|
||||
ground: mkRange(1, 26).map(n => <BBLoc>{type: "breadboard", row: "-", col: `${n}`}),
|
||||
},
|
||||
};
|
||||
private powerUsage: PowerUsage;
|
||||
private availableWireColors: string[];
|
||||
|
||||
constructor(opts: AllocatorOpts) {
|
||||
this.opts = opts;
|
||||
}
|
||||
|
||||
private allocPartIRs(def: PartDefinition, name: string, bbFit: PartBBFit): PartIR[] {
|
||||
let partIRs: PartIR[] = [];
|
||||
let mkIR = (def: PartDefinition, name: string, instPins?: PinTarget[], partParams?: Map<string>): PartIR => {
|
||||
let pinIRs: PinIR[] = [];
|
||||
for (let i = 0; i < def.numberOfPins; i++) {
|
||||
let pinDef = def.pinDefinitions[i];
|
||||
let pinTarget: PinTarget;
|
||||
if (typeof pinDef.target === "string") {
|
||||
pinTarget = <PinTarget>pinDef.target;
|
||||
} else {
|
||||
let instIdx = (<PinInstantiationIdx>pinDef.target).pinInstantiationIdx;
|
||||
U.assert(!!instPins && instPins[instIdx] !== undefined,
|
||||
`No pin found for PinInstantiationIdx: ${instIdx}. (Is the part missing an ArguementRole or "trackArgs=" annotations?)`);
|
||||
pinTarget = instPins[instIdx];
|
||||
}
|
||||
let pinLoc = def.visual.pinLocations[i];
|
||||
let adjustedY = bbFit.yOffset + pinLoc.y;
|
||||
let relativeRowIdx = Math.round(adjustedY / def.visual.pinDistance);
|
||||
let relativeYOffset = adjustedY - relativeRowIdx * def.visual.pinDistance;
|
||||
let adjustedX = bbFit.xOffset + pinLoc.x;
|
||||
let relativeColIdx = Math.round(adjustedX / def.visual.pinDistance);
|
||||
let relativeXOffset = adjustedX - relativeColIdx * def.visual.pinDistance;
|
||||
let pinBBFit: PinBBFit = {
|
||||
partRelativeRowIdx: relativeRowIdx,
|
||||
partRelativeColIdx: relativeColIdx,
|
||||
xOffset: relativeXOffset,
|
||||
yOffset: relativeYOffset
|
||||
};
|
||||
pinIRs.push({
|
||||
def: pinDef,
|
||||
loc: pinLoc,
|
||||
target: pinTarget,
|
||||
bbFit: pinBBFit,
|
||||
});
|
||||
}
|
||||
return {
|
||||
name: name,
|
||||
def: def,
|
||||
pins: pinIRs,
|
||||
partParams: partParams || {},
|
||||
bbFit: bbFit
|
||||
};
|
||||
};
|
||||
if (def.instantiation.kind === "singleton") {
|
||||
partIRs.push(mkIR(def, name));
|
||||
} else if (def.instantiation.kind === "function") {
|
||||
let fnAlloc = def.instantiation as PartFunctionDefinition;
|
||||
let fnNm = fnAlloc.fullyQualifiedName;
|
||||
let callsitesTrackedArgs = <string[]>this.opts.fnArgs[fnNm];
|
||||
U.assert(!!callsitesTrackedArgs && !!callsitesTrackedArgs.length, "Failed to read pin(s) from callsite for: " + fnNm);
|
||||
callsitesTrackedArgs.forEach(fnArgsStr => {
|
||||
let fnArgsSplit = fnArgsStr.split(",");
|
||||
U.assert(fnArgsSplit.length === fnAlloc.argumentRoles.length,
|
||||
`Mismatch between number of arguments at callsite (function name: ${fnNm}) vs number of argument roles in part definition (part: ${name}).`);
|
||||
let instPins: PinTarget[] = [];
|
||||
let paramArgs: Map<string> = {};
|
||||
fnArgsSplit.forEach((arg, idx) => {
|
||||
let role = fnAlloc.argumentRoles[idx];
|
||||
if (role.partParameter !== undefined) {
|
||||
paramArgs[role.partParameter] = arg;
|
||||
}
|
||||
if (role.pinInstantiationIdx !== undefined) {
|
||||
let instIdx = role.pinInstantiationIdx;
|
||||
let pin = readPin(arg);
|
||||
instPins[instIdx] = pin;
|
||||
}
|
||||
});
|
||||
partIRs.push(mkIR(def, name, instPins, paramArgs));
|
||||
});
|
||||
}
|
||||
return partIRs;
|
||||
}
|
||||
private computePartDimensions(def: PartDefinition, name: string): PartBBFit {
|
||||
let pinLocs = def.visual.pinLocations;
|
||||
let pinDefs = def.pinDefinitions;
|
||||
let numPins = def.numberOfPins;
|
||||
U.assert(pinLocs.length === numPins, `Mismatch between "numberOfPins" and length of "visual.pinLocations" for "${name}"`);
|
||||
U.assert(pinDefs.length === numPins, `Mismatch between "numberOfPins" and length of "pinDefinitions" for "${name}"`);
|
||||
U.assert(numPins > 0, `Part "${name}" has no pins`);
|
||||
let pins = pinLocs.map((loc, idx) => merge3({idx: idx}, loc, pinDefs[idx]));
|
||||
let bbPins = pins.filter(p => p.orientation === "-Z");
|
||||
let hasBBPins = bbPins.length > 0;
|
||||
let pinDist = def.visual.pinDistance;
|
||||
let xOff: number;
|
||||
let yOff: number;
|
||||
let colCount: number;
|
||||
let rowCount: number;
|
||||
if (hasBBPins) {
|
||||
let refPin = bbPins[0];
|
||||
let refPinColIdx = Math.ceil(refPin.x / pinDist);
|
||||
let refPinRowIdx = Math.ceil(refPin.y / pinDist);
|
||||
xOff = refPinColIdx * pinDist - refPin.x;
|
||||
yOff = refPinRowIdx * pinDist - refPin.y;
|
||||
colCount = Math.ceil((xOff + def.visual.width) / pinDist) + 1;
|
||||
rowCount = Math.ceil((yOff + def.visual.height) / pinDist) + 1;
|
||||
} else {
|
||||
colCount = Math.ceil(def.visual.width / pinDist);
|
||||
rowCount = Math.ceil(def.visual.height / pinDist);
|
||||
xOff = colCount * pinDist - def.visual.width;
|
||||
yOff = rowCount * pinDist - def.visual.height;
|
||||
}
|
||||
return {
|
||||
xOffset: xOff,
|
||||
yOffset: yOff,
|
||||
rowCount: rowCount,
|
||||
colCount: colCount
|
||||
};
|
||||
}
|
||||
private allocColumns(colCounts: {colCount: number}[]): number[] {
|
||||
let partsCount = colCounts.length;
|
||||
const totalColumnsCount = visuals.BREADBOARD_MID_COLS; //TODO allow multiple breadboards
|
||||
let totalSpaceNeeded = colCounts.map(d => d.colCount).reduce((p, n) => p + n, 0);
|
||||
let extraSpace = totalColumnsCount - totalSpaceNeeded;
|
||||
if (extraSpace <= 0) {
|
||||
console.log("Not enough breadboard space!");
|
||||
//TODO
|
||||
}
|
||||
let padding = Math.floor(extraSpace / (partsCount - 1 + 2));
|
||||
let partSpacing = padding; //Math.floor(extraSpace/(partsCount-1));
|
||||
let totalPartPadding = extraSpace - partSpacing * (partsCount - 1);
|
||||
let leftPadding = Math.floor(totalPartPadding / 2);
|
||||
let rightPadding = Math.ceil(totalPartPadding / 2);
|
||||
let nextAvailableCol = 1 + leftPadding;
|
||||
let partStartCol = colCounts.map(part => {
|
||||
let col = nextAvailableCol;
|
||||
nextAvailableCol += part.colCount + partSpacing;
|
||||
return col;
|
||||
});
|
||||
return partStartCol;
|
||||
}
|
||||
private placeParts(parts: PartIR[]): PartPlacement[] {
|
||||
const totalRowsCount = visuals.BREADBOARD_MID_ROWS + 2; // 10 letters + 2 for the middle gap
|
||||
let startColumnIndices = this.allocColumns(parts.map(p => p.bbFit));
|
||||
let startRowIndicies = parts.map(p => {
|
||||
let extraRows = totalRowsCount - p.bbFit.rowCount;
|
||||
let topPad = Math.floor(extraRows / 2);
|
||||
let startIdx = topPad;
|
||||
if (startIdx > 4)
|
||||
startIdx = 4;
|
||||
if (startIdx < 1)
|
||||
startIdx = 1;
|
||||
return startIdx;
|
||||
});
|
||||
let placements = parts.map((p, idx) => {
|
||||
let row = startRowIndicies[idx];
|
||||
let col = startColumnIndices[idx];
|
||||
return merge2({startColumnIdx: col, startRowIdx: row}, p);
|
||||
});
|
||||
return placements;
|
||||
}
|
||||
private nextColor(): string {
|
||||
if (!this.availableWireColors || this.availableWireColors.length <= 0) {
|
||||
this.availableWireColors = visuals.GPIO_WIRE_COLORS.map(c => c);
|
||||
}
|
||||
return this.availableWireColors.pop();
|
||||
}
|
||||
private allocWireIRs(part: PartPlacement): PartIRAndWireIRs {
|
||||
let groupToColor: string[] = [];
|
||||
let wires: WireIR[] = part.pins.map((pin, pinIdx) => {
|
||||
let end = pin.target;
|
||||
let start: WireIRLoc;
|
||||
let colIdx = part.startColumnIdx + pin.bbFit.partRelativeColIdx;
|
||||
let colName = visuals.getColumnName(colIdx);
|
||||
let pinRowIdx = part.startRowIdx + pin.bbFit.partRelativeRowIdx;
|
||||
if (pinRowIdx >= 7) //account for middle gap
|
||||
pinRowIdx -= 2;
|
||||
if (isConnectedToBB(pin.def)) {
|
||||
//make a wire from bb top or bottom to target
|
||||
let connectedToTop = pinRowIdx < 5;
|
||||
let rowName = connectedToTop ? "j" : "a";
|
||||
start = {
|
||||
type: "breadboard",
|
||||
row: rowName,
|
||||
col: colName,
|
||||
};
|
||||
} else {
|
||||
//make a wire directly from pin to target
|
||||
let rowName = visuals.getRowName(pinRowIdx);
|
||||
start = {
|
||||
type: "breadboard",
|
||||
row: rowName,
|
||||
col: colName,
|
||||
xOffset: pin.bbFit.xOffset / part.def.visual.pinDistance,
|
||||
yOffset: pin.bbFit.yOffset / part.def.visual.pinDistance
|
||||
}
|
||||
}
|
||||
let color: string;
|
||||
if (end === "ground") {
|
||||
color = GROUND_COLOR;
|
||||
} else if (end === "threeVolt") {
|
||||
color = POWER_COLOR;
|
||||
} else if (typeof pin.def.colorGroup === "number") {
|
||||
if (groupToColor[pin.def.colorGroup]) {
|
||||
color = groupToColor[pin.def.colorGroup];
|
||||
} else {
|
||||
color = groupToColor[pin.def.colorGroup] = this.nextColor();
|
||||
}
|
||||
} else {
|
||||
color = this.nextColor()
|
||||
}
|
||||
return {
|
||||
start: start,
|
||||
end: end,
|
||||
color: color,
|
||||
pinIdx: pinIdx,
|
||||
}
|
||||
});
|
||||
return merge2(part, {wires: wires});
|
||||
}
|
||||
private allocLocation(location: WireIRLoc, opts: AllocLocOpts): Loc {
|
||||
if (location === "ground" || location === "threeVolt") {
|
||||
//special case if there is only a single ground or three volt pin in the whole build
|
||||
if (location === "ground" && this.powerUsage.singleGround) {
|
||||
let boardGroundPin = this.getBoardGroundPin();
|
||||
return {type: "dalboard", pin: boardGroundPin};
|
||||
} else if (location === "threeVolt" && this.powerUsage.singleThreeVolt) {
|
||||
let boardThreeVoltPin = this.getBoardThreeVoltPin();
|
||||
return {type: "dalboard", pin: boardThreeVoltPin};
|
||||
}
|
||||
|
||||
U.assert(!!opts.referenceBBPin);
|
||||
let nearestCoord = this.opts.getBBCoord(opts.referenceBBPin);
|
||||
let firstTopAndBot = [
|
||||
this.availablePowerPins.top.ground[0] || this.availablePowerPins.top.threeVolt[0],
|
||||
this.availablePowerPins.bottom.ground[0] || this.availablePowerPins.bottom.threeVolt[0]
|
||||
].map(loc => {
|
||||
return this.opts.getBBCoord(loc);
|
||||
});
|
||||
if (!firstTopAndBot[0] || !firstTopAndBot[1]) {
|
||||
console.debug(`No more available "${location}" locations!`);
|
||||
//TODO
|
||||
}
|
||||
let nearTop = visuals.findClosestCoordIdx(nearestCoord, firstTopAndBot) == 0;
|
||||
let barPins: BBLoc[];
|
||||
if (nearTop) {
|
||||
if (location === "ground") {
|
||||
barPins = this.availablePowerPins.top.ground;
|
||||
} else if (location === "threeVolt") {
|
||||
barPins = this.availablePowerPins.top.threeVolt;
|
||||
}
|
||||
} else {
|
||||
if (location === "ground") {
|
||||
barPins = this.availablePowerPins.bottom.ground;
|
||||
} else if (location === "threeVolt") {
|
||||
barPins = this.availablePowerPins.bottom.threeVolt;
|
||||
}
|
||||
}
|
||||
let pinCoords = barPins.map(rowCol => {
|
||||
return this.opts.getBBCoord(rowCol);
|
||||
});
|
||||
let closestPinIdx = visuals.findClosestCoordIdx(nearestCoord, pinCoords);
|
||||
let pin = barPins[closestPinIdx];
|
||||
if (nearTop) {
|
||||
this.availablePowerPins.top.ground.splice(closestPinIdx, 1);
|
||||
this.availablePowerPins.top.threeVolt.splice(closestPinIdx, 1);
|
||||
} else {
|
||||
this.availablePowerPins.bottom.ground.splice(closestPinIdx, 1);
|
||||
this.availablePowerPins.bottom.threeVolt.splice(closestPinIdx, 1);
|
||||
}
|
||||
return pin;
|
||||
} else if ((<BBLoc>location).type === "breadboard") {
|
||||
return <BBLoc>location;
|
||||
} else if (location === "MOSI" || location === "MISO" || location === "SCK") {
|
||||
if (!this.opts.boardDef.spiPins)
|
||||
console.debug("No SPI pin mappings found!");
|
||||
let pin = (<any>this.opts.boardDef.spiPins)[location as string] as string;
|
||||
return {type: "dalboard", pin: pin};
|
||||
} else if (location === "SDA" || location === "SCL") {
|
||||
if (!this.opts.boardDef.i2cPins)
|
||||
console.debug("No I2C pin mappings found!");
|
||||
let pin = (<any>this.opts.boardDef.i2cPins)[location as string] as string;
|
||||
return {type: "dalboard", pin: pin};
|
||||
} else {
|
||||
//it must be a MicrobitPin
|
||||
U.assert(typeof location === "string", "Unknown location type: " + location);
|
||||
let mbPin = <MicrobitPin>location;
|
||||
let boardPin = this.opts.boardDef.gpioPinMap[mbPin];
|
||||
U.assert(!!boardPin, "Unknown pin: " + location);
|
||||
return {type: "dalboard", pin: boardPin};
|
||||
}
|
||||
}
|
||||
private getBoardGroundPin(): string {
|
||||
let boardGround = this.opts.boardDef.groundPins[0] || null;
|
||||
if (!boardGround) {
|
||||
console.log("No available ground pin on board!");
|
||||
//TODO
|
||||
}
|
||||
return boardGround;
|
||||
}
|
||||
private getBoardThreeVoltPin(): string {
|
||||
let threeVoltPin = this.opts.boardDef.threeVoltPins[0] || null;
|
||||
if (!threeVoltPin) {
|
||||
console.log("No available 3.3V pin on board!");
|
||||
//TODO
|
||||
}
|
||||
return threeVoltPin;
|
||||
}
|
||||
private allocPowerWires(powerUsage: PowerUsage): PartAndWiresInst {
|
||||
let boardGroundPin = this.getBoardGroundPin();
|
||||
let threeVoltPin = this.getBoardThreeVoltPin();
|
||||
const topLeft: BBLoc = {type: "breadboard", row: "-", col: "26"};
|
||||
const botLeft: BBLoc = {type: "breadboard", row: "-", col: "1"};
|
||||
const topRight: BBLoc = {type: "breadboard", row: "-", col: "50"};
|
||||
const botRight: BBLoc = {type: "breadboard", row: "-", col: "25"};
|
||||
let top: BBLoc, bot: BBLoc;
|
||||
if (this.opts.boardDef.attachPowerOnRight) {
|
||||
top = topRight;
|
||||
bot = botRight;
|
||||
} else {
|
||||
top = topLeft;
|
||||
bot = botLeft;
|
||||
}
|
||||
let groundWires: WireInst[] = [];
|
||||
let threeVoltWires: WireInst[] = [];
|
||||
if (powerUsage.bottomGround && powerUsage.topGround) {
|
||||
//bb top - <==> bb bot -
|
||||
groundWires.push({
|
||||
start: this.allocLocation("ground", {referenceBBPin: top}),
|
||||
end: this.allocLocation("ground", {referenceBBPin: bot}),
|
||||
color: GROUND_COLOR,
|
||||
});
|
||||
}
|
||||
if (powerUsage.topGround) {
|
||||
//board - <==> bb top -
|
||||
groundWires.push({
|
||||
start: this.allocLocation("ground", {referenceBBPin: top}),
|
||||
end: {type: "dalboard", pin: boardGroundPin},
|
||||
color: GROUND_COLOR,
|
||||
});
|
||||
} else if (powerUsage.bottomGround) {
|
||||
//board - <==> bb bot -
|
||||
groundWires.push({
|
||||
start: this.allocLocation("ground", {referenceBBPin: bot}),
|
||||
end: {type: "dalboard", pin: boardGroundPin},
|
||||
color: GROUND_COLOR,
|
||||
});
|
||||
}
|
||||
if (powerUsage.bottomThreeVolt && powerUsage.bottomGround) {
|
||||
//bb top + <==> bb bot +
|
||||
threeVoltWires.push({
|
||||
start: this.allocLocation("threeVolt", {referenceBBPin: top}),
|
||||
end: this.allocLocation("threeVolt", {referenceBBPin: bot}),
|
||||
color: POWER_COLOR,
|
||||
});
|
||||
}
|
||||
if (powerUsage.topThreeVolt) {
|
||||
//board + <==> bb top +
|
||||
threeVoltWires.push({
|
||||
start: this.allocLocation("threeVolt", {referenceBBPin: top}),
|
||||
end: {type: "dalboard", pin: threeVoltPin},
|
||||
color: POWER_COLOR,
|
||||
});
|
||||
} else if (powerUsage.bottomThreeVolt) {
|
||||
//board + <==> bb bot +
|
||||
threeVoltWires.push({
|
||||
start: this.allocLocation("threeVolt", {referenceBBPin: bot}),
|
||||
end: {type: "dalboard", pin: threeVoltPin},
|
||||
color: POWER_COLOR,
|
||||
});
|
||||
}
|
||||
let assembly: AssemblyStep[] = [];
|
||||
if (groundWires.length > 0)
|
||||
assembly.push({wireIndices: groundWires.map((w, i) => i)});
|
||||
let numGroundWires = groundWires.length;
|
||||
if (threeVoltWires.length > 0)
|
||||
assembly.push({wireIndices: threeVoltWires.map((w, i) => i + numGroundWires)});
|
||||
return {
|
||||
wires: groundWires.concat(threeVoltWires),
|
||||
assembly: assembly
|
||||
};
|
||||
}
|
||||
private allocWire(wireIR: WireIR): WireInst {
|
||||
let ends = [wireIR.start, wireIR.end];
|
||||
let endIsPower = ends.map(e => e === "ground" || e === "threeVolt");
|
||||
//allocate non-power first so we know the nearest pin for the power end
|
||||
let endInsts = ends.map((e, idx) => !endIsPower[idx] ? this.allocLocation(e, {}) : null)
|
||||
//allocate power pins closest to the other end of the wire
|
||||
endInsts = endInsts.map((e, idx) => {
|
||||
if (e)
|
||||
return e;
|
||||
let locInst = <BBLoc>endInsts[1 - idx]; // non-power end
|
||||
let l = this.allocLocation(ends[idx], {
|
||||
referenceBBPin: locInst,
|
||||
});
|
||||
return l;
|
||||
});
|
||||
return {start: endInsts[0], end: endInsts[1], color: wireIR.color};
|
||||
}
|
||||
private allocPart(ir: PartPlacement): PartInst {
|
||||
let bbConnections = ir.pins
|
||||
.filter(p => isConnectedToBB(p.def))
|
||||
.map(p => {
|
||||
let rowIdx = ir.startRowIdx + p.bbFit.partRelativeRowIdx;
|
||||
if (rowIdx >= 7) //account for middle gap
|
||||
rowIdx -= 2;
|
||||
let rowName = visuals.getRowName(rowIdx);
|
||||
let colIdx = ir.startColumnIdx + p.bbFit.partRelativeColIdx;
|
||||
let colName = visuals.getColumnName(colIdx);
|
||||
return <BBLoc>{
|
||||
type: "breadboard",
|
||||
row: rowName,
|
||||
col: colName,
|
||||
}
|
||||
});
|
||||
let part: PartInst = {
|
||||
name: ir.name,
|
||||
visual: ir.def.visual,
|
||||
bbFit: ir.bbFit,
|
||||
startColumnIdx: ir.startColumnIdx,
|
||||
startRowIdx: ir.startRowIdx,
|
||||
breadboardConnections: bbConnections,
|
||||
params: ir.partParams,
|
||||
simulationBehavior: ir.def.simulationBehavior
|
||||
}
|
||||
return part;
|
||||
}
|
||||
public allocAll(): AllocatorResult {
|
||||
let partNmAndDefs = this.opts.partsList
|
||||
.map(partName => {return {name: partName, def: this.opts.partDefs[partName]}})
|
||||
.filter(d => !!d.def);
|
||||
if (partNmAndDefs.length > 0) {
|
||||
let partNmsList = partNmAndDefs.map(p => p.name);
|
||||
let partDefsList = partNmAndDefs.map(p => p.def);
|
||||
let dimensions = partNmAndDefs.map(nmAndPart => this.computePartDimensions(nmAndPart.def, nmAndPart.name));
|
||||
let partIRs: PartIR[] = [];
|
||||
partNmAndDefs.forEach((nmAndDef, idx) => {
|
||||
let dims = dimensions[idx];
|
||||
let irs = this.allocPartIRs(nmAndDef.def, nmAndDef.name, dims);
|
||||
partIRs = partIRs.concat(irs);
|
||||
})
|
||||
let partPlacements = this.placeParts(partIRs);
|
||||
let partsAndWireIRs = partPlacements.map(p => this.allocWireIRs(p));
|
||||
let allWireIRs = partsAndWireIRs.map(p => p.wires).reduce((p, n) => p.concat(n), []);
|
||||
let allPowerUsage = allWireIRs.map(w => computePowerUsage(w));
|
||||
this.powerUsage = mergePowerUsage(allPowerUsage);
|
||||
let basicWires = this.allocPowerWires(this.powerUsage);
|
||||
let partsAndWires: PartAndWiresInst[] = partsAndWireIRs.map((irs, idx) => {
|
||||
let part = this.allocPart(irs);
|
||||
let wires = irs.wires.map(w => this.allocWire(w));
|
||||
let pinIdxToWireIdx: number[] = [];
|
||||
irs.wires.forEach((wIR, idx) => {
|
||||
pinIdxToWireIdx[wIR.pinIdx] = idx;
|
||||
});
|
||||
let assembly: AssemblyStep[] = irs.def.assembly.map(stepDef => {
|
||||
return {
|
||||
part: stepDef.part,
|
||||
wireIndices: (stepDef.pinIndices || []).map(i => pinIdxToWireIdx[i])
|
||||
}
|
||||
});
|
||||
return {
|
||||
part: part,
|
||||
wires: wires,
|
||||
assembly: assembly
|
||||
}
|
||||
});
|
||||
let all = [basicWires].concat(partsAndWires);
|
||||
return {
|
||||
partsAndWires: all
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
partsAndWires: []
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function allocateDefinitions(opts: AllocatorOpts): AllocatorResult {
|
||||
return new Allocator(opts).allocAll();
|
||||
}
|
||||
}
|
128
sim/dalboard.ts
@ -1,12 +1,7 @@
|
||||
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>
|
||||
|
||||
namespace pxsim {
|
||||
export class DalBoard extends BaseBoard {
|
||||
id: string;
|
||||
|
||||
// the bus
|
||||
bus: EventBus;
|
||||
|
||||
export class DalBoard extends CoreBoard {
|
||||
// state & update logic for component services
|
||||
ledMatrixState: LedMatrixState;
|
||||
edgeConnectorState: EdgeConnectorState;
|
||||
@ -19,31 +14,58 @@ namespace pxsim {
|
||||
radioState: RadioState;
|
||||
neopixelState: NeoPixelState;
|
||||
|
||||
// updates
|
||||
updateSubscribers: (() => void)[];
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
this.id = "b" + Math_.random(2147483647);
|
||||
this.bus = new EventBus(runtime);
|
||||
|
||||
// components
|
||||
this.ledMatrixState = new LedMatrixState(runtime);
|
||||
this.buttonPairState = new ButtonPairState();
|
||||
this.edgeConnectorState = new EdgeConnectorState();
|
||||
this.radioState = new RadioState(runtime);
|
||||
this.accelerometerState = new AccelerometerState(runtime);
|
||||
this.serialState = new SerialState();
|
||||
this.thermometerState = new ThermometerState();
|
||||
this.lightSensorState = new LightSensorState();
|
||||
this.compassState = new CompassState();
|
||||
this.neopixelState = new NeoPixelState();
|
||||
this.builtinParts["ledmatrix"] = this.ledMatrixState = new LedMatrixState(runtime);
|
||||
this.builtinParts["buttonpair"] = this.buttonPairState = new ButtonPairState({
|
||||
ID_BUTTON_A: DAL.MICROBIT_ID_BUTTON_A,
|
||||
ID_BUTTON_B: DAL.MICROBIT_ID_BUTTON_B,
|
||||
ID_BUTTON_AB: DAL.MICROBIT_ID_BUTTON_AB,
|
||||
BUTTON_EVT_UP: DAL.MICROBIT_BUTTON_EVT_UP,
|
||||
BUTTON_EVT_CLICK: DAL.MICROBIT_BUTTON_EVT_CLICK
|
||||
});
|
||||
this.builtinParts["edgeconnector"] = this.edgeConnectorState = new EdgeConnectorState({
|
||||
pins: [
|
||||
DAL.MICROBIT_ID_IO_P0,
|
||||
DAL.MICROBIT_ID_IO_P1,
|
||||
DAL.MICROBIT_ID_IO_P2,
|
||||
DAL.MICROBIT_ID_IO_P3,
|
||||
DAL.MICROBIT_ID_IO_P4,
|
||||
DAL.MICROBIT_ID_IO_P5,
|
||||
DAL.MICROBIT_ID_IO_P6,
|
||||
DAL.MICROBIT_ID_IO_P7,
|
||||
DAL.MICROBIT_ID_IO_P8,
|
||||
DAL.MICROBIT_ID_IO_P9,
|
||||
DAL.MICROBIT_ID_IO_P10,
|
||||
DAL.MICROBIT_ID_IO_P11,
|
||||
DAL.MICROBIT_ID_IO_P12,
|
||||
DAL.MICROBIT_ID_IO_P13,
|
||||
DAL.MICROBIT_ID_IO_P14,
|
||||
DAL.MICROBIT_ID_IO_P15,
|
||||
DAL.MICROBIT_ID_IO_P16,
|
||||
0,
|
||||
0,
|
||||
DAL.MICROBIT_ID_IO_P19,
|
||||
DAL.MICROBIT_ID_IO_P20
|
||||
]
|
||||
});
|
||||
this.builtinParts["radio"] = this.radioState = new RadioState(runtime);
|
||||
this.builtinParts["accelerometer"] = this.accelerometerState = new AccelerometerState(runtime);
|
||||
this.builtinParts["serial"] = this.serialState = new SerialState();
|
||||
this.builtinParts["thermometer"] = this.thermometerState = new ThermometerState();
|
||||
this.builtinParts["lightsensor"] = this.lightSensorState = new LightSensorState();
|
||||
this.builtinParts["compass"] = this.compassState = new CompassState();
|
||||
this.builtinParts["neopixel"] = this.neopixelState = new NeoPixelState();
|
||||
|
||||
// updates
|
||||
this.updateSubscribers = []
|
||||
this.updateView = () => {
|
||||
this.updateSubscribers.forEach(sub => sub());
|
||||
}
|
||||
this.builtinVisuals["buttonpair"] = () => new visuals.ButtonPairView();
|
||||
this.builtinVisuals["ledmatrix"] = () => new visuals.LedMatrixView();
|
||||
this.builtinVisuals["neopixel"] = () => new visuals.NeoPixelView();
|
||||
|
||||
this.builtinPartVisuals["buttonpair"] = (xy: visuals.Coord) => visuals.mkBtnSvg(xy);
|
||||
this.builtinPartVisuals["ledmatrix"] = (xy: visuals.Coord) => visuals.mkLedMatrixSvg(xy, 8, 8);
|
||||
this.builtinPartVisuals["neopixel"] = (xy: visuals.Coord) => visuals.mkNeoPixelPart(xy);
|
||||
}
|
||||
|
||||
receiveMessage(msg: SimulatorMessage) {
|
||||
@ -65,23 +87,17 @@ namespace pxsim {
|
||||
}
|
||||
}
|
||||
|
||||
kill() {
|
||||
super.kill();
|
||||
AudioContextManager.stop();
|
||||
}
|
||||
|
||||
initAsync(msg: SimulatorRunMessage): Promise<void> {
|
||||
super.initAsync(msg);
|
||||
|
||||
let options = (msg.options || {}) as RuntimeOptions;
|
||||
const options = (msg.options || {}) as RuntimeOptions;
|
||||
|
||||
let boardDef = CURRENT_BOARD; //TODO: read from pxt.json/pxttarget.json
|
||||
const boardDef = msg.boardDefinition;
|
||||
const cmpsList = msg.parts;
|
||||
const cmpDefs = msg.partDefinitions || {};
|
||||
const fnArgs = msg.fnArgs;
|
||||
|
||||
let cmpsList = msg.parts;
|
||||
let cmpDefs = msg.partDefinitions || {}; //TODO: read from pxt.json/pxttarget.json
|
||||
let fnArgs = msg.fnArgs;
|
||||
|
||||
let viewHost = new visuals.BoardHost({
|
||||
const opts : visuals.BoardHostOpts = {
|
||||
state: this,
|
||||
boardDef: boardDef,
|
||||
partsList: cmpsList,
|
||||
@ -89,7 +105,8 @@ namespace pxsim {
|
||||
fnArgs: fnArgs,
|
||||
maxWidth: "100%",
|
||||
maxHeight: "100%",
|
||||
});
|
||||
};
|
||||
const viewHost = new visuals.BoardHost(pxsim.visuals.mkBoardView(opts), opts);
|
||||
|
||||
document.body.innerHTML = ""; // clear children
|
||||
document.body.appendChild(viewHost.getView());
|
||||
@ -97,4 +114,37 @@ namespace pxsim {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
export function initRuntimeWithDalBoard() {
|
||||
U.assert(!runtime.board);
|
||||
let b = new DalBoard();
|
||||
runtime.board = b;
|
||||
runtime.postError = (e) => {
|
||||
led.setBrightness(255);
|
||||
let img = board().ledMatrixState.image;
|
||||
img.clear();
|
||||
img.set(0, 4, 255);
|
||||
img.set(1, 3, 255);
|
||||
img.set(2, 3, 255);
|
||||
img.set(3, 3, 255);
|
||||
img.set(4, 4, 255);
|
||||
img.set(0, 0, 255);
|
||||
img.set(1, 0, 255);
|
||||
img.set(0, 1, 255);
|
||||
img.set(1, 1, 255);
|
||||
img.set(3, 0, 255);
|
||||
img.set(4, 0, 255);
|
||||
img.set(3, 1, 255);
|
||||
img.set(4, 1, 255);
|
||||
runtime.updateDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
if (!pxsim.initCurrentRuntime) {
|
||||
pxsim.initCurrentRuntime = initRuntimeWithDalBoard;
|
||||
}
|
||||
|
||||
export function board() {
|
||||
return runtime.board as DalBoard;
|
||||
}
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
/// <reference path="../node_modules/pxt-core/typings/bluebird/bluebird.d.ts"/>
|
||||
/// <reference path="../node_modules/pxt-core/built/pxtparts.d.ts"/>
|
||||
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>
|
||||
/// <reference path="../libs/microbit/dal.d.ts"/>
|
||||
/// <reference path="./visuals/neopixel.ts"/>
|
||||
|
||||
namespace pxsim {
|
||||
export const MICROBIT_DEF: BoardDefinition = {
|
||||
visual: "microbit",
|
||||
gpioPinBlocks: [
|
||||
["P0"], ["P1"], ["P2"],
|
||||
["P3"],
|
||||
["P4", "P5", "P6", "P7"],
|
||||
["P8", "P9", "P10", "P11", "P12"],
|
||||
["P16"],
|
||||
],
|
||||
gpioPinMap: {
|
||||
"P0": "P0",
|
||||
"P1": "P1",
|
||||
"P2": "P2",
|
||||
"P3": "P3",
|
||||
"P4": "P4",
|
||||
"P5": "P5",
|
||||
"P6": "P6",
|
||||
"P7": "P7",
|
||||
"P8": "P8",
|
||||
"P9": "P9",
|
||||
"P10": "P10",
|
||||
"P11": "P11",
|
||||
"P12": "P12",
|
||||
"P13": "P13",
|
||||
"P14": "P14",
|
||||
"P15": "P15",
|
||||
"P16": "P16",
|
||||
"P19": "P19",
|
||||
"P20": "P20",
|
||||
},
|
||||
spiPins: {
|
||||
MOSI: "P15",
|
||||
MISO: "P14",
|
||||
SCK: "P13",
|
||||
},
|
||||
i2cPins: {
|
||||
SDA: "P20",
|
||||
SCL: "P19",
|
||||
},
|
||||
analogInPins: ["P0", "P1", "P2", "P3", "P10"],
|
||||
groundPins: ["GND"],
|
||||
threeVoltPins: ["+3v3"],
|
||||
attachPowerOnRight: true,
|
||||
onboardComponents: ["buttonpair", "ledmatrix", "speaker"],
|
||||
useCrocClips: true,
|
||||
marginWhenBreadboarding: [0, 0, 80, 0],
|
||||
}
|
||||
|
||||
export const builtinComponentSimVisual: Map<() => visuals.IBoardPart<any>> = {
|
||||
"buttonpair": () => new visuals.ButtonPairView(),
|
||||
"ledmatrix": () => new visuals.LedMatrixView(),
|
||||
"neopixel": () => new visuals.NeoPixelView(),
|
||||
};
|
||||
export const builtinComponentSimState: Map<(d: DalBoard) => any> = {
|
||||
"buttonpair": (d: DalBoard) => d.buttonPairState,
|
||||
"ledmatrix": (d: DalBoard) => d.ledMatrixState,
|
||||
"edgeconnector": (d: DalBoard) => d.edgeConnectorState,
|
||||
"serial": (d: DalBoard) => d.serialState,
|
||||
"radio": (d: DalBoard) => d.radioState,
|
||||
"thermometer": (d: DalBoard) => d.thermometerState,
|
||||
"accelerometer": (d: DalBoard) => d.accelerometerState,
|
||||
"compass": (d: DalBoard) => d.compassState,
|
||||
"lightsensor": (d: DalBoard) => d.lightSensorState,
|
||||
"neopixel": (d: DalBoard) => d.neopixelState,
|
||||
};
|
||||
export const builtinComponentPartVisual: Map<(xy: visuals.Coord) => visuals.SVGElAndSize> = {
|
||||
"buttonpair": (xy: visuals.Coord) => visuals.mkBtnSvg(xy),
|
||||
"ledmatrix": (xy: visuals.Coord) => visuals.mkLedMatrixSvg(xy, 8, 8),
|
||||
"neopixel": (xy: visuals.Coord) => visuals.mkNeoPixelPart(xy),
|
||||
};
|
||||
|
||||
//TODO: add multiple board support
|
||||
export const CURRENT_BOARD = MICROBIT_DEF;
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
/// <reference path="../../node_modules/pxt-core/typings/bluebird/bluebird.d.ts"/>
|
||||
/// <reference path="../../node_modules/pxt-core/built/pxtsim.d.ts"/>
|
||||
/// <reference path="../../node_modules/pxt-core/built/pxtrunner.d.ts"/>
|
||||
/// <reference path="../visuals/genericboard.ts"/>
|
||||
/// <reference path="../visuals/wiring.ts"/>
|
||||
/// <reference path="../node_modules/pxt-core/typings/bluebird/bluebird.d.ts"/>
|
||||
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>
|
||||
/// <reference path="../node_modules/pxt-core/built/pxtrunner.d.ts"/>
|
||||
|
||||
//HACK: allows instructions.html to access pxtblocks without requiring simulator.html to import blocks as well
|
||||
if (!(<any>window).pxt) (<any>window).pxt = {};
|
||||
@ -284,13 +282,14 @@ namespace pxsim.instructions {
|
||||
return div;
|
||||
}
|
||||
function mkCmpDiv(cmp: "wire" | PartVisualDefinition, opts: mkCmpDivOpts): HTMLElement {
|
||||
let state = runtime.board as pxsim.CoreBoard;
|
||||
let el: visuals.SVGElAndSize;
|
||||
if (cmp == "wire") {
|
||||
el = visuals.mkWirePart([0, 0], opts.wireClr || "red", opts.crocClips);
|
||||
} else {
|
||||
let partVis = <PartVisualDefinition>cmp;
|
||||
if (typeof partVis.builtIn == "string") {
|
||||
let cnstr = builtinComponentPartVisual[partVis.builtIn];
|
||||
let cnstr = state.builtinPartVisuals[partVis.builtIn];
|
||||
el = cnstr([0, 0]);
|
||||
} else {
|
||||
el = visuals.mkGenericPartSVG(partVis);
|
||||
@ -355,8 +354,8 @@ namespace pxsim.instructions {
|
||||
};
|
||||
}
|
||||
function mkBlankBoardAndBreadboard(boardDef: BoardDefinition, cmpDefs: Map<PartDefinition>, fnArgs: any, width: number, buildMode: boolean = false): visuals.BoardHost {
|
||||
let state = runtime.board as pxsim.DalBoard;
|
||||
let boardHost = new visuals.BoardHost({
|
||||
const state = runtime.board as pxsim.CoreBoard;
|
||||
const opts : visuals.BoardHostOpts = {
|
||||
state: state,
|
||||
boardDef: boardDef,
|
||||
forceBreadboard: true,
|
||||
@ -364,7 +363,8 @@ namespace pxsim.instructions {
|
||||
maxWidth: `${width}px`,
|
||||
fnArgs: fnArgs,
|
||||
wireframe: buildMode,
|
||||
});
|
||||
};
|
||||
let boardHost = new visuals.BoardHost(pxsim.visuals.mkBoardView(opts), opts);
|
||||
let view = boardHost.getView();
|
||||
svg.addClass(view, "board-svg");
|
||||
|
||||
@ -615,6 +615,9 @@ ${tsPackage}
|
||||
});
|
||||
}
|
||||
|
||||
// board def
|
||||
const boardDef = JSON.parse(getQsVal("board")) as pxsim.BoardDefinition;
|
||||
|
||||
//parts list
|
||||
let parts = (getQsVal("parts") || "").split(" ");
|
||||
parts.sort();
|
||||
@ -638,7 +641,6 @@ ${tsPackage}
|
||||
|
||||
style.textContent += STYLE;
|
||||
|
||||
const boardDef = CURRENT_BOARD;
|
||||
const cmpDefs = partDefinitions;
|
||||
|
||||
//props
|
272
sim/simlib.ts
@ -1,272 +0,0 @@
|
||||
/// <reference path="../node_modules/pxt-core/typings/bluebird/bluebird.d.ts"/>
|
||||
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>
|
||||
/// <reference path="../libs/microbit/dal.d.ts"/>
|
||||
|
||||
namespace pxsim {
|
||||
export type BoardPin = string;
|
||||
export interface BBLoc {
|
||||
type: "breadboard",
|
||||
row: string,
|
||||
col: string
|
||||
xOffset?: number,
|
||||
yOffset?: number
|
||||
};
|
||||
export interface BoardLoc {
|
||||
type: "dalboard",
|
||||
pin: BoardPin
|
||||
};
|
||||
export type Loc = BBLoc | BoardLoc;
|
||||
|
||||
export function initRuntimeWithDalBoard() {
|
||||
U.assert(!runtime.board);
|
||||
let b = new DalBoard();
|
||||
runtime.board = b;
|
||||
runtime.postError = (e) => {
|
||||
led.setBrightness(255);
|
||||
let img = board().ledMatrixState.image;
|
||||
img.clear();
|
||||
img.set(0, 4, 255);
|
||||
img.set(1, 3, 255);
|
||||
img.set(2, 3, 255);
|
||||
img.set(3, 3, 255);
|
||||
img.set(4, 4, 255);
|
||||
img.set(0, 0, 255);
|
||||
img.set(1, 0, 255);
|
||||
img.set(0, 1, 255);
|
||||
img.set(1, 1, 255);
|
||||
img.set(3, 0, 255);
|
||||
img.set(4, 0, 255);
|
||||
img.set(3, 1, 255);
|
||||
img.set(4, 1, 255);
|
||||
runtime.updateDisplay();
|
||||
}
|
||||
}
|
||||
if (!pxsim.initCurrentRuntime) {
|
||||
pxsim.initCurrentRuntime = initRuntimeWithDalBoard;
|
||||
}
|
||||
|
||||
export function board() {
|
||||
return runtime.board as DalBoard;
|
||||
}
|
||||
|
||||
export function mkRange(a: number, b: number): number[] {
|
||||
let res: number[] = [];
|
||||
for (; a < b; a++)
|
||||
res.push(a);
|
||||
return res;
|
||||
}
|
||||
|
||||
export function parseQueryString(): (key: string) => string {
|
||||
let qs = window.location.search.substring(1);
|
||||
let getQsVal = (key: string) => decodeURIComponent((qs.split(`${key}=`)[1] || "").split("&")[0] || ""); //.replace(/\+/g, " ");
|
||||
return getQsVal;
|
||||
}
|
||||
}
|
||||
|
||||
namespace pxsim.visuals {
|
||||
export interface IPointerEvents {
|
||||
up: string,
|
||||
down: string,
|
||||
move: string,
|
||||
leave: string
|
||||
}
|
||||
|
||||
export const pointerEvents: IPointerEvents = !!(window as any).PointerEvent ? {
|
||||
up: "pointerup",
|
||||
down: "pointerdown",
|
||||
move: "pointermove",
|
||||
leave: "pointerleave"
|
||||
} : {
|
||||
up: "mouseup",
|
||||
down: "mousedown",
|
||||
move: "mousemove",
|
||||
leave: "mouseleave"
|
||||
};
|
||||
|
||||
export function translateEl(el: SVGElement, xy: [number, number]) {
|
||||
//TODO append translation instead of replacing the full transform
|
||||
svg.hydrate(el, { transform: `translate(${xy[0]} ${xy[1]})` });
|
||||
}
|
||||
|
||||
export interface ComposeOpts {
|
||||
el1: SVGAndSize<SVGSVGElement>,
|
||||
scaleUnit1: number,
|
||||
el2: SVGAndSize<SVGSVGElement>,
|
||||
scaleUnit2: number,
|
||||
margin: [number, number, number, number],
|
||||
middleMargin: number,
|
||||
maxWidth?: string,
|
||||
maxHeight?: string,
|
||||
}
|
||||
export interface ComposeResult {
|
||||
host: SVGSVGElement,
|
||||
scaleUnit: number,
|
||||
under: SVGGElement,
|
||||
over: SVGGElement,
|
||||
edges: number[],
|
||||
toHostCoord1: (xy: Coord) => Coord,
|
||||
toHostCoord2: (xy: Coord) => Coord,
|
||||
}
|
||||
export function composeSVG(opts: ComposeOpts): ComposeResult {
|
||||
let [a, b] = [opts.el1, opts.el2];
|
||||
U.assert(a.x == 0 && a.y == 0 && b.x == 0 && b.y == 0, "el1 and el2 x,y offsets not supported");
|
||||
let setXY = (e: SVGSVGElement, x: number, y: number) => svg.hydrate(e, { x: x, y: y });
|
||||
let setWH = (e: SVGSVGElement, w: string, h: string) => {
|
||||
if (w)
|
||||
svg.hydrate(e, { width: w });
|
||||
if (h)
|
||||
svg.hydrate(e, { height: h });
|
||||
}
|
||||
let setWHpx = (e: SVGSVGElement, w: number, h: number) => svg.hydrate(e, { width: `${w}px`, height: `${h}px` });
|
||||
let scaleUnit = opts.scaleUnit2;
|
||||
let aScalar = opts.scaleUnit2 / opts.scaleUnit1;
|
||||
let bScalar = 1.0;
|
||||
let aw = a.w * aScalar;
|
||||
let ah = a.h * aScalar;
|
||||
setWHpx(a.el, aw, ah);
|
||||
let bw = b.w * bScalar;
|
||||
let bh = b.h * bScalar;
|
||||
setWHpx(b.el, bw, bh);
|
||||
let [mt, mr, mb, ml] = opts.margin;
|
||||
let mm = opts.middleMargin;
|
||||
let innerW = Math.max(aw, bw);
|
||||
let ax = mr + (innerW - aw) / 2.0;
|
||||
let ay = mt;
|
||||
setXY(a.el, ax, ay);
|
||||
let bx = mr + (innerW - bw) / 2.0;
|
||||
let by = ay + ah + mm;
|
||||
setXY(b.el, bx, by);
|
||||
let edges = [ay, ay + ah, by, by + bh];
|
||||
let w = mr + innerW + ml;
|
||||
let h = mt + ah + mm + bh + mb;
|
||||
let host = <SVGSVGElement>svg.elt("svg", {
|
||||
"version": "1.0",
|
||||
"viewBox": `0 0 ${w} ${h}`,
|
||||
"class": `sim-bb`,
|
||||
});
|
||||
setWH(host, opts.maxWidth, opts.maxHeight);
|
||||
setXY(host, 0, 0);
|
||||
let under = <SVGGElement>svg.child(host, "g");
|
||||
host.appendChild(a.el);
|
||||
host.appendChild(b.el);
|
||||
let over = <SVGGElement>svg.child(host, "g");
|
||||
let toHostCoord1 = (xy: Coord): Coord => {
|
||||
let [x, y] = xy;
|
||||
return [x * aScalar + ax, y * aScalar + ay];
|
||||
};
|
||||
let toHostCoord2 = (xy: Coord): Coord => {
|
||||
let [x, y] = xy;
|
||||
return [x * bScalar + bx, y * bScalar + by];
|
||||
};
|
||||
return {
|
||||
under: under,
|
||||
over: over,
|
||||
host: host,
|
||||
edges: edges,
|
||||
scaleUnit: scaleUnit,
|
||||
toHostCoord1: toHostCoord1,
|
||||
toHostCoord2: toHostCoord2,
|
||||
};
|
||||
}
|
||||
|
||||
export function mkScaleFn(originUnit: number, targetUnit: number): (n: number) => number {
|
||||
return (n: number) => n * (targetUnit / originUnit);
|
||||
}
|
||||
export interface MkImageOpts {
|
||||
image: string,
|
||||
width: number,
|
||||
height: number,
|
||||
imageUnitDist: number,
|
||||
targetUnitDist: number
|
||||
}
|
||||
export function mkImageSVG(opts: MkImageOpts): SVGAndSize<SVGImageElement> {
|
||||
let scaleFn = mkScaleFn(opts.imageUnitDist, opts.targetUnitDist);
|
||||
let w = scaleFn(opts.width);
|
||||
let h = scaleFn(opts.height);
|
||||
let img = <SVGImageElement>svg.elt("image", {
|
||||
width: w,
|
||||
height: h,
|
||||
"href": `${opts.image}`
|
||||
});
|
||||
return { el: img, w: w, h: h, x: 0, y: 0 };
|
||||
}
|
||||
|
||||
export type Coord = [number, number];
|
||||
export function findDistSqrd(a: Coord, b: Coord): number {
|
||||
let x = a[0] - b[0];
|
||||
let y = a[1] - b[1];
|
||||
return x * x + y * y;
|
||||
}
|
||||
export function findClosestCoordIdx(a: Coord, bs: Coord[]): number {
|
||||
let dists = bs.map(b => findDistSqrd(a, b));
|
||||
let minIdx = dists.reduce((prevIdx, currDist, currIdx, arr) => {
|
||||
return currDist < arr[prevIdx] ? currIdx : prevIdx;
|
||||
}, 0);
|
||||
return minIdx;
|
||||
}
|
||||
|
||||
export interface IBoardPart<T> {
|
||||
style: string,
|
||||
element: SVGElement,
|
||||
overElement?: SVGElement,
|
||||
defs: SVGElement[],
|
||||
init(bus: EventBus, state: T, svgEl: SVGSVGElement, otherParams: Map<string>): void, //NOTE: constructors not supported in interfaces
|
||||
moveToCoord(xy: Coord): void,
|
||||
updateState(): void,
|
||||
updateTheme(): void,
|
||||
}
|
||||
|
||||
export function mkTxt(cx: number, cy: number, size: number, rot: number, txt: string, txtXOffFactor?: number, txtYOffFactor?: number): SVGTextElement {
|
||||
let el = <SVGTextElement>svg.elt("text")
|
||||
//HACK: these constants (txtXOffFactor, txtYOffFactor) tweak the way this algorithm knows how to center the text
|
||||
txtXOffFactor = txtXOffFactor || -0.33333;
|
||||
txtYOffFactor = txtYOffFactor || 0.3;
|
||||
const xOff = txtXOffFactor * size * txt.length;
|
||||
const yOff = txtYOffFactor * size;
|
||||
svg.hydrate(el, {
|
||||
style: `font-size:${size}px;`,
|
||||
transform: `translate(${cx} ${cy}) rotate(${rot}) translate(${xOff} ${yOff})`
|
||||
});
|
||||
svg.addClass(el, "noselect");
|
||||
el.textContent = txt;
|
||||
return el;
|
||||
}
|
||||
|
||||
export type WireColor =
|
||||
"black" | "white" | "gray" | "purple" | "blue" | "green" | "yellow" | "orange" | "red" | "brown" | "pink";
|
||||
export const GPIO_WIRE_COLORS = ["pink", "green", "purple", "orange", "yellow"];
|
||||
export const WIRE_COLOR_MAP: Map<string> = {
|
||||
black: "#514f4d",
|
||||
white: "#fcfdfc",
|
||||
gray: "#acabab",
|
||||
purple: "#a772a1",
|
||||
blue: "#01a6e8",
|
||||
green: "#3cce73",
|
||||
yellow: "#ece600",
|
||||
orange: "#fdb262",
|
||||
red: "#f44f43",
|
||||
brown: "#c89764",
|
||||
pink: "#ff80fa"
|
||||
}
|
||||
export function mapWireColor(clr: WireColor | string): string {
|
||||
return WIRE_COLOR_MAP[clr] || clr;
|
||||
}
|
||||
|
||||
export interface SVGAndSize<T extends SVGElement> {
|
||||
el: T,
|
||||
y: number,
|
||||
x: number,
|
||||
w: number,
|
||||
h: number
|
||||
};
|
||||
export type SVGElAndSize = SVGAndSize<SVGElement>;
|
||||
|
||||
export const PIN_DIST = 15;
|
||||
|
||||
export interface BoardView {
|
||||
getView(): SVGAndSize<SVGSVGElement>;
|
||||
getCoord(pinNm: string): Coord;
|
||||
getPinDist(): number;
|
||||
highlightPin(pinNm: string): void;
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
namespace pxsim.input {
|
||||
export function onButtonPressed(button: number, handler: RefAction): void {
|
||||
let b = board().buttonPairState;
|
||||
if (button == DAL.MICROBIT_ID_BUTTON_AB && !b.usesButtonAB) {
|
||||
if (button == b.props.ID_BUTTON_AB && !b.usesButtonAB) {
|
||||
b.usesButtonAB = true;
|
||||
runtime.queueDisplayUpdate();
|
||||
}
|
||||
@ -10,32 +10,12 @@ namespace pxsim.input {
|
||||
|
||||
export function buttonIsPressed(button: number): boolean {
|
||||
let b = board().buttonPairState;
|
||||
if (button == DAL.MICROBIT_ID_BUTTON_AB && !b.usesButtonAB) {
|
||||
if (button == b.abBtn.id && !b.usesButtonAB) {
|
||||
b.usesButtonAB = true;
|
||||
runtime.queueDisplayUpdate();
|
||||
}
|
||||
if (button == DAL.MICROBIT_ID_BUTTON_A) return b.aBtn.pressed;
|
||||
if (button == DAL.MICROBIT_ID_BUTTON_B) return b.bBtn.pressed;
|
||||
if (button == b.aBtn.id) return b.aBtn.pressed;
|
||||
if (button == b.bBtn.id) return b.bBtn.pressed;
|
||||
return b.abBtn.pressed || (b.aBtn.pressed && b.bBtn.pressed);
|
||||
}
|
||||
}
|
||||
|
||||
namespace pxsim {
|
||||
export class Button {
|
||||
constructor(public id: number) { }
|
||||
pressed: boolean;
|
||||
}
|
||||
|
||||
export class ButtonPairState {
|
||||
usesButtonAB: boolean = false;
|
||||
aBtn: Button;
|
||||
bBtn: Button;
|
||||
abBtn: Button;
|
||||
|
||||
constructor() {
|
||||
this.aBtn = new Button(DAL.MICROBIT_ID_BUTTON_A);
|
||||
this.bBtn = new Button(DAL.MICROBIT_ID_BUTTON_B);
|
||||
this.abBtn = new Button(DAL.MICROBIT_ID_BUTTON_AB);
|
||||
}
|
||||
}
|
||||
}
|
@ -12,11 +12,4 @@ namespace pxsim.input {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
namespace pxsim {
|
||||
export class CompassState {
|
||||
usesHeading = false;
|
||||
heading = 90;
|
||||
}
|
||||
}
|
@ -24,64 +24,6 @@ namespace pxsim {
|
||||
export function getPin(id: number) {
|
||||
return board().edgeConnectorState.getPin(id);
|
||||
}
|
||||
|
||||
export enum PinFlags {
|
||||
Unused = 0,
|
||||
Digital = 0x0001,
|
||||
Analog = 0x0002,
|
||||
Input = 0x0004,
|
||||
Output = 0x0008,
|
||||
Touch = 0x0010
|
||||
}
|
||||
|
||||
export class Pin {
|
||||
constructor(public id: number) { }
|
||||
touched = false;
|
||||
value = 0;
|
||||
period = 0;
|
||||
mode = PinFlags.Unused;
|
||||
pitch = false;
|
||||
pull = 0; // PullDown
|
||||
|
||||
isTouched(): boolean {
|
||||
this.mode = PinFlags.Touch;
|
||||
return this.touched;
|
||||
}
|
||||
}
|
||||
|
||||
export class EdgeConnectorState {
|
||||
pins: Pin[];
|
||||
|
||||
constructor() {
|
||||
this.pins = [
|
||||
new Pin(DAL.MICROBIT_ID_IO_P0),
|
||||
new Pin(DAL.MICROBIT_ID_IO_P1),
|
||||
new Pin(DAL.MICROBIT_ID_IO_P2),
|
||||
new Pin(DAL.MICROBIT_ID_IO_P3),
|
||||
new Pin(DAL.MICROBIT_ID_IO_P4),
|
||||
new Pin(DAL.MICROBIT_ID_IO_P5),
|
||||
new Pin(DAL.MICROBIT_ID_IO_P6),
|
||||
new Pin(DAL.MICROBIT_ID_IO_P7),
|
||||
new Pin(DAL.MICROBIT_ID_IO_P8),
|
||||
new Pin(DAL.MICROBIT_ID_IO_P9),
|
||||
new Pin(DAL.MICROBIT_ID_IO_P10),
|
||||
new Pin(DAL.MICROBIT_ID_IO_P11),
|
||||
new Pin(DAL.MICROBIT_ID_IO_P12),
|
||||
new Pin(DAL.MICROBIT_ID_IO_P13),
|
||||
new Pin(DAL.MICROBIT_ID_IO_P14),
|
||||
new Pin(DAL.MICROBIT_ID_IO_P15),
|
||||
new Pin(DAL.MICROBIT_ID_IO_P16),
|
||||
null,
|
||||
null,
|
||||
new Pin(DAL.MICROBIT_ID_IO_P19),
|
||||
new Pin(DAL.MICROBIT_ID_IO_P20)
|
||||
];
|
||||
}
|
||||
|
||||
public getPin(id: number) {
|
||||
return this.pins.filter(p => p && p.id == id)[0] || null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace pxsim.pins {
|
||||
|
@ -116,72 +116,6 @@ namespace pxsim {
|
||||
}
|
||||
return font;
|
||||
}
|
||||
|
||||
export interface AnimationOptions {
|
||||
interval: number;
|
||||
// false means last frame
|
||||
frame: () => boolean;
|
||||
whenDone?: (cancelled: boolean) => void;
|
||||
}
|
||||
|
||||
export class AnimationQueue {
|
||||
private queue: AnimationOptions[] = [];
|
||||
private process: () => void;
|
||||
|
||||
constructor(private runtime: Runtime) {
|
||||
this.process = () => {
|
||||
let top = this.queue[0]
|
||||
if (!top) return
|
||||
if (this.runtime.dead) return
|
||||
runtime = this.runtime
|
||||
let res = top.frame()
|
||||
runtime.queueDisplayUpdate()
|
||||
runtime.maybeUpdateDisplay()
|
||||
if (res === false) {
|
||||
this.queue.shift();
|
||||
// if there is already something in the queue, start processing
|
||||
if (this.queue[0])
|
||||
setTimeout(this.process, this.queue[0].interval)
|
||||
// this may push additional stuff
|
||||
top.whenDone(false);
|
||||
} else {
|
||||
setTimeout(this.process, top.interval)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public cancelAll() {
|
||||
let q = this.queue
|
||||
this.queue = []
|
||||
for (let a of q) {
|
||||
a.whenDone(true)
|
||||
}
|
||||
}
|
||||
|
||||
public cancelCurrent() {
|
||||
let top = this.queue[0]
|
||||
if (top) {
|
||||
this.queue.shift();
|
||||
top.whenDone(true);
|
||||
}
|
||||
}
|
||||
|
||||
public enqueue(anim: AnimationOptions) {
|
||||
if (!anim.whenDone) anim.whenDone = () => { };
|
||||
this.queue.push(anim)
|
||||
// we start processing when the queue goes from 0 to 1
|
||||
if (this.queue.length == 1)
|
||||
this.process()
|
||||
}
|
||||
|
||||
public executeAsync(anim: AnimationOptions) {
|
||||
U.assert(!anim.whenDone)
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
anim.whenDone = resolve
|
||||
this.enqueue(anim)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace pxsim.images {
|
||||
@ -337,6 +271,7 @@ namespace pxsim.led {
|
||||
|
||||
export function stopAnimation(): void {
|
||||
board().ledMatrixState.animationQ.cancelAll();
|
||||
board().ledMatrixState.image.clear();
|
||||
}
|
||||
|
||||
export function setDisplayMode(mode: DisplayMode): void {
|
||||
|
@ -1,10 +1,3 @@
|
||||
namespace pxsim {
|
||||
export class LightSensorState {
|
||||
usesLightLevel = false;
|
||||
lightLevel = 128;
|
||||
}
|
||||
}
|
||||
|
||||
namespace pxsim.input {
|
||||
export function lightLevel(): number {
|
||||
let b = board().lightSensorState;
|
||||
|