Skip to content

Commit

Permalink
Update documentation for new IO library.
Browse files Browse the repository at this point in the history
  • Loading branch information
floitsch committed Apr 9, 2024
1 parent 15d3dfc commit c55cd54
Show file tree
Hide file tree
Showing 52 changed files with 195 additions and 179 deletions.
2 changes: 1 addition & 1 deletion docs/language/syntax.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ equivalently:
Assignment operators are only allowed at the start of statements and
in the first clause of a `for`, `if`, or `while` statement.

<!-- HIDDEN CODE import reader show Reader -->
<!-- HIDDEN CODE import io show Reader -->
<!-- HIDDEN CODE my-function3 reader/Reader str/string: -->

```
Expand Down
12 changes: 3 additions & 9 deletions docs/peripherals/drivers/sparkfun_joystick.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,16 @@ The last 6 bits of the result are unused, but to keep the code simple we treat t
</Note>

```
import binary
import serial

class SparkFunJoystick:

// ...

read-position_ reg/int -> float:
value := registers_.read-u16-be reg
// Move from uint16 range to int16 range.
value -= binary.INT16-MAX
value := registers_.read-i16-be reg
// Perform floating-point division to get to [-1..1] range.
return value.to-float / binary.INT16-MAX
return value.to-float / int.MAX-16
```

<!-- HIDDEN CODE registers_/serial.Registers? := null -->
Expand Down Expand Up @@ -217,7 +214,6 @@ To improve responsibility, the sensor should be read at a higher frequency. Howe
<!-- CODE FILENAME driver.toit -->

```
import binary
import serial

class SparkFunJoystick:
Expand Down Expand Up @@ -259,10 +255,8 @@ class SparkFunJoystick:

read-position_ reg/int -> float:
value := registers_.read-u16-be reg
// Move from uint16 range to int16 range.
value -= binary.INT16-MAX
// Perform floating-point division to get to [-1..1] range.
return value.to-float / binary.INT16-MAX
return value.to-float / int.MAX-16
```

### The Toit application running on your device
Expand Down
24 changes: 14 additions & 10 deletions docs/tutorials/misc/ota.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ The paths are set up for a Linux system with the Toit SDK installed in
TOIT_SDK := /opt/toit-sdk
TOIT_COMPILE := $(TOIT_SDK)/bin/toit.compile
TOIT_FIRMWARE := $(TOIT_SDK)/tools/firmware
VERSION := v2.0.0-alpha.90
VERSION := $(shell $(TOIT_SDK)/bin/toit.lsp version)
ENVELOPE_URL := https://github.com/toitlang/toit/releases/download/$(VERSION)/firmware-esp32.gz

.PHONY: all
Expand All @@ -144,7 +144,7 @@ all: ota.bin
firmware.envelope: firmware.envelope.gz
gunzip -c firmware.envelope.gz > firmware.envelope

firmware.envelop.gz:
firmware.envelope.gz:
curl -L -o $@ $(ENVELOPE_URL)

%.snapshot: %.toit
Expand All @@ -154,9 +154,13 @@ ota.bin: validate.snapshot firmware.envelope
$(TOIT_FIRMWARE) -e firmware.envelope container install validate validate.snapshot
$(TOIT_FIRMWARE) -e firmware.envelope extract --format=binary -o ota.bin

.PHONY:
.PHONY: serve
serve: ota.bin
python3 -m http.server
python3 -m http.server 8000

.PHONY: version
version:
@echo $(VERSION)
```

## Serving the new firmware
Expand Down Expand Up @@ -188,14 +192,14 @@ desktop computer, as found in the previous step.
<!-- ANALYZE CODE -->
``` toit
import http
import io
import net
import system.firmware
import reader show Reader SizedReader

UPDATE-URL := "http://<YOUR_IP>:8000/ota.bin"

install-firmware reader/SizedReader -> none:
firmware-size := reader.size
install-firmware reader/io.Reader -> none:
firmware-size := reader.content-size
print "installing firmware with $firmware-size bytes"
written-size := 0
writer := firmware.FirmwareWriter 0 firmware-size
Expand All @@ -218,7 +222,7 @@ main:
client := http.Client network
try:
response := client.get --uri=UPDATE-URL
install-firmware (response.body as SizedReader)
install-firmware response.body
finally:
client.close
network.close
Expand All @@ -227,8 +231,8 @@ main:

Note that the program expects the server to return a `Content-Length`
header with the size of the firmware. Given this header, the
`body` field of the response will be a `SizedReader`, giving us access
to the size of the firmware. The program could also obtain the
`body` field of the response will have the `content-size` field set, giving
us access to the size of the firmware. The program could also obtain the
firmware size in other ways.

Flashing the firmware consists of three steps:
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/mqtt/qubitro.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ See the [packages](../../setup/packages) tutorial for details on how to
install packages.

``` shell
jag pkg install github.com/kasperl/[email protected].0
jag pkg install github.com/kasperl/[email protected]
```

<Note>
Expand Down
11 changes: 5 additions & 6 deletions docs/tutorials/network/http-file-server.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ serve-file request-path/string writer/http.ResponseWriter:
writer.headers.add "content_length" "$(file.size path)"
stream := file.Stream.for-read path
try:
while chunk := stream.read:
writer.write chunk
writer.out.write-from stream.in
finally:
stream.close
```
Expand All @@ -127,7 +126,7 @@ serve-directory request-path/string writer/http.ResponseWriter:
path := "./$request-path"
stream := directory.DirectoryStream path
writer.headers.add "content_type" "text/html"
writer.write """
writer.out.write """
<!DOCTYPE html>
<html>
<head>
Expand All @@ -145,19 +144,19 @@ serve-directory request-path/string writer/http.ResponseWriter:
prefix := request-path.trim --right "/"
entry-request-path := "$prefix/$entry"
if file.is-directory entry-path:
writer.write """
writer.out.write """
<div class="directory">
<a href="$entry-request-path">$entry/</a>
</div>
"""
else:
writer.write """
writer.out.write """
<div class="file">
<a href="$entry-request-path" download>$entry</a>
</div>
"""
stream.close
writer.write """
writer.out.write """
</body>
</html>
"""
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/network/http-server.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ main:
server.listen server-socket:: | request/http.RequestIncoming response-writer/http.ResponseWriter |
if request.path == "/" or request.path == "/index.html":
response-writer.headers.add "Content-Type" "text/html"
response-writer.write INDEX-HTML
response-writer.out.write INDEX-HTML
else if request.path == "/ws":
web-socket := server.web-socket request response-writer
clients.add web-socket
Expand Down
58 changes: 29 additions & 29 deletions tools/package.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sdk: ^2.0.0-alpha.121
sdk: ^2.0.0-alpha.144
prefixes:
bme280: bme280-driver
cellular: cellular
Expand Down Expand Up @@ -31,18 +31,18 @@ packages:
cellular:
url: github.com/toitware/cellular
name: cellular
version: 2.1.12
hash: ff46e15bbca3b41031b66778a2bc60937a82381a
version: 2.2.0
hash: 2f50148ed01e28ab2c3de09182b09f67ffcde776
mqtt:
url: github.com/toitware/mqtt
name: mqtt
version: 2.7.0
hash: ae42b7f4949ec65512e845e7bef7e90a33a914d9
version: 2.8.1
hash: 79c44885b4544257e1e2c94c9d1fb4c53e69fbbd
pkg-cli:
url: github.com/toitlang/pkg-cli
name: cli
version: 1.3.0
hash: 667d385441179dfe90c3427b8bc9ee252a948884
version: 1.8.0
hash: 73c8aabb60a6f5f304566a1e781d7b025aa17e9b
prefixes:
fs: pkg-fs
host: pkg-host
Expand All @@ -54,30 +54,30 @@ packages:
pkg-fs:
url: github.com/toitlang/pkg-fs
name: fs
version: 1.0.0
hash: c816c85022a155f37a4396455da9b27595050de1
version: 2.2.0
hash: 863280c5c62ac259d16d0d3b24df21209b461b14
prefixes:
host: pkg-host
pkg-host:
url: github.com/toitlang/pkg-host
name: host
version: 1.11.0
hash: 7e7df6ac70d98a02f232185add81a06cec0d77e8
version: 1.15.1
hash: ff187c2c19d695e66c3dc1d9c09b4dc6bec09088
pkg-http:
url: github.com/toitlang/pkg-http
name: http
version: 2.3.4
hash: 39fe52083b4c745cc37420649a48277b45728fd2
version: 2.7.1
hash: 54a5bb458d9fc9305e839b878e6de3b456f5c4a6
pkg-ntp:
url: github.com/toitlang/pkg-ntp
name: ntp
version: 1.0.0
hash: 1c3cc4a4819f459393f00efc576f66f838665719
version: 1.1.0
hash: e69bb1abc0d3d4aa7642eec3360e52744e4d011d
toit-1-wire:
url: github.com/toitware/toit-1-wire
name: one_wire
version: 2.1.1
hash: 54b96442d359b86bd5b8888ad07b9c9d38b82884
version: 2.2.0
hash: 8e15ea2315dc114824e6728a10e1260b4f388176
toit-artemis:
url: github.com/toitware/toit-artemis
name: artemis
Expand All @@ -96,15 +96,15 @@ packages:
toit-ds18b20:
url: github.com/toitware/toit-ds18b20
name: ds18b20
version: 2.0.0
hash: ff7e98673b8979278571020aa2beca563c108480
version: 2.1.0
hash: 09534f8f474d595620531df23b61e9707e1f5483
prefixes:
one_wire: toit-1-wire
toit-hc-sr04:
url: github.com/lask/toit-hc-sr04
name: hc_sr04
version: 2.1.0
hash: a3a90c8217da0c4637fafc095f7c759320978e8b
version: 2.1.1
hash: da8389adec9f012999c385b69bc42e26e19b51fa
toit-icons-pictogrammers:
url: github.com/toitware/toit-icons-pictogrammers
name: pictogrammers_icons
Expand All @@ -118,8 +118,8 @@ packages:
toit-pixel-display:
url: github.com/toitware/toit-pixel-display
name: pixel_display
version: 2.3.0
hash: 4a6f7c4c30152ec3c80b6cbe765133ce9015dab0
version: 2.8.0
hash: d7789ab67f6f0cde4e6df40b7aac88a56b871ca7
prefixes:
png-tools: toit-png-tools
toit-pixel-strip:
Expand Down Expand Up @@ -151,21 +151,21 @@ packages:
toit-supabase:
url: github.com/toitware/toit-supabase
name: supabase
version: 0.2.4
hash: 3dbfb8935f0128439258269b83fe9ca83a535db2
version: 0.2.8
hash: 168ddb448e71e91431e71121958c32aaf4c1ef02
prefixes:
host: pkg-host
http: pkg-http
toit-telegram:
url: github.com/floitsch/toit-telegram
name: telegram
version: 0.5.2
hash: 86f963b32a97f3d473d4261c19cb9af3f0354688
version: 0.5.3
hash: 438903d35f6eae1faa7573f5f51b4fa5db3b7dff
prefixes:
certificate_roots: toit-cert-roots
http: pkg-http
toit-watchdog:
url: github.com/toitware/toit-watchdog
name: watchdog
version: 1.2.0
hash: 61e70151f3623e60464e6bab8aa00825fd41f320
version: 1.4.0
hash: 3dccabf427af3a8ba3ef48429244ece0956fa684
26 changes: 13 additions & 13 deletions tools/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,49 @@ dependencies:
version: ^1.0.0
cellular:
url: github.com/toitware/cellular
version: ^2.1.12
version: ^2.2.0
certificate_roots:
url: github.com/toitware/toit-cert-roots
version: ^1.6.1
cli:
url: github.com/toitlang/pkg-cli
version: ^1.3.0
version: ^1.8.0
dhtxx:
url: github.com/toitware/toit-dhtxx
version: ^1.4.0
ds18b20:
url: github.com/toitware/toit-ds18b20
version: ^2.0.0
version: ^2.1.0
font_x11_adobe:
url: github.com/toitlang/pkg-font-x11-adobe
version: ^0.1.0
hc_sr04:
url: github.com/lask/toit-hc-sr04
version: ^2.1.0
version: ^2.1.1
host:
url: github.com/toitlang/pkg-host
version: ^1.11.0
version: ^1.15.1
http:
url: github.com/toitlang/pkg-http
version: ^2.3.4
version: ^2.7.1
morse:
url: github.com/toitware/toit-morse
version: ^1.0.6
mqtt:
url: github.com/toitware/mqtt
version: ^2.6.0
version: ^2.8.1
ntp:
url: github.com/toitlang/pkg-ntp
version: ^1.0.0
version: ^1.1.0
one_wire:
url: github.com/toitware/toit-1-wire
version: ^2.1.1
version: ^2.2.0
pictogrammers_icons:
url: github.com/toitware/toit-icons-pictogrammers
version: ^1.0.0
pixel_display:
url: github.com/toitware/toit-pixel-display
version: ^2.3.0
version: ^2.8.0
pixel_strip:
url: github.com/toitware/toit-pixel-strip
version: ^0.3.0
Expand All @@ -58,10 +58,10 @@ dependencies:
version: ^2.0.1
supabase:
url: github.com/toitware/toit-supabase
version: ^0.2.4
version: ^0.2.8
telegram:
url: github.com/floitsch/toit-telegram
version: ^0.5.2
version: ^0.5.3
watchdog:
url: github.com/toitware/toit-watchdog
version: ^1.2.0
version: ^1.4.0
Loading

0 comments on commit c55cd54

Please sign in to comment.