Skip to content

Commit 30361f6

Browse files
committed
Add temperature-indicator-advanced example for concolic
1 parent 7c67eb6 commit 30361f6

4 files changed

Lines changed: 50 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build:
2+
asc temp.ts -o upload.wasm --disable mutable-globals --disable sign-extension --disable nontrapping-f2i --disable bulk-memory --sourceMap
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
@external("env", "chip_analog_read") declare function chip_analog_read(pin: i32): i32;
2+
@external("env", "chip_digital_write") declare function chip_digital_write(pin: i32, value: i32): void;
3+
@external("env", "chip_pin_mode") declare function chip_pin_mode(pin: i32, mode: i32): void;
4+
5+
enum Pin {
6+
Red = 15,
7+
Orange = 16,
8+
Green = 17,
9+
Sensor = 12
10+
}
11+
12+
enum PinMode {
13+
Input = 0,
14+
Output = 2
15+
}
16+
17+
const highThreshold = 70;
18+
const warningThreshold = 50;
19+
20+
function readTemp(pin: Pin): i32 {
21+
return (chip_analog_read(Pin.Sensor) * 488 - 50000) / 1000;
22+
}
23+
24+
function setColor(pin: Pin): void {
25+
chip_digital_write(Pin.Orange, pin == Pin.Orange);
26+
chip_digital_write(Pin.Red, pin == Pin.Red);
27+
chip_digital_write(Pin.Green, pin == Pin.Green);
28+
}
29+
30+
export function main(): void {
31+
chip_pin_mode(Pin.Sensor, PinMode.Input);
32+
chip_pin_mode(Pin.Red, PinMode.Output);
33+
chip_pin_mode(Pin.Orange, PinMode.Output);
34+
chip_pin_mode(Pin.Green, PinMode.Output);
35+
36+
while (true) {
37+
if (readTemp(Pin.Sensor) > highThreshold) {
38+
setColor(Pin.Red);
39+
}
40+
else if(readTemp(Pin.Sensor) > warningThreshold) {
41+
setColor(Pin.Orange);
42+
}
43+
else {
44+
setColor(Pin.Green);
45+
}
46+
}
47+
}
375 Bytes
Binary file not shown.

examples/temperature-indicator-advanced/upload.wasm.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)