Hello,
I have this struc containing different information (sensor acquisition mode, sensor location and raw values sent as an array of UInt8). I would like to compute certain properties from raw values depending on the acquisition mode.
I tried different things (mutating function, switch statement) unsucessfully... The switch-case seems to be the neater solution but I can't get it to work, I get a "expected declaration" error message.
Thanks !
enum Location {
case left, right, up, down
}
enum AcqMode {
case fast, full
}
struct SensorData {
var raw: [UInt8]
var pos: Location
var mode: AcqMode
init(raw: [UInt8], pos: Location, mode: AcqMode) {
self.raw = raw
self.pos = pos
self.mode = mode
}
switch mode {
case .fast:
var c1: UInt16 {
get {
return UInt16(raw[0]) * 256 + UInt16(raw[1])
}
}
var c2: UInt16 {
get {
return UInt16(raw[2]) * 256 + UInt16(raw[3])
}
}
var timeStamp: UInt16 {
get {
return UInt16(raw[4]) * 256 + UInt16(raw[5])
}
}
case .full:
var ind:[Int] {
get {
return [Int(raw[0]), Int(raw[1]), Int(raw[2]), Int(raw[3]), Int(raw[4]), Int(raw[5])]
}
}
var timeStamp: UInt16 {
get {
return UInt16(raw[6]) * 256 + UInt16(raw[7])
}
}
}
}