Upgrade to Pro — share decks privately, control downloads, hide ads and more …

struct Drift: Bicycle, Swift

struct Drift: Bicycle, Swift

台灣城市單車聯盟 https://tuba.org.tw

Yung-Luen Lan

October 21, 2018
Tweet

More Decks by Yung-Luen Lan

Other Decks in Programming

Transcript

  1. struct Drift: Bicycle, Swift { let author = Yllan() let

    outline = [ Motivation(), Hacking(), Demo(), ] }
  2. let motionManager = CMMotionManager() motionManager.deviceMotionUpdateInterval = 1.0 / 60.0 motionManager.startDeviceMotionUpdates(to:

    OperationQueue.main) { (motion, error) in if let motion = motion { print(motion.gravity.x) print(motion.gravity.y) print(motion.gravity.z) } } x y Z
  3. let server = NWEndpoint.service(name: "yllan", type: "_bicycle._tcp", domain: "local", interface:

    nil) let connection = NWConnection(to: server, using: .tcp) connection.stateUpdateHandler = { (newState) in switch newState { case .ready: // can send data break default: // error, waiting, disconnected break } } connection.start(queue: q) let listener = try NWListener(using: .tcp) listener.service = NWListener.Service(name: "yllan", type: "_bicycle._tcp") listener.newConnectionHandler = { (newConnection) in newConnection.stateUpdateHandler = { (newState) in switch newState { case .ready: // can read break default: break } } newConnection.start(queue: q) } listener.start(queue: q)
  4. • 中華電信 MOD 送的 AP 太爛? • 減⼩小 Packet Size

    • 設定 serviceClass • 改⽤用 UDP • 關閉藍藍牙
  5. • CoreLocation • CLHeading • CoreMotion • Magneto Meter •

    CMMagnetoMeterData • Device Motion • CMCalibratedMagneticField