Gestures and The Gesture Mode

A gesture is the path of the movement of a Ring device.
The SDK compares the path of the movement and registered gesture data to recognize what the user has drawn.

About Points String

A gesture will be encoded into a String like this:

Currently, you can register predefined gestures in CRCommon.h. þǫ0þǫ is the list of predefined gestures.
We are now planning to release a function to support define your own gestures.

Display the path of a gesture

You can get a UIImage object which represents the path of a gesture via the imageWithPoints function defined in the CRCommon class.

Arguments

Here is an example.

Prepare for Using Gestures

Before using gestures, you must prepare some gestures which you want to be recognized to the SDK to enable gesture recognition.
The preparation is divided into two steps:

Installing gestures

The installGestures:error: function defined in the CRApplication class installs gestures to the SDK.

installGestures:error:

installedGestureIdentifiers

This function will return an array which contains IDs of installed gestures, or nil if no gesture is installed.

Assigning Recognizable Gestures

To make a installed gesture recognizable, you must assign the gesture to the SDK using the setActiveGestureIdentifiers:gestureIdentifiers function defined in the CRApplication class.
You also can obtain the list of assigned gestures from the activeGestureIdentifiers function.

setActiveGestureIdentifiers:gestureIdentifiers

activeGestureIdentifiers

The Gesture Mode

In this mode, the gesture recognition is available.
You can receive the result of gesture recognition via the didReceiveGesture: function. The function returns the ID of recognized gesture or nil if failed to recognize.

Implementation Example

Swift

import UIKit

class ViewController: UIViewController, CRApplicationDelegate {

  var ringApp: CRApplication!

  override func viewDidLoad() {
    super.viewDidLoad()


    // Draw gesture images

    let width = self.view.bounds.size.width / 2;

    let leftImage = CRCommon.imageWithPoints(CR_POINTS_LEFT,
                                             width:width,
                                             lineColor:UIColor.grayColor(),
                                             pointColor:UIColor.grayColor())

    let leftImageView = UIImageView(image: leftImage)
    leftImageView.frame = CGRectMake(0, 0, width, width)
    self.view.addSubview(leftImageView)

    let rightImage = CRCommon.imageWithPoints(CR_POINTS_RIGHT,
                                              width:width,
                                              lineColor:UIColor.grayColor(),
                                              pointColor:UIColor.grayColor())
    let rightImageView = UIImageView(image: rightImage)
    rightImageView.frame = CGRectMake(width, 0, width, width)
    self.view.addSubview(rightImageView)


    // Start ringApp

    ringApp = CRApplication(delegate:self, background: false)

    if 0 == ringApp.installedGestureIdentifiers().count {
      let gestures = [
        "left" : CR_POINTS_LEFT,
        "right" : CR_POINTS_RIGHT,
        "up" : CR_POINTS_UP,
        "down" : CR_POINTS_DOWN,
        "circle" : CR_POINTS_CIRCLE,
        "heart" : CR_POINTS_HEART,
        "triangle" : CR_POINTS_TRIANGLE,
        "pigtail" : CR_POINTS_PIGTAIL,
        "one" : CR_POINTS_ONE,
        "two" : CR_POINTS_TWO,
        "three" : CR_POINTS_THREE,
        "four" : CR_POINTS_FOUR
      ]

      do {
        try ringApp.installGestures(gestures)
      } catch let error as NSError {
        print(error)
        return
      }
    }

    ringApp.setActiveGestureIdentifiers(["left", "right"]);

    ringApp.start()
  }

  func didReceiveEvent(event: CRRingEvent) {
  }

  func didReceivePoint(point: CGPoint) {
  }

  func didReceiveQuaternion(quaternion: CRQuaternion) {
  }

  func didReceiveGesture(identifier: String!) {

    guard let gestureId = identifier else {
      print("not match")
      return
    }
    print(identifier)

    if "left" == gestureId {
      ringApp.setActiveGestureIdentifiers(["up", "down"])
      return;
    }

    if "up" == gestureId {
      ringApp.setActiveGestureIdentifiers(["left", "right"])
      return;
    }

  }

  func deviceDidInitialize() {
  }

  func deviceDidDisconnect() {
  }
}

Objective-C

#import "ViewController.h"
#import <CoreRing/CoreRing.h>

@interface ViewController () <CRApplicationDelegate>
@property (nonatomic, strong) CRApplication *ringApp;
@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];


  // Draw gesture images

  CGFloat width = self.view.bounds.size.width / 2;

  UIImage *leftImage = [CRCommon imageWithPoints:CR_POINTS_LEFT
                                           width:width
                                       lineColor:UIColor.grayColor
                                      pointColor:UIColor.grayColor];
  UIImageView *leftImageView = [[UIImageView alloc] initWithImage:leftImage];
  leftImageView.frame = CGRectMake(0, 0, width, width);
  [self.view addSubview:leftImageView];

  UIImage *rightImage = [CRCommon imageWithPoints:CR_POINTS_RIGHT
                                            width:width
                                        lineColor:UIColor.grayColor
                                       pointColor:UIColor.grayColor];
  UIImageView *rightImageView = [[UIImageView alloc] initWithImage:rightImage];
  rightImageView.frame = CGRectMake(width, 0, width, width);
  [self.view addSubview:rightImageView];


  // Start ringApp

  self.ringApp = [[CRApplication alloc] initWithDelegate:self background:NO];

  if (![self.ringApp installedGestureIdentifiers].count) {
    NSDictionary *gestures = @{ @"left" : CR_POINTS_LEFT,
                                @"right" : CR_POINTS_RIGHT,
                                @"up" : CR_POINTS_UP,
                                @"down" : CR_POINTS_DOWN,
                                @"circle" : CR_POINTS_CIRCLE,
                                @"heart" : CR_POINTS_HEART,
                                @"triangle" : CR_POINTS_TRIANGLE,
                                @"pigtail" : CR_POINTS_PIGTAIL,
                                @"one" : CR_POINTS_ONE,
                                @"two" : CR_POINTS_TWO,
                                @"three" : CR_POINTS_THREE,
                                @"four" : CR_POINTS_FOUR };
    NSError *error;
    if (![self.ringApp installGestures:gestures error:&error]) {
      NSLog(@"%@", error);
      return;
    }
  }

  [self.ringApp setActiveGestureIdentifiers:@[@"left", @"right"]];

  [self.ringApp start];
}

- (void)didReceiveEvent:(CRRingEvent)event {
}

- (void)didReceivePoint:(CGPoint)point {
}

- (void)didReceiveQuaternion:(CRQuaternion)quaternion {
}

- (void)didReceiveGesture:(NSString *)identifier {
  NSLog(@"%@", identifier);

  if ([@"left" isEqualToString:identifier]) {
    [self.ringApp setActiveGestureIdentifiers:@[@"up", @"down"]];
    return;
  }

  if ([@"up" isEqualToString:identifier]) {
    [self.ringApp setActiveGestureIdentifiers:@[@"left", @"right"]];
    return;
  }

}

- (void)deviceDidInitialize {
}

- (void)deviceDidDisconnect {
}

@end


<The Quaternion Mode     |     TOP     |     Running Background>