Skip to content

Commit ed31507

Browse files
committed
Allow easier centerPoint retrieval from messages
Otherwise the caller would have to check the length of a list of coordinates nd then use the first..
1 parent fb431b0 commit ed31507

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/lightbug.toit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ import .messages
44
import .services
55
import .util.docs
66

7+
import coordinate show Coordinate
8+
79
export *

src/protocol/data.toit

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,13 @@ class Data:
233233
l.add [LITTLE-ENDIAN.int32 data i, LITTLE-ENDIAN.int32 data (i + 4)]
234234
return l
235235

236+
get-data-coordinate dataType/int -> Coordinate:
237+
data := get-data dataType
238+
if data.size != 8:
239+
log.error "Data size not 8 for datatype $(dataType)"
240+
return Coordinate 0.0 0.0 // TOOD consider all getts returning null on error, not a 0 value...
241+
return Coordinate ((LITTLE-ENDIAN.int32 data 0) / 1e7) ((LITTLE-ENDIAN.int32 data 4) / 1e7)
242+
236243
get-data-list-coordinates dataType/int -> List:
237244
data := get-data dataType
238245
if data.size % 8 != 0:

0 commit comments

Comments
 (0)