-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
69 lines (69 loc) · 1.77 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
enum RadioMessage {
message1 = 49434
}
/**
* Pulse Input on P0
*/
/**
* Dialing input on P1
*/
/**
* Telephone hook on P3
*/
pins.onPulsed(DigitalPin.P0, PulseValue.Low, function () {
if (control.millis() - lastPulse > 60) {
send("phone/onPulse " + pulses, 5)
led.plot(0, 0)
if (pulses < 9) {
pulses += 1
} else {
pulses = 0
}
lastPulse = control.millis()
}
})
pins.onPulsed(DigitalPin.P1, PulseValue.High, function () {
if (control.millis() - lastDialstart > 300) {
send("phone/onStartDial", 5)
basic.clearScreen()
pulses = 0
led.plot(4, 0)
lastDialstart = control.millis()
}
})
pins.onPulsed(DigitalPin.P3, PulseValue.Low, function () {
send("phone/onHang false ", 10)
})
function send (message: string, repeat: number) {
serial.writeLine(message)
for (let index = 0; index < repeat; index++) {
radio.sendString(message)
}
}
pins.onPulsed(DigitalPin.P1, PulseValue.Low, function () {
if (pins.digitalReadPin(DigitalPin.P1) == 1) {
send("phone/onDialed " + pulses, 40)
led.unplot(4, 0)
basic.showNumber(pulses)
}
})
pins.onPulsed(DigitalPin.P0, PulseValue.High, function () {
led.unplot(0, 0)
})
pins.onPulsed(DigitalPin.P3, PulseValue.High, function () {
send("phone/onHang true", 10)
})
let lastPulse = 0
let lastDialstart = 0
let pulses = 0
radio.setTransmitPower(7)
radio.setGroup(1)
radio.setFrequencyBand(70)
pins.setPull(DigitalPin.P0, PinPullMode.PullUp)
pins.setPull(DigitalPin.P1, PinPullMode.PullUp)
pins.setPull(DigitalPin.P3, PinPullMode.PullUp)
basic.showNumber(pulses)
lastDialstart = 0
loops.everyInterval(1200000, function () {
send("phone/vcc " + pins.analogReadPinInternalRef(), 1)
})