Skip to content

Instantly share code, notes, and snippets.

@programmarchy
Created October 28, 2014 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save programmarchy/96d4a2dcefa23b126d9e to your computer and use it in GitHub Desktop.
Save programmarchy/96d4a2dcefa23b126d9e to your computer and use it in GitHub Desktop.
Basic MOSS View Controller
//
// ViewController.m
// ExampleMoss
//
// Created by Donald Ness on 10/28/14.
// Copyright (c) 2014 Modular Robotics. All rights reserved.
//
#import "ViewController.h"
#import <MossKit/MossKit.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
MRMossBrainManager *manager = [MRMossBrainManager sharedMossBrainManager];
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(mossBrainsDidChange:)
name:MRMossBrainManagerMossBrainsDidChangeNotification
object:manager];
[manager scanForMossBrains];
}
- (void)mossBrainsDidChange:(id)note {
NSArray *mossBrains = [[MRMossBrainManager sharedMossBrainManager] mossBrains];
if (mossBrains.count > 0) {
MRMossBrain *firstBrain = mossBrains[0];
[self connectToFirstMossBrain:firstBrain];
}
}
- (void)connectToFirstMossBrain:(MRMossBrain *)brain
{
NSLog(@"brain name: %@", brain.name);
[brain connectWithResult:^(NSError *err) {
if (err) {
NSLog(@"error connecting: %@", err);
}
else {
// Now, we're connected!
[brain setFaceState:MRMossBrainFaceStateInput atIndex:5 withResult:^(NSError *err) {
// Now face 6 is an input!
[brain
startFaceValueUpdatesToQueue:dispatch_get_main_queue()
withHandler:^(UInt8 index, UInt8 value) {
if (index == 5) {
float floatValue = 1.0 * value / 255.0f;
self.valueSlider.minimumValue = 0;
self.valueSlider.maximumValue = 1;
NSLog(@"value of %d is %f", index, floatValue);
self.valueSlider.value = floatValue;
}
} withResult:nil];
}];
}
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment