Skip to content

Commit 7673b39

Browse files
committed
Add buzzer seqence message
1 parent 0534d2d commit 7673b39

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import ..protocol as protocol
2+
3+
class BuzzerSequence extends protocol.Data:
4+
static MT := 46
5+
static FREQUENCIES := 6
6+
static TIMINGS := 7
7+
8+
static doMsg frequencies/List timings/List -> protocol.Message:
9+
msg := protocol.Message MT
10+
msg.header.data.addDataUint8 protocol.Header.TYPE_MESSAGE_METHOD protocol.Header.METHOD_DO
11+
msg.data.addDataListFloat32 FREQUENCIES frequencies
12+
msg.data.addDataListUint16 TIMINGS timings
13+
return msg
14+
15+
constructor.fromData data/protocol.Data:
16+
super.fromData data
17+
18+
// frequencies -> List:
19+
// return getDataListFloat32 FREQUENCIES
20+
21+
// timings -> List<int>:
22+
// return getDataListUint16 TIMINGS
23+
24+
// stringify -> string:
25+
// return {
26+
// "Frequencies": frequencies,
27+
// "Timings": timings,
28+
// }.stringify

src/messages/messages.toit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import .m42-buzzer-control show BuzzerControl
1515
import .m43-battery-status show BatteryStatus
1616
import .m44-pressure show Pressure
1717
import .m45-alarm-control show AlarmControl
18+
import .m46-buzzer-sequence show BuzzerSequence
1819
import .m50-link-control show LinkControl
1920
import .m1004-lora show Lora
2021
import .m10008-preset-page show PresetPage

src/protocol/Data.toit

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ class Data:
228228
LITTLE-ENDIAN.put-uint32 b (i * 4) data[i]
229229
addData dataType b
230230

231+
addDataListFloat32 dataType/int data/List -> none:
232+
b := ByteArray data.size * 4
233+
for i := 0; i < data.size; i++:
234+
LITTLE-ENDIAN.put-float32 b (i * 4) data[i]
235+
addData dataType b
236+
231237
getDataListUint32 dataType/int -> List:
232238
data := getData dataType
233239
if data.size % 4 != 0:

src/services/httpmsg/msgs.toit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ sample-messages := {
3737
"200ms 1khz": (messages.BuzzerControl.doMsg --duration=200 --frequency=1.0 ).bytesForProtocol,
3838
"2s Ambulance": (messages.BuzzerControl.doMsg --duration=2000 --soundType=messages.BuzzerControl.SOUND_AMBULANCE --intensity=1 ).bytesForProtocol,
3939
},
40+
"$(messages.BuzzerSequence.MT) Buzzer Sequence": {
41+
"Starwars": (messages.BuzzerSequence.doMsg [0.440, 0.0, 0.440, 0.0, 0.440, 0.0, 0.349, 0.0, 0.523, 0.0, 0.440, 0.0, 0.349, 0.0, 0.523, 0.0, 0.440, 0.0, 0.659, 0.0, 0.659, 0.0, 0.659, 0.0, 0.698, 0.0, 0.523, 0.0, 0.415, 0.0, 0.349, 0.0, 0.523, 0.0, 0.440] [400, 50, 400, 50, 400, 50, 300, 50, 100, 50, 400, 50, 300, 50, 100, 50, 800, 50, 400, 50, 400, 50, 400, 50, 300, 50, 100, 50, 400, 50, 300, 50, 100, 50, 800]).bytesForProtocol,
42+
// "Nokia_Tune": (messages.BuzzerSequence.doMsg [ 1.318, 0.0, 1.174, 0.0, 1.480, 0.0, 1.662, 0.0, 1.108, 0.0, 0.988, 0.0, 1.174, 0.0, 1.318, 0.0, 0.988, 0.0, 0.880, 0.0, 1.108, 0.0, 1.318, 0.0, 0.880 ] [75, 50, 75, 50, 150, 50, 150, 50, 75, 50, 75, 50, 150, 50, 150, 50, 75, 50, 75, 50, 150, 50, 150, 50, 500]).bytesForProtocol,
43+
},
4044
"$(messages.AlarmControl.MT) Alarm": {
4145
"Duration 0": (messages.AlarmControl.doMsg --duration=0).bytesForProtocol,
4246
"3s pattern 4 intensity 1": (messages.AlarmControl.doMsg --duration=3 --buzzerPattern=4 --buzzerIntensity=1).bytesForProtocol,

0 commit comments

Comments
 (0)