Compare commits
53 Commits
Author | SHA1 | Date | |
---|---|---|---|
e545ae948a | |||
dc6386da52 | |||
c908794d23 | |||
8e27d596aa | |||
9b46145391 | |||
3182f7c546 | |||
8aed8548cc | |||
5e10bd7cc9 | |||
fddb9ff0d8 | |||
a0a0554633 | |||
df92a3daae | |||
26985f2813 | |||
e7fd68e7ee | |||
e63b764568 | |||
ef821e4b8b | |||
b7a547c2b4 | |||
43d600ab38 | |||
b38145e46a | |||
b29f8faa14 | |||
e58dd64780 | |||
b1028abb04 | |||
9f0f63a79e | |||
1c403e4ddb | |||
9143b34d9d | |||
f5a41d7c37 | |||
57c8698b58 | |||
4e3ed27f93 | |||
41977f087e | |||
c1a4a55e2b | |||
abc9e90cb9 | |||
3119bcc625 | |||
905da373c0 | |||
05dce8efce | |||
cbfc960594 | |||
c2c765098d | |||
9daf6ad9fc | |||
0c05ae9b64 | |||
27ea7cae56 | |||
80f9c52bac | |||
afef607ccf | |||
45fe7e6bb4 | |||
8e66b041e2 | |||
e99a2df578 | |||
7e5f3fdbf3 | |||
b538526948 | |||
889142d0f7 | |||
3791689fc4 | |||
d05f66650f | |||
a4f08e99a9 | |||
3999c215ce | |||
c6b8acb0b8 | |||
1e054f96ec | |||
190e5e2e03 |
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -12,6 +12,7 @@
|
||||
*.html text eol=lf
|
||||
*.py text eol=lf
|
||||
*.exp text eol=lf
|
||||
*.manifest text eol=lf
|
||||
|
||||
# do not enforce text for everything - it causes issues with random binary files
|
||||
|
||||
|
@ -16,9 +16,11 @@ that wraps codemicrobit.com and provides additional features.
|
||||
|
||||
### Sideloading
|
||||
|
||||
Find the latest build under ``win10/app/AppPackages/latest`` and run the ``Add-AppDevPackage.ps1`` PowerShell script.
|
||||
* Open Windows **settings** and search for **Developer options**
|
||||
* Enable the developer mode.
|
||||
* Find the latest build under ``win10/app/AppPackages/latest`` and run the ``Add-AppDevPackage.ps1`` PowerShell script (mouse right-click, then `run with PowerShell`)
|
||||
|
||||
### Building
|
||||
|
||||
* Install Visual Studio 2015 Update 2 or higher. Make sure the Windows 10 templates are installed.
|
||||
* open the ``win10/app.sln`` solution and launch the ``codemicrobit`` project.
|
||||
* open the ``win10/app.sln`` solution and launch the ``codemicrobit`` project.
|
||||
|
@ -62,7 +62,7 @@ basic.showString("BBC micro:bit");
|
||||
|
||||
## C++ Runtime
|
||||
|
||||
The C++ BBC micro:bit library, created at [Lancaster University](http://www.lancaster.ac.uk/), provides access to the hardware functions of the micro:bit,
|
||||
The [C++ BBC 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,
|
||||
as well as a set of helper functions (such as displaying a number/image/string on the LED screen).
|
||||
The JavaScript micro:bit library 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.
|
||||
|
133
docs/device.md
133
docs/device.md
@ -4,121 +4,80 @@ All the bits and pieces that make up your BBC micro:bit
|
||||
|
||||

|
||||
|
||||
### Lights
|
||||
### LED Screen and Status LED
|
||||
|
||||
### What are the red lights on the front?
|
||||
The red lights are [LEDs](/microbit/device/screen) (light emitting diodes) and form a 5 x 5 LED Screen.
|
||||
They can be set to on/off and the brightness can be controlled.
|
||||
|
||||
The red lights are [LEDs](/microbit/device/screen) (light emitting diodes) and form a 5 x 5 grid. They can be set to on/off and the brightness can be controlled.
|
||||
|
||||
### What is the yellow light on the back of the micro:bit?
|
||||
|
||||
It is the status LED. It flashes yellow when the system wants to tell the user that something has happened.
|
||||
The yellow light on the back of the micro:bit is the status LED.
|
||||
It flashes yellow when the system wants to tell the user that something has happened.
|
||||
|
||||
### Buttons
|
||||
|
||||
### What are the buttons for?
|
||||
Buttons A and B are a form of input. When you press a button, it completes an electrical circuit.
|
||||
The micro:bit can detect either of its two buttons being pressed and un-pressed and be programmed
|
||||
to act on that or send the information to another device.
|
||||
|
||||
Buttons A and B are a form of input. They detect when the button is being pressed. When you press one of the buttons, it completes an electrical circuit. The micro:bit can detect either of its two buttons being pressed and un-pressed and be programmed to act on that or send the information to another device.
|
||||
Button R on the back of the micro:bit is a system button. It has different uses.
|
||||
When you have downloaded and run your code onto your micro:bit, press Button R to restart and run your program from the beginning.
|
||||
|
||||
Button R on the back of the micro:bit is a system button. It has different uses. When you have downloaded and run your code onto your micro:bit, press Button R to restart and run your program from the beginning.
|
||||
|
||||
When you plug in your micro:bit, it should appear as MICROBIT. If you accidentally hold down the reset button as you’re plugging in your micro:bit, the micro:bit will appear as a MAINTENANCE drive instead of MICROBIT. This is known as maintenance mode.**
|
||||
When you plug in your micro:bit, it should appear as MICROBIT.
|
||||
If you accidentally hold down the reset button as you’re plugging in your micro:bit,
|
||||
the micro:bit will appear as a MAINTENANCE drive instead of MICROBIT. This is known as maintenance mode.**
|
||||
|
||||
To continue programming your micro:bit YOU MUST unplug your USB and reconnect it. Check that the drive now shows as MICROBIT.
|
||||
|
||||
**Use with caution. If you click on the drive while it shows as MAINTENANCE, you can see which version of firmware you have running on your micro:bit. Firmware on your micro:bit should be up-to-date already. You can find the version of firmware in the 'version.txt' file on the micro:bit. Further information on the firmware can be found here:
|
||||
**Use with caution. If you click on the drive while it shows as MAINTENANCE,
|
||||
you can see which version of firmware you have running on your micro:bit.
|
||||
Firmware on your micro:bit should be up-to-date already.
|
||||
You can find the version of firmware in the 'version.txt' file on the micro:bit. Further information on the firmware can be found here:
|
||||
|
||||
https://developer.mbed.org/platforms/Microbit/#firmware
|
||||
|
||||
### Compass
|
||||
|
||||
### Why is there a compass on the micro:bit?
|
||||
|
||||
The compass can detect magnetic fields such as the Earth’s magnetic field. As the micro:bit has this compass, it is possible to detect the direction it is moving in. The micro:bit can detect where it is facing and movement in degrees. This data can be used by the micro:bit in a program or be sent to another device.
|
||||
The compass can detect magnetic fields such as the Earth’s magnetic field.
|
||||
As the micro:bit has this compass, it is possible to detect the direction it is moving in.
|
||||
The micro:bit can detect where it is facing and movement in degrees.
|
||||
This data can be used by the micro:bit in a program or be sent to another device.
|
||||
|
||||
### Accelerometer
|
||||
|
||||
### Why is there an accelerometer on the micro:bit?
|
||||
There is a an accelerometer on your micro:bit which detects changes in the micro:bit’s speed.
|
||||
It converts analogue information into digital form that can be used in micro:bit programs.
|
||||
Output is in milli-g. The device will also detect a small number of standard actions e.g. shake, tilt and free-fall.
|
||||
|
||||
There is a an accelerometer on your micro:bit which detects changes in the micro:bit’s speed. It converts analogue information into digital form that can be used in micro:bit programs. Output is in milli-g. The device will also detect a small number of standard actions e.g. shake, tilt and free-fall.
|
||||
### Pins
|
||||
|
||||
### PINS
|
||||
|
||||
### What are the rings labelled 0, 1, 2 on the bottom edge of the micro:bit?
|
||||
|
||||
These are labels for the input/output pins P0, P1, P2, which you can attach external sensors to such as thermometers or moisture detectors. The pins can be a form of input or output. You can read more about large and small pins [here](/microbit/device/pins).
|
||||
The pins can be a form of input or output.
|
||||
There are labels for the input/output pins P0, P1, P2, which you can attach external sensors to such as thermometers or moisture detectors.
|
||||
You can read more about large and small pins [here](/microbit/device/pins).
|
||||
|
||||
### How do I connect the micro:bit to my computer?
|
||||
|
||||
It can be connected to your computer or device with a micro USB. Data can be sent and received between the micro:bit and the computer so programs can be downloaded from Windows and Macs onto the micro:bit via this USB data connection. You can read more information on how to run scripts on your micro:bit [here](/microbit/device/usb), and about the error messages you might get [here](/microbit/device/error-codes).
|
||||
Your micro:bit can be connected to your computer via a micro USB cable.
|
||||
Data can be sent and received between the micro:bit and the computer so programs
|
||||
can be downloaded from Windows, Macs and Chromebooks onto the micro:bit via this USB data connection.
|
||||
You can read more information on how to run scripts on your micro:bit [here](/microbit/device/usb),
|
||||
and about the error messages you might get [here](/microbit/device/error-codes).
|
||||
|
||||
### Batteries
|
||||
### Powering your micro:bit
|
||||
|
||||
### How do I power my micro:bit?
|
||||
When your micro:bit is connected to your computer with the micro USB, it doesn’t need another power source.
|
||||
When your micro:bit isn’t connected to your computer, tablet or mobile, you will need 2 x AAA 1.5 V batteries to power it.
|
||||
|
||||
When your micro:bit is connected to your computer with the micro USB, it doesn’t need another power source. When your micro:bit isn’t connected to your computer, tablet or mobile, you will need 2 x AAA 1.5 V batteries to power it.
|
||||
The pins labelled 3V and GND are the power supply pins.
|
||||
You can attach an external device such as a motor to these and power it using the battery or USB.
|
||||
|
||||
### 3V GND
|
||||
### Bluetooth Low Energy Antenna
|
||||
|
||||
### What are the rings labelled 3V and GND?
|
||||
|
||||
The pins labelled 3V and GND are the power supply pins. You can attach an external device such as a motor to these and power it using the battery or USB.
|
||||
|
||||
### What is a Bluetooth Low Energy Antenna?
|
||||
|
||||
You will see this labelled BLE ANNTENA on the back of your micro:bit. It is for a messaging service, built for the Internet of Things so that devices can talk to each other. The micro:bit is a peripheral device which can talk to a central device like a smart phone or tablet that has Bluetooth Low Energy (BLE). The micro:bit can send signals and receive signals from a central device so another BLE device can control the micro:bit or the micro:bit can control another BLE device.
|
||||
|
||||
### What is Bluetooth Low Energy?
|
||||
|
||||
Bluetooth wireless technology was developed as an alternative to data cables and allowed wireless communication between devices such as PCs, smartphones and tablets. Bluetooth® Smart or Bluetooth Low Energy is a power-friendly version of Bluetooth wireless technology.
|
||||
|
||||
### What is the Internet of Things?
|
||||
|
||||
The Internet of Things (IoT) was first talked about more than 15 years ago, when it was speculated that objects and people would be able to connect wirelessly over the internet. Objects can be detected and controlled remotely, allowing greater integration between the physical and computer based world. It will let you to remotely control your alarm system, thermostat or lights in your home. It has many applications in different fields including manufacturing, health and fitness, consumer electronics and the home.
|
||||
You will see the label BLE ANNTENA on the back of your micro:bit. It is for a messaging service,
|
||||
so that devices can talk to each other. The micro:bit is a peripheral
|
||||
device which can talk to a central device like a smart phone or tablet that has Bluetooth Low Energy (BLE).
|
||||
The micro:bit can send signals and receive signals from a central device so another BLE device can
|
||||
control the micro:bit or the micro:bit can control another BLE device.
|
||||
|
||||
### Technical Information
|
||||
|
||||
The micro:bit has been designed to be a bare-board micro controller for use by children aged 11-12. The device has been through extensive safety and compliance testing to the following standards:
|
||||
|
||||
### Safety
|
||||
|
||||
IEC 60950-1:2005 (Second Edition) + Am 1:2009 + Am 2:2013
|
||||
|
||||
### EMC
|
||||
|
||||
EN 55032: 2012
|
||||
|
||||
EN 55024: 2010
|
||||
|
||||
EN 55022:2010
|
||||
|
||||
EN 301 489-1 V1.9.2 (2011-09)
|
||||
|
||||
EN 301 489-17 V2.2.1 (2012-09)
|
||||
|
||||
### Radio Spectrum
|
||||
|
||||
ETSI EN 300 328 V1.9.1 (2015-02)
|
||||
|
||||
EN 62479:2010
|
||||
|
||||
### Chemical
|
||||
|
||||
Restriction of Hazardous Substances (RoHS) 2011/65/EU Annex II article 4(1)
|
||||
|
||||
EN71-3:2013 + A1:2014 - Migration of certain elements.
|
||||
|
||||
Analysis of the 163 substances of very high concern (SVHC) on the Candidate List for authorization, concerning Regulation (EC) No. 1907/2006 as published on the European Chemicals Agency (ECHA) website.
|
||||
|
||||

|
||||
|
||||
The micro:bit device features Bluetooth Low Energy radio. The radio on the device operates in the following frequencies:
|
||||
|
||||
Frequency Range: 2402MHz to 2480MHz
|
||||
|
||||
Bluetooth Version: V4.0 Bluetooth Low Energy
|
||||
|
||||
### Declaration of Conformity
|
||||
|
||||
The document can be downloaded by clicking here for the [Declaration of Conformity](https://microbit0.blob.core.windows.net/pub/hkeghjes/declaration-of-conformity.pdf)
|
||||
|
||||
The micro:bit has been designed to be a bare-board micro controller for use by children aged 11-12.
|
||||
More information is available at the [BBC web site](http://www.microbit.co.uk/device).
|
||||
|
BIN
docs/static/logo128.png
vendored
Normal file
BIN
docs/static/logo128.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
BIN
docs/static/logo32.png
vendored
Normal file
BIN
docs/static/logo32.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
BIN
docs/static/logo512.png
vendored
Normal file
BIN
docs/static/logo512.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 129 KiB |
18
docs/windows10.md
Normal file
18
docs/windows10.md
Normal file
@ -0,0 +1,18 @@
|
||||
# Windows 10 App
|
||||
|
||||
## Features
|
||||
|
||||
The Windows 10 App provides all the existing features of codemicrobit.com plus the following ones:
|
||||
|
||||
* **auto-upload**: the compiled .hex file is automatically deployed to all connected BBC micro:bits
|
||||
* **serial piping**: all serial data sent by connected BBC micro:bit is automatically imported and analyzed in the editor.
|
||||
|
||||
## Installing the pre-release app
|
||||
|
||||
The following instructions allow to side-load the Windows 10 app. This is required until the app is in the store.
|
||||
|
||||
* Search for “developer settings” in Windows 10 and put your computer in “Developer mode”.
|
||||
* Download https://pxt.io/codemicrobit.appx and unzip it. **DO NOT try to install from a zipped folder.**
|
||||
* Open the extracted folder, right-click on `Add-AppDevPackage.ps1` and click on `Run with PowerShell`. Follow the prompts…
|
||||
|
||||
4) In order to communicate with the micro:bit via serial, you need to install the [ARM mbed driver](https://developer.mbed.org/handbook/Windows-serial-configuration).
|
@ -18,4 +18,25 @@ namespace control {
|
||||
export function eventValue(id: EventBusValue) : number {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display specified error code and stop the program.
|
||||
*/
|
||||
//% shim=pxtrt::panic
|
||||
export function panic(code:number)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* If the condition is false, display msg on serial console, and panic with code 098.
|
||||
*/
|
||||
export function assert(condition:boolean, msg?: string)
|
||||
{
|
||||
if (!condition) {
|
||||
console.log("ASSERTION FAILED")
|
||||
if (msg != null)
|
||||
console.log(msg)
|
||||
panic(98)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,18 @@ namespace String_ {
|
||||
{
|
||||
return ManagedString::EmptyString.leakData();
|
||||
}
|
||||
|
||||
//%
|
||||
StringData *substr(StringData *s, int start, int length)
|
||||
{
|
||||
if (length <= 0)
|
||||
return mkEmpty();
|
||||
if (start < 0)
|
||||
start = max(s->len + start, 0);
|
||||
length = min(length, s->len - start);
|
||||
ManagedString x(s);
|
||||
return x.substring(start, length).leakData();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
181
libs/microbit/core.d.ts
vendored
181
libs/microbit/core.d.ts
vendored
@ -1,181 +0,0 @@
|
||||
/// <reference no-default-lib="true"/>
|
||||
|
||||
interface Array<T> {
|
||||
/**
|
||||
* Gets or sets the length of the array. This is a number one higher than the highest element defined in an array.
|
||||
*/
|
||||
//% shim=Array_::length
|
||||
length: number;
|
||||
|
||||
/**
|
||||
* Appends new elements to an array.
|
||||
* @param items New elements of the Array.
|
||||
*/
|
||||
//% shim=Array_::push
|
||||
push(item: T): void;
|
||||
|
||||
/**
|
||||
* Removes the last element from an array and returns it.
|
||||
*/
|
||||
//% helper=arrayPop
|
||||
pop(): T;
|
||||
|
||||
/**
|
||||
* Reverses the elements in an Array.
|
||||
*/
|
||||
//% helper=arrayReverse
|
||||
reverse(): void;
|
||||
|
||||
/**
|
||||
* Removes the first element from an array and returns it.
|
||||
*/
|
||||
//% helper=arrayShift
|
||||
shift(): T;
|
||||
|
||||
/**
|
||||
* Returns a section of an array.
|
||||
* @param start The beginning of the specified portion of the array.
|
||||
* @param end The end of the specified portion of the array.
|
||||
*/
|
||||
//% helper=arraySlice
|
||||
slice(start: number, end: number): T[];
|
||||
|
||||
/** Removes the first occurence of an object. Returns true if removed. */
|
||||
//% shim=Array_::removeElement
|
||||
removeElement(element:T) : boolean;
|
||||
|
||||
/** Removes the object at position index. */
|
||||
//% shim=Array_::removeAt
|
||||
removeAt(idx:number) : void;
|
||||
|
||||
|
||||
/**
|
||||
* Removes elements from an array.
|
||||
* @param start The zero-based location in the array from which to start removing elements.
|
||||
* @param deleteCount The number of elements to remove.
|
||||
*/
|
||||
//% helper=arraySplice
|
||||
splice(start: number, deleteCount: number): void;
|
||||
|
||||
/**
|
||||
* Inserts new elements at the start of an array.
|
||||
* @param items Elements to insert at the start of the Array.
|
||||
*/
|
||||
//% helper=arrayUnshift
|
||||
unshift(item:T): void;
|
||||
|
||||
/**
|
||||
* Returns the index of the first occurrence of a value in an array.
|
||||
* @param searchElement The value to locate in the array.
|
||||
* @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
|
||||
*/
|
||||
//% shim=Array_::indexOf
|
||||
indexOf(searchElement: T, fromIndex?: number): number;
|
||||
|
||||
|
||||
[n: number]: T;
|
||||
}
|
||||
|
||||
declare interface String {
|
||||
/**
|
||||
* Returns the character at the specified index.
|
||||
* @param pos The zero-based index of the desired character.
|
||||
*/
|
||||
//% shim=String_::charAt
|
||||
charAt(pos: number): string;
|
||||
|
||||
/**
|
||||
* Returns the Unicode value of the character at the specified location.
|
||||
* @param index The zero-based index of the desired character. If there is no character at the specified index, NaN is returned.
|
||||
*/
|
||||
//% shim=String_::charCodeAt
|
||||
charCodeAt(index: number): number;
|
||||
|
||||
/**
|
||||
* Returns a string that contains the concatenation of two or more strings.
|
||||
* @param other The string to append to the end of the string.
|
||||
*/
|
||||
//% shim=String_::concat
|
||||
concat(other: string): string;
|
||||
|
||||
/**
|
||||
* Determines whether relative order of two strings (in ASCII encoding).
|
||||
* @param that String to compare to target string
|
||||
*/
|
||||
//% shim=String_::compare
|
||||
compare(that: string): number;
|
||||
|
||||
/** Returns the length of a String object. */
|
||||
//% property shim=String_::length
|
||||
length: number;
|
||||
|
||||
[index: number]: string;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Converts A string to an integer.
|
||||
* @param s A string to convert into a number.
|
||||
*/
|
||||
//% shim=String_::toNumber
|
||||
declare function parseInt(s: string): number;
|
||||
|
||||
interface Object {}
|
||||
interface Function {}
|
||||
interface IArguments {}
|
||||
interface RegExp {}
|
||||
|
||||
|
||||
declare interface Boolean {
|
||||
/**
|
||||
* Returns a string representation of an object.
|
||||
*/
|
||||
//% shim=Boolean_::toString
|
||||
toString(): string;
|
||||
}
|
||||
|
||||
declare namespace String {
|
||||
|
||||
/**
|
||||
* Make a string from the given ASCII character code.
|
||||
*/
|
||||
//% shim=String_::fromCharCode
|
||||
function fromCharCode(code: number): string;
|
||||
}
|
||||
|
||||
|
||||
declare interface Number {
|
||||
/**
|
||||
* Returns a string representation of a number.
|
||||
*/
|
||||
//% shim=Number_::toString
|
||||
toString(): string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Numbers and arithmetic operators
|
||||
*/
|
||||
declare namespace Math {
|
||||
|
||||
/**
|
||||
* Returns the value of a base expression taken to a specified power.
|
||||
* @param x The base value of the expression.
|
||||
* @param y The exponent value of the expression.
|
||||
*/
|
||||
//% shim=Math_::pow
|
||||
function pow(x: number, y: number): number;
|
||||
|
||||
/**
|
||||
* Returns a pseudorandom number between 0 and `max`.
|
||||
*/
|
||||
//% shim=Math_::random
|
||||
function random(max: number): number;
|
||||
|
||||
/**
|
||||
* Returns the square root of a number.
|
||||
* @param x A numeric expression.
|
||||
*/
|
||||
//% shim=Math_::sqrt
|
||||
function sqrt(x: number): number;
|
||||
}
|
@ -25,6 +25,14 @@ namespace images {
|
||||
}
|
||||
|
||||
namespace ImageMethods {
|
||||
/**
|
||||
* Plots the image at a given column to the screen
|
||||
*/
|
||||
//% help=images/plot-image
|
||||
void plotImage(Image i, int xOffset = 0) {
|
||||
uBit.display.print(MicroBitImage(i), -xOffset, 0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows an frame from the image at offset ``x offset``.
|
||||
* @param xOffset TODO
|
||||
@ -35,6 +43,16 @@ namespace ImageMethods {
|
||||
uBit.display.print(MicroBitImage(i), -xOffset, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the ``index``-th frame of the image on the screen.
|
||||
* @param xOffset TODO
|
||||
*/
|
||||
//% help=images/plot-frame weight=80
|
||||
void plotFrame(Image i, int xOffset) {
|
||||
// TODO showImage() used in original implementation
|
||||
plotImage(i, xOffset * 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scrolls an image .
|
||||
* @param frameOffset x offset moved on each animation step, eg: 5, 1, -1
|
||||
@ -51,14 +69,6 @@ namespace ImageMethods {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Plots the image at a given column to the screen
|
||||
*/
|
||||
//% help=images/plot-image
|
||||
void plotImage(Image i, int xOffset = 0) {
|
||||
uBit.display.print(MicroBitImage(i), -xOffset, 0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets all pixels off.
|
||||
*/
|
||||
@ -85,4 +95,52 @@ namespace ImageMethods {
|
||||
if (pix < 0) return 0;
|
||||
return pix;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the width in columns
|
||||
*/
|
||||
//% help=functions/width
|
||||
int width(Image i) {
|
||||
return i->width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the height in rows (always 5)
|
||||
*/
|
||||
//% shim=
|
||||
int height(Image i) {
|
||||
return i->height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a pixel state at position ``(x,y)``
|
||||
* @param x TODO
|
||||
* @param y TODO
|
||||
* @param value TODO
|
||||
*/
|
||||
//% help=functions/set-pixel
|
||||
void setPixel(Image i, int x, int y, bool value) {
|
||||
setPixelBrightness(i, x, y, value ? 255 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pixel state at position ``(x,y)``
|
||||
* @param x TODO
|
||||
* @param y TODO
|
||||
*/
|
||||
//% help=functions/pixel
|
||||
bool pixel(Image i, int x, int y) {
|
||||
return pixelBrightness(i, x, y) > 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shows a particular frame of the image strip.
|
||||
* @param frame TODO
|
||||
*/
|
||||
//% weight=70 help=functions/show-frame
|
||||
void showFrame(Image i, int frame) {
|
||||
showImage(i, frame * 5);
|
||||
}
|
||||
}
|
||||
|
@ -36,10 +36,10 @@ enum Note {
|
||||
Eb4 = 311,
|
||||
E4 = 330,
|
||||
F4 = 349,
|
||||
//% block=F#3
|
||||
//% block=F#4
|
||||
FSharp4 = 370,
|
||||
G4 = 392,
|
||||
//% block=G#3
|
||||
//% block=G#4
|
||||
GSharp4 = 415,
|
||||
A4 = 440,
|
||||
Bb4 = 466,
|
||||
@ -134,8 +134,9 @@ namespace music {
|
||||
*/
|
||||
//% help=music/beat weight=49
|
||||
//% blockId=device_beat block="%fraction|beat"
|
||||
export function beat(fraction : BeatFraction = BeatFraction.Whole): number {
|
||||
export function beat(fraction?: BeatFraction): number {
|
||||
init();
|
||||
if (fraction == null) fraction = BeatFraction.Whole;
|
||||
let beat = 60000 / beatsPerMinute;
|
||||
if (fraction == BeatFraction.Whole) return beat;
|
||||
else if (fraction == BeatFraction.Half) return beat / 2;
|
||||
|
55
libs/microbit/shims.d.ts
vendored
55
libs/microbit/shims.d.ts
vendored
@ -24,6 +24,12 @@ declare namespace images {
|
||||
|
||||
|
||||
declare interface Image {
|
||||
/**
|
||||
* Plots the image at a given column to the screen
|
||||
*/
|
||||
//% help=images/plot-image xOffset.defl=0 shim=ImageMethods::plotImage
|
||||
plotImage(xOffset?: number): void;
|
||||
|
||||
/**
|
||||
* Shows an frame from the image at offset ``x offset``.
|
||||
* @param xOffset TODO
|
||||
@ -32,6 +38,13 @@ declare interface Image {
|
||||
//% BUGblockId=device_show_image_offset block="show image %sprite|at offset %offset" blockGap=8 xOffset.defl=0 shim=ImageMethods::showImage
|
||||
showImage(xOffset?: number): void;
|
||||
|
||||
/**
|
||||
* Draws the ``index``-th frame of the image on the screen.
|
||||
* @param xOffset TODO
|
||||
*/
|
||||
//% help=images/plot-frame weight=80 shim=ImageMethods::plotFrame
|
||||
plotFrame(xOffset: number): void;
|
||||
|
||||
/**
|
||||
* Scrolls an image .
|
||||
* @param frameOffset x offset moved on each animation step, eg: 5, 1, -1
|
||||
@ -41,12 +54,6 @@ declare interface Image {
|
||||
//% BUGblockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8 frameOffset.defl=0 interval.defl=200 shim=ImageMethods::scrollImage
|
||||
scrollImage(frameOffset?: number, interval?: number): void;
|
||||
|
||||
/**
|
||||
* Plots the image at a given column to the screen
|
||||
*/
|
||||
//% help=images/plot-image xOffset.defl=0 shim=ImageMethods::plotImage
|
||||
plotImage(xOffset?: number): void;
|
||||
|
||||
/**
|
||||
* Sets all pixels off.
|
||||
*/
|
||||
@ -64,6 +71,42 @@ declare interface Image {
|
||||
*/
|
||||
//% help= shim=ImageMethods::pixelBrightness
|
||||
pixelBrightness(x: number, y: number): number;
|
||||
|
||||
/**
|
||||
* Gets the width in columns
|
||||
*/
|
||||
//% help=functions/width shim=ImageMethods::width
|
||||
width(): number;
|
||||
|
||||
/**
|
||||
* Gets the height in rows (always 5)
|
||||
*/
|
||||
//% shim= shim=ImageMethods::height
|
||||
height(): number;
|
||||
|
||||
/**
|
||||
* Set a pixel state at position ``(x,y)``
|
||||
* @param x TODO
|
||||
* @param y TODO
|
||||
* @param value TODO
|
||||
*/
|
||||
//% help=functions/set-pixel shim=ImageMethods::setPixel
|
||||
setPixel(x: number, y: number, value: boolean): void;
|
||||
|
||||
/**
|
||||
* Get the pixel state at position ``(x,y)``
|
||||
* @param x TODO
|
||||
* @param y TODO
|
||||
*/
|
||||
//% help=functions/pixel shim=ImageMethods::pixel
|
||||
pixel(x: number, y: number): boolean;
|
||||
|
||||
/**
|
||||
* Shows a particular frame of the image strip.
|
||||
* @param frame TODO
|
||||
*/
|
||||
//% weight=70 help=functions/show-frame shim=ImageMethods::showFrame
|
||||
showFrame(frame: number): void;
|
||||
}
|
||||
|
||||
|
||||
|
@ -8,22 +8,20 @@ separately.
|
||||
|
||||
## Basic usage
|
||||
|
||||
```
|
||||
```blocks
|
||||
// Create a NeoPixel driver - specify the number of LEDs:
|
||||
let strip = neopixel.create(24)
|
||||
let strip = neopixel.create(DigitalPin.P0, 24)
|
||||
|
||||
// set pixel colors
|
||||
strip.setPix(0, 255, 255, 255) // white
|
||||
strip.setPix(1, 255, 0, 0) // red
|
||||
strip.setPix(2, 0, 255, 0) // green
|
||||
strip.setPix(3, 0, 0, 255) // blue
|
||||
strip.setPixelColor(0, 255, 255, 255) // white
|
||||
strip.setPixelColor(1, 255, 0, 0) // red
|
||||
strip.setPixelColor(2, 0, 255, 0) // green
|
||||
strip.setPixelColor(3, 0, 0, 255) // blue
|
||||
|
||||
// send the data to the strip
|
||||
strip.display()
|
||||
strip.show()
|
||||
```
|
||||
|
||||
Use `strip.setPin()` if your strip is not at `P0`.
|
||||
|
||||
Use `strip.setBrigthness()` to lower the brightness (it's maxed out by default).
|
||||
|
||||
Use `strip.shift()` or `strip.rotate()` to shift the lights around.
|
||||
@ -33,15 +31,15 @@ Use `strip.shift()` or `strip.rotate()` to shift the lights around.
|
||||
This little program will let the position of the microbit control the color of the first LED.
|
||||
This first LED will then get shifted further away every 100ms.
|
||||
|
||||
```
|
||||
let strip = neopixel.create(24)
|
||||
```blocks
|
||||
let strip = neopixel.create(DigitalPin.P0, 24)
|
||||
while (true) {
|
||||
let x = input.acceleration(Dimension.X) / 2
|
||||
let y = input.acceleration(Dimension.Y) / 2
|
||||
let z = input.acceleration(Dimension.Z) / 2
|
||||
strip.setPix(0, x, y, -z);
|
||||
strip.setPixelColor(0, x, y, -z);
|
||||
strip.shift(1);
|
||||
strip.display();
|
||||
strip.show();
|
||||
basic.pause(100);
|
||||
}
|
||||
```
|
||||
|
@ -1,88 +1,119 @@
|
||||
/**
|
||||
* Functions to operate NeoPixel strips.
|
||||
*/
|
||||
//% weight=5 color=#2699BF
|
||||
namespace neopixel {
|
||||
|
||||
//% shim=sendBufferAsm
|
||||
function sendBuffer(buf: Buffer, pin: DigitalPin) {
|
||||
}
|
||||
|
||||
class Strip {
|
||||
/**
|
||||
* A NeoPixel strip
|
||||
*/
|
||||
export class Strip {
|
||||
buf: Buffer;
|
||||
pin: DigitalPin;
|
||||
brightness: number;
|
||||
|
||||
length() {
|
||||
return this.buf.length / 3
|
||||
/**
|
||||
* Set give LED to a given color (range 0-255 for r, g, b)
|
||||
*/
|
||||
//% blockId="neopixel_set_pixel_color" block="%strip|set pixel color at %ledoff|red: %red|green: %green|blue: %blue" blockGap=8
|
||||
//% weight=80
|
||||
setPixelColor(ledoff: number, red: number, green: number, blue: number): void {
|
||||
ledoff = ledoff * 3;
|
||||
let br = this.brightness;
|
||||
if (br < 255) {
|
||||
red = (Math.clamp(0, 255, red) * br) >> 8;
|
||||
green = (Math.clamp(0, 255, blue) * br) >> 8;
|
||||
blue = (Math.clamp(0, 255, blue) * br) >> 8;
|
||||
}
|
||||
let buf = this.buf;
|
||||
buf[ledoff + 0] = Math.clamp(0, 255, green);
|
||||
buf[ledoff + 1] = Math.clamp(0, 255, red);
|
||||
buf[ledoff + 2] = Math.clamp(0, 255, blue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the brightness of the strip, 0-255.
|
||||
* Send all the changes to the strip.
|
||||
*/
|
||||
setBrigthness(brightness: number): void {
|
||||
this.brightness = brightness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the pin where the neopixel is connected, defaults to P0.
|
||||
*/
|
||||
setPin(pin: DigitalPin): void {
|
||||
this.pin = pin;
|
||||
pins.digitalWritePin(this.pin, 0)
|
||||
basic.pause(50)
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn off all LEDs.
|
||||
*/
|
||||
clear(): void {
|
||||
this.buf.fill(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shift LEDs forward.
|
||||
*/
|
||||
shift(off: number = 1): void {
|
||||
this.buf.shift(-off * 3)
|
||||
}
|
||||
|
||||
/**
|
||||
* Shift LEDs forward.
|
||||
*/
|
||||
rotate(): void {
|
||||
this.buf.rotate(-3)
|
||||
}
|
||||
|
||||
display() {
|
||||
//% blockId="neopixel_show" block="%strip|show" blockGap=8
|
||||
//% weight=79
|
||||
show() {
|
||||
basic.pause(1)
|
||||
sendBuffer(this.buf, this.pin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set give LED to a given color (range 0-255 for r, g, b)
|
||||
* Turn off all LEDs.
|
||||
*/
|
||||
setPix(ledoff: number, r: number, g: number, b: number): void {
|
||||
ledoff = ledoff * 3;
|
||||
let br = this.brightness;
|
||||
if (br < 255) {
|
||||
r = (Math.clamp(0, 255, r) * br) >> 8;
|
||||
g = (Math.clamp(0, 255, b) * br) >> 8;
|
||||
b = (Math.clamp(0, 255, b) * br) >> 8;
|
||||
}
|
||||
let buf = this.buf;
|
||||
buf[ledoff + 0] = Math.clamp(0, 255, g);
|
||||
buf[ledoff + 1] = Math.clamp(0, 255, r);
|
||||
buf[ledoff + 2] = Math.clamp(0, 255, b);
|
||||
//% blockId="neopixel_clear" block="%strip|clear"
|
||||
//% weight=76
|
||||
clear(): void {
|
||||
this.buf.fill(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of pixels declared on the strip
|
||||
*/
|
||||
//% blockId="neopixel_length" block="%strip|length" blockGap=8
|
||||
//% weight=60
|
||||
length() {
|
||||
return this.buf.length / 3
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the brightness of the strip, 0-255. eg: 255
|
||||
*/
|
||||
//% blockId="neopixel_set_brightness" block="%strip|set brightness %brightness" blockGap=8
|
||||
//% weight=59
|
||||
setBrigthness(brightness: number): void {
|
||||
this.brightness = brightness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shift LEDs forward and clear with zeros.
|
||||
* @params off number of pixels to shift forward, eg: 1
|
||||
*/
|
||||
//% blockId="neopixel_shift" block="%strip|shift pixels forward by %off" blockGap=8
|
||||
//% weight=40
|
||||
shift(off: number = 1): void {
|
||||
this.buf.shift(-off * 3)
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate LEDs forward.
|
||||
* @params off number of pixels to rotate forward, eg: 1
|
||||
*/
|
||||
//% blockId="neopixel_rotate" block="%strip|rotate pixels forward by %off" blockGap=8
|
||||
//% weight=39
|
||||
rotate(off:number = 1): void {
|
||||
this.buf.rotate(-off * 3)
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the pin where the neopixel is connected, defaults to P0.
|
||||
*/
|
||||
setPin(pin: DigitalPin): void {
|
||||
this.pin = pin;
|
||||
pins.digitalWritePin(this.pin, 0)
|
||||
basic.pause(50)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new NeoPixel driver for `numleds` LEDs.
|
||||
* @params pin the pin where the neopixel is connected.
|
||||
* @params numleds number of leds in the strip, eg: 24,30,60,64
|
||||
*/
|
||||
export function create(numleds: number): Strip {
|
||||
//% blockId="neopixel_create" block="neopixel create|at pin %pin|with %numleds leds"
|
||||
//% weight=90
|
||||
export function create(pin: DigitalPin, numleds: number): Strip {
|
||||
let strip = new Strip();
|
||||
strip.buf = pins.createBuffer(numleds * 3);
|
||||
strip.setBrigthness(255)
|
||||
strip.setPin(DigitalPin.P0)
|
||||
strip.setPin(pin)
|
||||
return strip;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
let strip = neopixel.create(24);
|
||||
let strip = neopixel.create(DigitalPin.P0, 24);
|
||||
let br = 100;
|
||||
strip.setBrigthness(100);
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
@ -39,9 +39,9 @@ while (true) {
|
||||
if (rotationMode) {
|
||||
strip.rotate();
|
||||
} else {
|
||||
strip.setPix(0, x, y, -z);
|
||||
strip.setPixelColor(0, x, y, -z);
|
||||
strip.shift(1);
|
||||
}
|
||||
strip.display();
|
||||
strip.show();
|
||||
basic.pause(100);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-microbit",
|
||||
"version": "0.2.49",
|
||||
"version": "0.2.63",
|
||||
"description": "BBC micro:bit target for PXT",
|
||||
"keywords": [
|
||||
"JavaScript",
|
||||
@ -29,6 +29,6 @@
|
||||
"typescript": "^1.8.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"pxt-core": "0.2.51"
|
||||
"pxt-core": "0.2.67"
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "microbit",
|
||||
"name": "code micro:bit",
|
||||
"title": "micro:bit",
|
||||
"title": "code micro:bit",
|
||||
"corepkg": "microbit",
|
||||
"bundleddirs": [
|
||||
"libs/microbit",
|
||||
@ -65,10 +65,11 @@
|
||||
},
|
||||
"serial": {
|
||||
"manufacturerFilter": "^mbed$",
|
||||
"nameFilter": "^mbed Serial Port",
|
||||
"log": true
|
||||
},
|
||||
"appTheme": {
|
||||
"logoUrl": "https://www.microbit.co.uk/",
|
||||
"logoUrl": "https://codemicrobit.com/about",
|
||||
"logo": "./static/logo.svg",
|
||||
"portraitLogo":"./static/portraitlogo.svg",
|
||||
"footerLogo": "./static/footerlogo.svg",
|
||||
|
@ -151,7 +151,7 @@ namespace pxsim.basic {
|
||||
if (interval < 0) return;
|
||||
|
||||
let leds = createImageFromString(x.toString());
|
||||
if (x < 0 || x >= 10) scrollImage(leds, interval, 1);
|
||||
if (x < 0 || x >= 10) ImageMethods.scrollImage(leds, interval, 1);
|
||||
else showLeds(leds, interval * 5);
|
||||
}
|
||||
|
||||
@ -163,7 +163,7 @@ namespace pxsim.basic {
|
||||
} else {
|
||||
let leds = createImageFromString(s);
|
||||
if (s.length == 1) showLeds(leds, interval * 5)
|
||||
else scrollImage(leds, interval, 1);
|
||||
else ImageMethods.scrollImage(leds, interval, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,32 +176,12 @@ namespace pxsim.basic {
|
||||
runtime.queueDisplayUpdate()
|
||||
}
|
||||
|
||||
function scrollImage(leds: Image, interval: number, stride: number): void {
|
||||
let cb = getResume()
|
||||
let off = stride > 0 ? 0 : leds.width - 1;
|
||||
let display = board().image;
|
||||
|
||||
board().animationQ.enqueue({
|
||||
interval: interval,
|
||||
frame: () => {
|
||||
if (off >= leds.width || off < 0) return false;
|
||||
stride > 0 ? display.shiftLeft(stride) : display.shiftRight(-stride);
|
||||
let c = Math.min(stride, leds.width - off);
|
||||
leds.copyTo(off, c, display, 5 - stride)
|
||||
off += stride;
|
||||
return true;
|
||||
},
|
||||
whenDone: cb
|
||||
})
|
||||
}
|
||||
|
||||
export function showAnimation(leds: Image, interval: number = 400): void {
|
||||
scrollImage(leds, interval, 5);
|
||||
ImageMethods.scrollImage(leds, interval, 5);
|
||||
}
|
||||
|
||||
export function plotLeds(leds: Image): void {
|
||||
leds.copyTo(0, 5, board().image, 0)
|
||||
runtime.queueDisplayUpdate()
|
||||
ImageMethods.plotImage(leds, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -305,6 +285,25 @@ namespace pxsim.input {
|
||||
default: return Math.floor(Math.sqrt(acc.instantaneousAccelerationSquared()));
|
||||
}
|
||||
}
|
||||
|
||||
export function rotation(kind : number) : number {
|
||||
let b = board();
|
||||
let acc = b.accelerometer;
|
||||
acc.activate();
|
||||
let x = acc.getX(MicroBitCoordinateSystem.NORTH_EAST_DOWN);
|
||||
let y = acc.getX(MicroBitCoordinateSystem.NORTH_EAST_DOWN);
|
||||
let z = acc.getX(MicroBitCoordinateSystem.NORTH_EAST_DOWN);
|
||||
|
||||
let roll = Math.atan2(y,z);
|
||||
let pitch = Math.atan(-x / (y*Math.sin(roll) + z*Math.cos(roll)));
|
||||
|
||||
let r = 0;
|
||||
switch(kind) {
|
||||
case 0: r = pitch; break;
|
||||
case 1: r = roll; break;
|
||||
}
|
||||
return Math.floor(r / Math.PI * 180);
|
||||
}
|
||||
|
||||
export function setAccelerometerRange(range: number) {
|
||||
let b = board();
|
||||
@ -365,6 +364,12 @@ namespace pxsim.led {
|
||||
board().displayMode = mode;
|
||||
runtime.queueDisplayUpdate()
|
||||
}
|
||||
|
||||
export function screenshot() : Image {
|
||||
let img = createImage(5)
|
||||
board().image.copyTo(0, 5, img, 0);
|
||||
return img;
|
||||
}
|
||||
}
|
||||
|
||||
namespace pxsim.serial {
|
||||
@ -516,5 +521,39 @@ namespace pxsim.ImageMethods {
|
||||
runtime.queueDisplayUpdate()
|
||||
}
|
||||
|
||||
// TODO ...
|
||||
export function plotImage(leds: Image, offset:number): void {
|
||||
leds.copyTo(offset, 5, board().image, 0)
|
||||
runtime.queueDisplayUpdate()
|
||||
}
|
||||
|
||||
export function clear(i: Image) {
|
||||
i.clear();
|
||||
}
|
||||
|
||||
export function setPixelBrightness(i:Image, x:number, y:number, b:number) {
|
||||
i.set(x,y,b);
|
||||
}
|
||||
|
||||
export function pixelBrightness(i:Image, x:number, y:number) : number {
|
||||
return i.get(x,y);
|
||||
}
|
||||
|
||||
export function scrollImage(leds: Image, interval: number, stride: number): void {
|
||||
let cb = getResume()
|
||||
let off = stride > 0 ? 0 : leds.width - 1;
|
||||
let display = board().image;
|
||||
|
||||
board().animationQ.enqueue({
|
||||
interval: interval,
|
||||
frame: () => {
|
||||
if (off >= leds.width || off < 0) return false;
|
||||
stride > 0 ? display.shiftLeft(stride) : display.shiftRight(-stride);
|
||||
let c = Math.min(stride, leds.width - off);
|
||||
leds.copyTo(off, c, display, 5 - stride)
|
||||
off += stride;
|
||||
return true;
|
||||
},
|
||||
whenDone: cb
|
||||
})
|
||||
}
|
||||
}
|
||||
|
9
sim/public/sim.manifest
Normal file
9
sim/public/sim.manifest
Normal file
@ -0,0 +1,9 @@
|
||||
CACHE MANIFEST
|
||||
|
||||
CACHE:
|
||||
/cdn/bluebird.min.js
|
||||
/cdn/pxtsim.js
|
||||
/sim/sim.js
|
||||
|
||||
NETWORK:
|
||||
*
|
@ -1,5 +1,5 @@
|
||||
<!doctype html>
|
||||
<html lang="en" data-framework="typescript">
|
||||
<html lang="en" data-manifest="" data-framework="typescript">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
|
@ -46,6 +46,18 @@ namespace pxsim.micro_bit {
|
||||
theme?: IBoardTheme;
|
||||
disableTilt?:boolean;
|
||||
}
|
||||
|
||||
const pointerEvents = !!(window as any).PointerEvent ? {
|
||||
up: "pointerup",
|
||||
down: "pointerdown",
|
||||
move: "pointermove",
|
||||
leave: "pointerleave"
|
||||
} : {
|
||||
up: "mouseup",
|
||||
down: "mousedown",
|
||||
move: "mousemove",
|
||||
leave: "mouseleave"
|
||||
};
|
||||
|
||||
export class MicrobitBoardSvg
|
||||
{
|
||||
@ -138,15 +150,15 @@ namespace pxsim.micro_bit {
|
||||
if (state.useShake && !this.shakeButton) {
|
||||
this.shakeButton = Svg.child(this.g, "circle", {cx:380, cy:100, r:16.5}) as SVGCircleElement;
|
||||
Svg.fill(this.shakeButton, this.props.theme.virtualButtonUp)
|
||||
this.shakeButton.addEventListener("mousedown", ev => {
|
||||
this.shakeButton.addEventListener(pointerEvents.down, ev => {
|
||||
let state = this.board;
|
||||
Svg.fill(this.shakeButton, this.props.theme.buttonDown);
|
||||
})
|
||||
this.shakeButton.addEventListener("mouseleave", ev => {
|
||||
this.shakeButton.addEventListener(pointerEvents.leave, ev => {
|
||||
let state = this.board;
|
||||
Svg.fill(this.shakeButton, this.props.theme.virtualButtonUp);
|
||||
})
|
||||
this.shakeButton.addEventListener("mouseup", ev => {
|
||||
this.shakeButton.addEventListener(pointerEvents.up, ev => {
|
||||
let state = this.board;
|
||||
Svg.fill(this.shakeButton, this.props.theme.virtualButtonUp);
|
||||
this.board.bus.queue(DAL.MICROBIT_ID_GESTURE, 11); // GESTURE_SHAKE
|
||||
@ -404,14 +416,14 @@ svg.sim.grayscale {
|
||||
}
|
||||
|
||||
.sim-text {
|
||||
font-family:monospace;
|
||||
font-family:"Lucida Console", Monaco, monospace;
|
||||
font-size:25px;
|
||||
fill:#fff;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.sim-text-pin {
|
||||
font-family:monospace;
|
||||
font-family:"Lucida Console", Monaco, monospace;
|
||||
font-size:20px;
|
||||
fill:#fff;
|
||||
pointer-events: none;
|
||||
@ -571,7 +583,7 @@ svg.sim.grayscale {
|
||||
}
|
||||
}
|
||||
let tiltDecayer = 0;
|
||||
this.element.addEventListener("mousemove", (ev: MouseEvent) => {
|
||||
this.element.addEventListener(pointerEvents.move, (ev: MouseEvent) => {
|
||||
let state = this.board;
|
||||
if (!state.accelerometer.isActive) return;
|
||||
|
||||
@ -591,7 +603,7 @@ svg.sim.grayscale {
|
||||
state.accelerometer.update(x,y,z);
|
||||
this.updateTilt();
|
||||
}, false);
|
||||
this.element.addEventListener("mouseleave", (ev: MouseEvent) => {
|
||||
this.element.addEventListener(pointerEvents.leave, (ev: MouseEvent) => {
|
||||
let state = this.board;
|
||||
if (!state.accelerometer.isActive) return;
|
||||
|
||||
@ -655,17 +667,17 @@ svg.sim.grayscale {
|
||||
});
|
||||
})
|
||||
this.pins.slice(0,3).forEach((btn, index) => {
|
||||
btn.addEventListener("mousedown", ev => {
|
||||
btn.addEventListener(pointerEvents.down, ev => {
|
||||
let state = this.board;
|
||||
state.pins[index].touched = true;
|
||||
this.updatePin(state.pins[index], index);
|
||||
})
|
||||
btn.addEventListener("mouseleave", ev => {
|
||||
btn.addEventListener(pointerEvents.leave, ev => {
|
||||
let state = this.board;
|
||||
state.pins[index].touched = false;
|
||||
this.updatePin(state.pins[index], index);
|
||||
})
|
||||
btn.addEventListener("mouseup", ev => {
|
||||
btn.addEventListener(pointerEvents.up, ev => {
|
||||
let state = this.board;
|
||||
state.pins[index].touched = false;
|
||||
this.updatePin(state.pins[index], index);
|
||||
@ -673,17 +685,17 @@ svg.sim.grayscale {
|
||||
})
|
||||
})
|
||||
this.buttonsOuter.slice(0,2).forEach((btn, index) => {
|
||||
btn.addEventListener("mousedown", ev => {
|
||||
btn.addEventListener(pointerEvents.down, ev => {
|
||||
let state = this.board;
|
||||
state.buttons[index].pressed = true;
|
||||
Svg.fill(this.buttons[index], this.props.theme.buttonDown);
|
||||
})
|
||||
btn.addEventListener("mouseleave", ev => {
|
||||
btn.addEventListener(pointerEvents.leave, ev => {
|
||||
let state = this.board;
|
||||
state.buttons[index].pressed = false;
|
||||
Svg.fill(this.buttons[index], this.props.theme.buttonUp);
|
||||
})
|
||||
btn.addEventListener("mouseup", ev => {
|
||||
btn.addEventListener(pointerEvents.up, ev => {
|
||||
let state = this.board;
|
||||
state.buttons[index].pressed = false;
|
||||
Svg.fill(this.buttons[index], this.props.theme.buttonUp);
|
||||
@ -691,7 +703,7 @@ svg.sim.grayscale {
|
||||
this.board.bus.queue(state.buttons[index].id, DAL.MICROBIT_BUTTON_EVT_CLICK);
|
||||
})
|
||||
})
|
||||
this.buttonsOuter[2].addEventListener("mousedown", ev => {
|
||||
this.buttonsOuter[2].addEventListener(pointerEvents.down, ev => {
|
||||
let state = this.board;
|
||||
state.buttons[0].pressed = true;
|
||||
state.buttons[1].pressed = true;
|
||||
@ -700,7 +712,7 @@ svg.sim.grayscale {
|
||||
Svg.fill(this.buttons[1], this.props.theme.buttonDown);
|
||||
Svg.fill(this.buttons[2], this.props.theme.buttonDown);
|
||||
})
|
||||
this.buttonsOuter[2].addEventListener("mouseleave", ev => {
|
||||
this.buttonsOuter[2].addEventListener(pointerEvents.leave, ev => {
|
||||
let state = this.board;
|
||||
state.buttons[0].pressed = false;
|
||||
state.buttons[1].pressed = false;
|
||||
@ -709,7 +721,7 @@ svg.sim.grayscale {
|
||||
Svg.fill(this.buttons[1], this.props.theme.buttonUp);
|
||||
Svg.fill(this.buttons[2], this.props.theme.virtualButtonUp);
|
||||
})
|
||||
this.buttonsOuter[2].addEventListener("mouseup", ev => {
|
||||
this.buttonsOuter[2].addEventListener(pointerEvents.up, ev => {
|
||||
let state = this.board;
|
||||
state.buttons[0].pressed = false;
|
||||
state.buttons[1].pressed = false;
|
||||
|
@ -618,12 +618,12 @@ namespace pxsim {
|
||||
this.data = data;
|
||||
}
|
||||
public get(x: number, y: number): number {
|
||||
// TODO range checking
|
||||
if (x < 0 || x >= this.width || y < 0 || y >= 5) return 0;
|
||||
return this.data[y * this.width + x];
|
||||
}
|
||||
public set(x: number, y: number, v: number) {
|
||||
// TODO range checking
|
||||
this.data[y * this.width + x] = v;
|
||||
if (x < 0 || x >= this.width || y < 0 || y >= 5) return;
|
||||
this.data[y * this.width + x] = Math.max(0, Math.min(255, v));
|
||||
}
|
||||
public copyTo(xSrcIndex: number, length: number, target: Image, xTargetIndex: number): void {
|
||||
for (let x = 0; x < length; x++) {
|
||||
|
17
webmanifest.json
Normal file
17
webmanifest.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"icons": [
|
||||
{
|
||||
"src": "https://az851932.vo.msecnd.net/pub/fpenpmjz",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png"
|
||||
}, {
|
||||
"src": "https://az851932.vo.msecnd.net/pub/vetoccmr",
|
||||
"sizes": "128x128",
|
||||
"type": "image/png"
|
||||
}, {
|
||||
"src": "https://az851932.vo.msecnd.net/pub/xiioeeyf",
|
||||
"sizes": "32x32",
|
||||
"type": "image/png"
|
||||
}
|
||||
]
|
||||
}
|
Binary file not shown.
@ -1 +1 @@
|
||||
MainPackage=C:\gh\pxt-microbit\win10\app\bin\Debug\codemicrobit_0.1.2.0_AnyCPU_Debug.appx
|
||||
MainPackage=C:\gh\pxt-microbit\win10\app\bin\Debug\codemicrobit_0.1.3.0_AnyCPU_Debug.appx
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp">
|
||||
<Identity Name="39122940-ab16-4cd4-a0ce-79a3eb863ecf" Version="0.1.2.0" Publisher="CN=jhalleux" />
|
||||
<Identity Name="39122940-ab16-4cd4-a0ce-79a3eb863ecf" Version="0.1.3.0" Publisher="CN=jhalleux" />
|
||||
<mp:PhoneIdentity PhoneProductId="39122940-ab16-4cd4-a0ce-79a3eb863ecf" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
|
||||
<Properties>
|
||||
<DisplayName>codemicrobitapp</DisplayName>
|
||||
@ -39,5 +39,11 @@
|
||||
<Capabilities>
|
||||
<Capability Name="internetClient" />
|
||||
<uap:Capability Name="removableStorage" />
|
||||
<DeviceCapability Name="bluetooth" />
|
||||
<DeviceCapability Name="serialcommunication">
|
||||
<Device Id="any">
|
||||
<Function Type="name:serialPort" />
|
||||
</Device>
|
||||
</DeviceCapability>
|
||||
</Capabilities>
|
||||
</Package>
|
Reference in New Issue
Block a user