File tree Expand file tree Collapse file tree 7 files changed +511
-31
lines changed Expand file tree Collapse file tree 7 files changed +511
-31
lines changed Original file line number Diff line number Diff line change 1+ open System.IO
12open Fake.Core
23open Fake.IO
34
@@ -6,27 +7,39 @@ open Helpers
67initializeContext()
78
89let srcPath = Path.getFullName " src"
10+ let appName = " app.py"
911
1012Target.create " Clean" ( fun _ ->
1113 run dotnet " fable-py clean --yes" srcPath // Delete *.py files created by Fable
1214)
1315
1416Target.create " Build" ( fun _ ->
1517 run dotnet $" fable-py -c Release" srcPath
18+
19+ // Rewrite imports to flat file system.
20+ let python = File.ReadAllText( $" {srcPath}/{appName}" )
21+ let python = python.Replace( " fable_modules.fable_library." , " " )
22+ File.WriteAllText( $" {srcPath}/{appName}" , python)
1623)
1724
1825Target.create " Flash" ( fun _ ->
19- run flash " " $" {srcPath}/app.py"
26+ run flash appName srcPath
27+ )
28+
29+ Target.create " FableLibrary" ( fun _ ->
30+ run ufs $" put util.py" srcPath
2031)
2132
2233open Fake.Core .TargetOperators
2334
2435let dependencies = [
2536 " Clean"
2637 ==> " Build"
27-
2838 " Clean"
39+ ==> " Build"
2940 ==> " Flash"
41+ " Clean"
42+ ==> " FableLibrary"
3043]
3144
3245[<EntryPoint>]
Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ let createProcess exe arg dir =
7373
7474let dotnet = createProcess " dotnet"
7575let flash = createProcess " uflash"
76+ let ufs = createProcess " ufs"
7677
7778let npm =
7879 let npmPath =
Original file line number Diff line number Diff line change 22
33Write your F# program in ` src/App.fs ` .
44
5+ Note that the Fable Library is not supported so it's very limited what
6+ you can do. The needed parts of fable library need to be ported to work
7+ with MicroPython see ` util.fs ` as an example.
8+
9+ The micro: bit have a flat file-system so all files needs to be in the
10+ same top-level directory.
11+
512## Install
613
14+ These tools are needed by the Build script:
15+
716``` sh
817pip install uflash
18+ pip install microfs
919```
1020
1121## Build
Original file line number Diff line number Diff line change @@ -2,4 +2,31 @@ module App
22
33open Fable.Python .MicroBit
44
5- display.scroll ( " Fable Python!" ) |> ignore
5+ //display.scroll ("Fable Python!") |> ignore
6+
7+ let mutable time = 0
8+ let mutable start = 0
9+ let mutable running = false
10+
11+ while true do
12+ if running then
13+ display.show ( Image.HEART)
14+ sleep ( 300 )
15+ display.show ( Image.HEART_ SMALL)
16+ sleep ( 300 )
17+ else
18+ display.show ( Image.ASLEEP)
19+
20+ if button_ a.was_ pressed () then
21+ running <- true
22+ start <- running_ time ()
23+
24+ if button_ b.was_ pressed () then
25+ if running then
26+ time <- time + running_ time () - start
27+
28+ running <- false
29+
30+ if pin_ logo.is_ touched () then
31+ if not running then
32+ display.scroll ( int ( time / 1000 ))
You can’t perform that action at this time.
0 commit comments