ButtonPressCarelinkMessageBody.swift 660 B

1234567891011121314151617181920212223242526272829
  1. //
  2. // ButtonPressCarelinkMessageBody.swift
  3. // RileyLink
  4. //
  5. // Created by Pete Schwamb on 3/12/16.
  6. // Copyright © 2016 Pete Schwamb. All rights reserved.
  7. //
  8. import Foundation
  9. public class ButtonPressCarelinkMessageBody: CarelinkLongMessageBody {
  10. public enum ButtonType: UInt8 {
  11. case act = 0x02
  12. case esc = 0x01
  13. case down = 0x04
  14. case up = 0x03
  15. case easy = 0x00
  16. }
  17. public convenience init(buttonType: ButtonType) {
  18. let numArgs = 1
  19. let data = Data(hexadecimalString: String(format: "%02x%02x", numArgs, buttonType.rawValue))!
  20. self.init(rxData: data)!
  21. }
  22. }