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

//

import Foundation

open class WahooAdvancedFitnessMachineSerializer {
    public enum OpCode: UInt8 {

        
        public var currentTilt: Double? {
            if eventCode == .currentTiltChanged && bytes.count >= 2 {
                return decodeTilt(lsb: bytes[0], msb: bytes[1])
            }
            return nil
        }
        
        public var minimumTilt: Double? {
            if [EventCode.tiltLimitsAvailable, .tiltLimitsChanged].contains(eventCode) && bytes.count >= 2 {
                return decodeTilt(lsb: bytes[0], msb: bytes[1])
            }
            return nil
        }
        
        public var maximumTilt: Double? {
            if [EventCode.tiltLimitsAvailable, .tiltLimitsChanged].contains(eventCode) && bytes.count >= 4 {
                return decodeTilt(lsb: bytes[0], msb: bytes[1])
            }
            return nil
        }
