|
| 1 | +/// Micro:Bit stubs for Fable Python |
1 | 2 | module Fable.Python.MicroBit |
2 | 3 |
|
3 | 4 | open Fable.Core |
4 | 5 |
|
5 | | -/// Micro:Bit stubs for Fable Python |
| 6 | + |
| 7 | +[<Import("Image", "microbit")>] |
| 8 | +type Image (image: string) = |
| 9 | + /// Gets the number of columns in an image |
| 10 | + member _.width () : int = nativeOnly |
| 11 | + |
| 12 | + /// Gets the number of rows in an image |
| 13 | + member _.height () : int = nativeOnly |
| 14 | + |
| 15 | + /// Sets the brightness of a pixel at the given position Cannot be used on inbuilt images. |
| 16 | + member _.set_pixel(x: int, y: int, value: int) : unit = nativeOnly |
| 17 | + member _.get_pixel(x: int, y: int) : int = nativeOnly |
| 18 | + |
| 19 | + member _.shift_left(n: int) : unit = nativeOnly |
| 20 | + member _.shift_right(n: int) : unit = nativeOnly |
| 21 | + member _.shift_up(n: int) : unit = nativeOnly |
| 22 | + member _.shift_down(n: int) : unit = nativeOnly |
| 23 | + |
| 24 | + /// Return an exact copy of the image. |
| 25 | + member _.copy() : Image = nativeOnly |
| 26 | + /// Return a new image by inverting the brightness of the pixels in the source image. |
| 27 | + member _.invert() : Image = nativeOnly |
| 28 | + |
| 29 | + /// Return a new image by inverting the brightness of the pixels in the |
| 30 | + /// source image. Cannot be used on inbuilt images. |
| 31 | + member _.fill(value: int) : Image = nativeOnly |
| 32 | + |
| 33 | + static member HEART : Image = nativeOnly |
| 34 | + static member HEART_SMALL : Image = nativeOnly |
| 35 | + static member HAPPY : Image = nativeOnly |
| 36 | + static member SMILE : Image = nativeOnly |
| 37 | + static member SAD : Image = nativeOnly |
| 38 | + static member CONFUSED : Image = nativeOnly |
| 39 | + static member ANGRY : Image = nativeOnly |
| 40 | + static member ASLEEP : Image = nativeOnly |
| 41 | + static member SURPRISED : Image = nativeOnly |
| 42 | + static member SILLY : Image = nativeOnly |
| 43 | + static member FABULOUS : Image = nativeOnly |
| 44 | + static member MEH : Image = nativeOnly |
| 45 | + |
| 46 | + static member YES : Image = nativeOnly |
| 47 | + static member NO : Image = nativeOnly |
| 48 | + |
| 49 | + static member ALL_CLOCKS : Image array = nativeOnly |
| 50 | + static member ALL_ARROWS : Image array = nativeOnly |
| 51 | + |
6 | 52 | type IDisplay = |
7 | 53 | /// Clear the display. |
8 | 54 | abstract clear : unit -> unit |
9 | 55 |
|
| 56 | + /// Shows the image on the display |
| 57 | + abstract show : image: Image array * delay: int -> unit |
| 58 | + abstract show : image: Image -> unit |
| 59 | + abstract show : letter: char -> unit |
| 60 | + abstract show : number: int -> unit |
| 61 | + |
10 | 62 | /// Scrolls value horizontally on the display. If value is an integer or |
11 | 63 | /// float it is first converted to a string using str(). The delay |
12 | 64 | /// parameter controls how fast the text is scrolling. If wait is True, |
@@ -44,3 +96,47 @@ type IButton = |
44 | 96 |
|
45 | 97 | [<Import("button", "microbit")>] |
46 | 98 | let button: IButton = nativeOnly |
| 99 | + |
| 100 | +type ICompass = |
| 101 | + /// Starts the calibration process. An instructive message will be scrolled |
| 102 | + /// to the user after which they will need to rotate the device in order to |
| 103 | + /// draw a circle on the LED display. |
| 104 | + abstract calibrate : unit -> unit |
| 105 | + /// Gives the compass heading, calculated from the above readings, as an |
| 106 | + /// integer in the range from 0 to 360, representing the angle in degrees, |
| 107 | + /// clockwise, with north as 0. |
| 108 | + abstract heading : unit -> int |
| 109 | + |
| 110 | +[<Import("compass", "microbit")>] |
| 111 | +let compass : ICompass = nativeOnly |
| 112 | + |
| 113 | +type IAccelerometer = |
| 114 | + /// Get the acceleration measurement in the x axis, as a positive or |
| 115 | + /// negative integer, depending on the direction. The measurement is given |
| 116 | + /// in milli-g. By default the accelerometer is configured with a range of |
| 117 | + /// +/- 2g, and so this method will return within the range of +/- 2000mg. |
| 118 | + abstract get_x : unit -> int |
| 119 | + /// Get the acceleration measurement in the y axis, as a positive or |
| 120 | + /// negative integer, depending on the direction. The measurement is given |
| 121 | + /// in milli-g. By default the accelerometer is configured with a range of |
| 122 | + /// +/- 2g, and so this method will return within the range of +/- 2000mg. |
| 123 | + abstract get_y : unit -> int |
| 124 | + /// Get the acceleration measurement in the z axis, as a positive or |
| 125 | + /// negative integer, depending on the direction. The measurement is given |
| 126 | + /// in milli-g. By default the accelerometer is configured with a range of |
| 127 | + /// +/- 2g, and so this method will return within the range of +/- 2000mg. |
| 128 | + abstract get_z : unit -> int |
| 129 | + |
| 130 | + |
| 131 | +[<Import("accelerometer", "microbit")>] |
| 132 | +let accelerometer : IAccelerometer = nativeOnly |
| 133 | + |
| 134 | +[<Import("sleep", "microbit")>] |
| 135 | +///Wait for n milliseconds. One second is 1000 milliseconds". |
| 136 | +let sleep(milliseconds: int) = nativeOnly |
| 137 | + |
| 138 | + |
| 139 | +[<Import("temperature", "microbit")>] |
| 140 | +///Wait for n milliseconds. One second is 1000 milliseconds". |
| 141 | +let temperature() = nativeOnly |
| 142 | + |
0 commit comments