 //
 
 import Foundation
+
+func decodeTilt(lsb: UInt8, msb: UInt8) -> Double {
+    let unsignedValue = UInt16(msb) << 8 | UInt16(lsb)
+    let signedValue = Int16(bitPattern: unsignedValue)
+    return Double(signedValue) / 100
+}
 
 open class WahooAdvancedFitnessMachineSerializer {
     public enum OpCode: UInt8 {

    }
    
    public static func setTargetTilt(grade: Double) -> CommandPacket {
        let targetTilt = UInt16(grade * 100)
        let data = [
            UInt8(targetTilt & 0xFF),
            UInt8(targetTilt >> 8 & 0xFF)

        
        public var targetTilt: Double? {
            if eventCode == .targetTiltChanged && bytes.count >= 2 {
                return decodeTilt(lsb: bytes[0], msb: bytes[1])
            }
            return nil
        }
