Skip to content

Peripheral Setup from the Central

Rob Reuss edited this page Dec 20, 2015 · 3 revisions

What Is It?

Peripheral Setup allows for configuration of the Peripheral from the Central. The primary use case is the creation of a single, generic Peripheral (software-based controller) that can work with multiple games by the Central sending configuration information to the Peripheral.

####Preliminary Design Currently, a very basic set of properties are supported. If you require additional properties, please let us know at [email protected].

####How to implement

Shortly after calling startAs on the Central, use the following syntax to send a Peripheral Setup message to the Peripheral:

VgcManager.peripheralSetup = VgcPeripheralSetup()

// Turn on motion from the Central
VgcManager.peripheralSetup.motionActive = false

VgcManager.peripheralSetup.backgroundColor = UIColor.blueColor()

VgcManager.peripheralSetup.enableMotionAttitude = true
VgcManager.peripheralSetup.enableMotionGravity = true
VgcManager.peripheralSetup.enableMotionUserAcceleration = false
VgcManager.peripheralSetup.enableMotionRotationRate = false

VgcManager.peripheralSetup.sendToController(controller)

To detect the reciept of Peripheral Setup information on the Peripheral, observe for the following notification:

NSNotificationCenter.defaultCenter().addObserver(self, selector: "receivedPeripheralSetup:", name: VgcPeripheralSetupNotification, object: nil)

Here is an example from the iOS Peripheral sample project of handling an incoming PeripheralSetup object:

@objc func receivedPeripheralSetup(notification: NSNotification) {
  
    if VgcManager.peripheralSetup.motionActive {
        VgcManager.peripheral.motion.start()
    } else {
        VgcManager.peripheral.motion.stop()
    }
    
    VgcManager.peripheral.motion.enableUserAcceleration = VgcManager.peripheralSetup.enableMotionUserAcceleration
    VgcManager.peripheral.motion.enableGravity = VgcManager.peripheralSetup.enableMotionGravity
    VgcManager.peripheral.motion.enableRotationRate = VgcManager.peripheralSetup.enableMotionRotationRate
    VgcManager.peripheral.motion.enableAttitude = VgcManager.peripheralSetup.enableMotionAttitude
    
    VgcManager.peripheral.deviceInfo.profileType = VgcManager.peripheralSetup.profileType
    print(VgcManager.peripheralSetup)
    for view in peripheralControlPadView.parentView.subviews {
        view.removeFromSuperview()
    }
    peripheralControlPadView = PeripheralControlPadView(vc: self)
    peripheralControlPadView.controlOverlay.frame = CGRect(x: 0, y: -peripheralControlPadView.parentView.bounds.size.height, width: peripheralControlPadView.parentView.bounds.size.width, height: peripheralControlPadView.parentView.bounds.size.height)

    peripheralControlPadView.parentView.backgroundColor = VgcManager.peripheralSetup.backgroundColor
}