Giter VIP home page Giter VIP logo

unitycorebluetooth's Introduction

UnityCoreBluetooth

Platform Unity Xode

Example: Get Raw Value from Daydream Controller

daydream

Installation

Features

  • Peripheral
    • Get name
    • Search services
  • Service
    • Get uuid
    • Search characteristics
  • Characteristic
    • Get uuid
    • Get properties
    • Write value
    • Read value
    • Receive notify

Usage

Example (Get Raw Value from Daydream Controller)

About Daydream Controller

  • Get raw value form Daydream controller
Property Target
Peripheral Name Daydream controller
Service UUID FE55
Characteristic Usage notify

1. Get CoreBluetoothManager instance

  • Get shared CoreBluetoothManager instance.
manager = CoreBluetoothManager.Shared;

2. Start Scan On PowerOn

manager.OnUpdateState((string state) =>
{
    Debug.Log("state: " + state);
    if (state != "poweredOn") return;
    manager.StartScan();
});

3. Discover And Connect Daydream Controller

manager.OnDiscoverPeripheral((CoreBluetoothPeripheral peripheral) =>
{
    if (peripheral.name != "")
        Debug.Log("discover peripheral name: " + peripheral.name);
    if (peripheral.name != "Daydream controller") return;

    manager.StopScan();
    manager.ConnectToPeripheral(peripheral);
});

4. Discover Services And Characteristic On Connected

manager.OnConnectPeripheral((CoreBluetoothPeripheral peripheral) =>
{
    Debug.Log("connected peripheral name: " + peripheral.name);
    peripheral.discoverServices();
});

manager.OnDiscoverService((CoreBluetoothService service) =>
{
    Debug.Log("discover service uuid: " + service.uuid);
    if (service.uuid != "FE55") return;
    service.discoverCharacteristics();
});

5. Enable Notify

manager.OnDiscoverCharacteristic((CoreBluetoothCharacteristic characteristic) =>
{
    string uuid = characteristic.uuid;
    string usage = characteristic.propertis[0];
    Debug.Log("discover characteristic uuid: " + uuid + ", usage: " + usage);
    if (usage != "notify") return;
    characteristic.setNotifyValue(true);
});

6. Handle Notify Value

manager.OnUpdateValue((CoreBluetoothCharacteristic characteristic, byte[] data) =>
{
    this.value = data;
    this.flag = true;
});

7. Start CoreBluetoothManager

manager.Start();

8. Write Value

byte[] value = { 0x64, 0x68 };
characteristic.Write(value);

Examples

  • Example for Unity
  • Unity Version: 2020.3.5
  • Work on Unity Editor And iOS device
  • Show raw value from Daydream controller or M5StickC
  • Peripheral Example for M5StickC (Plus)
  • Support write and notify

NativeExamples

  • Native Examample for iOS
  • Show raw value from Daydream controller
  • Native Examample for macOS
  • Show raw value from Daydream controller

unitycorebluetooth's People

Contributors

fuziki avatar rimzici avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.