Slide 1

Slide 1 text

7Masters - Wearables Ezequiel França WatchShaker! ⌚

Slide 2

Slide 2 text

Mecatrônica @ SENAI Automação Industrial @ IFSP Analise de Sistemas @ FIAP Desenvolvedor iOS, Maker e open-source hacker. Ezequiel França

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Heurística?

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Let’s Shake

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

http://indiatoday.intoday.in/technology/story/apple-watch- handshakes-nfc-gestures/1/448093.html

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

lembrando rapidinho de protocolos delegates

Slide 15

Slide 15 text

protocol SomeProtocol { func someTypeMethod() }

Slide 16

Slide 16 text

protocol SomeProtocol { func someTypeMethod() } class SomeClass: SomeProtocol{ }

Slide 17

Slide 17 text

protocol WatchShakerDelegate { func watchShakerDidShake(_ watchShaker: WatchShaker) func watchShaker(_ watchShaker:WatchShaker, didFailWith error: Error) }

Slide 18

Slide 18 text

protocol WatchShakerDelegate { func didShake() func didFail(error: Error) }

Slide 19

Slide 19 text

protocol WatchShakerDelegate { func watchShakerDidShake(_ watchShaker: WatchShaker) func watchShaker(_ watchShaker:WatchShaker, didFailWith error: Error) }

Slide 20

Slide 20 text

class WatchShaker { public var delegate: WatchShakerDelegate? fileprivate var motionManager: CMMotionManager! fileprivate var lastShakeDate: Date? !// The threshold for how much acceleration needs to happen before an event will register. fileprivate var threshold:Double !// Time between shakes fileprivate var delay:Double = 0.1

Slide 21

Slide 21 text

init(shakeSensibility to:ShakeSensibility, delay time:Double) { self.threshold = to.rawValue self.delay = time self.motionManager = CMMotionManager() }

Slide 22

Slide 22 text

ShakeSensibility

Slide 23

Slide 23 text

enum ShakeSensibility: Double { case shakeSensibilitySoftest = 0.1 case shakeSensibilitySoft = 0.7 case shakeSensibilityNormal = 1.0 case shakeSensibilityHard = 1.2 case shakeSensibilityHardest = 2.0 }

Slide 24

Slide 24 text

public func start(delay accelerometerUpdateInterval:Double = 0.02) { guard motionManager.isAccelerometerAvailable else { return } motionManager.accelerometerUpdateInterval = accelerometerUpdateInterval let motionQueue = OperationQueue() motionManager.startAccelerometerUpdates(to: motionQueue) { (accelerometerData, err) -> Void in guard err == nil else { self.delegate?.watchShaker(self, didFailWith: err!) return }

Slide 25

Slide 25 text

guard let data = accelerometerData else { let e = NSError(domain: "No accelerometer data", code: 666, userInfo: ["No accelerometer data":"info"]) self.delegate?.watchShaker(self, didFailWith: e) return }

Slide 26

Slide 26 text

let valueX = fabs(data.acceleration.x) let valueY = fabs(data.acceleration.y) let maxValue = valueX > valueY ? valueX : valueY if maxValue > self.threshold { if let lastDate = self.lastShakeDate { if Date().compare(lastDate.addingTimeInterval(self.delay)) !== .orderedDescending { self.lastShakeDate = Date() self.delegate!?.watchShakerDidShake(self) } return } self.lastShakeDate = Date() self.delegate!?.watchShakerDidShake(self) }

Slide 27

Slide 27 text

:) @ezefranca http://ezefranca.com