source: orbit/iOS/Orbit/Orbit/controllers/FlightViewController.m @ ab9d63b

RawEEGServoTab_Interfacepyramid
Last change on this file since ab9d63b was ab9d63b, checked in by Jonathon Horsman <jonathon@…>, 9 years ago

Initial check in to convert into a 4 tab app with tutorial, flight, advanced and support tabs.
Old controller code remains for now but about to be removed

  • Property mode set to 100644
File size: 4.0 KB
Line 
1//
2//  FlightViewController.m
3//  Orbit
4//
5//  Copyright (c) 2013 Puzzlebox Productions, LLC. All rights reserved.
6//  Originally created by Jonathon Horsman.
7//
8//  This code is released under the GNU Public License (GPL) version 2
9//  For more information please refer to http://www.gnu.org/copyleft/gpl.html
10//
11
12#import <QuartzCore/QuartzCore.h>
13#import "FlightViewController.h"
14#import "AppDelegate.h"
15#import "SignalConverter.h"
16
17#define STATUS_DEFAULT 0
18#define STATUS_CONNECTING 1
19#define STATUS_CONNECTED 2
20#define STATUS_PROCESSING 3
21#define STATUS_ACTIVE 4
22
23@implementation FlightViewController {
24    SignalConverter *signalConverter;
25}
26
27@synthesize status, attention, meditation, signal, power, attentionThreshold, meditationThreshold, connectButton, statusImage;
28
29- (void)viewDidLoad
30{
31    [super viewDidLoad];
32    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
33    signalConverter = appDelegate.signalConverter;
34   
35    signalConverter.delegate = self;
36    [self.attentionThreshold addTarget:self action:@selector(sliderChanged) forControlEvents:UIControlEventValueChanged];
37    [self.meditationThreshold addTarget:self action:@selector(sliderChanged) forControlEvents:UIControlEventValueChanged];
38    [signalConverter prepare];
39}
40
41// Start the data stream from the bluetooth headset if it's attached, and reset the display output
42- (void) appForegrounded
43{
44    [self resetViews]; // just in case it didn't happen on close
45}
46
47#pragma mark view updates
48
49// Set all levels back to zero
50- (void) resetViews
51{
52    signal.progress = 0;
53    attention.progress = 0;
54    meditation.progress = 0;
55    power.progress = 0;
56    [self logMessage:@"Disconnected"];
57}
58
59- (void) updateStatusImage:(int) statusNo
60{
61    [statusImage setImage: [UIImage imageNamed:[NSString stringWithFormat:@"status_%u", statusNo]]];
62}
63
64- (void) sliderChanged
65{
66    [signalConverter setValuesForAttention:attentionThreshold.value meditation:meditationThreshold.value];
67//   
68//    if (attentionThreshold.value < 0.2) {
69//        [self updateStatusImage:STATUS_DEFAULT];
70//    } else if (attentionThreshold.value < 0.4) {
71//        [self updateStatusImage:STATUS_CONNECTING];
72//    } else if (attentionThreshold.value < 0.6) {
73//        [self updateStatusImage:STATUS_CONNECTED];
74//    } else if (attentionThreshold.value < 0.8) {
75//        [self updateStatusImage:STATUS_PROCESSING];
76//    } else {
77//        [self updateStatusImage:STATUS_ACTIVE];
78//    }
79}
80
81- (void) logMessage:(NSString *) str
82{
83    status.text = str;
84}
85
86#pragma mark - SignalConverterDelegate methods
87
88- (void) updatedValuesForSignal: (float)signalStrength
89                      attention: (float)attentionLevel
90                     meditation: (float)meditationLevel
91                          power: (float)powerLevel
92{
93    self.signal.progress = signalStrength;
94    self.signalPercent.text = [NSString stringWithFormat:@"%i%%", (int)(signalStrength * 100)];
95    self.attention.progress = attentionLevel;
96    self.attentionPercent.text = [NSString stringWithFormat:@"%i%%", (int)(attentionLevel * 100)];
97    self.meditation.progress = meditationLevel;
98    self.meditationPercent.text = [NSString stringWithFormat:@"%i%%", (int)(meditationLevel * 100)];
99    self.power.progress = powerLevel;
100    self.powerPercent.text = [NSString stringWithFormat:@"%i%%", (int)(powerLevel * 100)];
101}
102
103- (void) notifyHeadsetConnect
104{
105    [self logMessage:@"Headet connected"];
106}
107
108- (void) notifyHeadsetDisconnect
109{
110    // Reset the outputs back to zero
111    [self resetViews];
112    [self logMessage:@"Headet disconnected"];   
113}
114
115- (void) notifyDeviceConnected:(NSString *)name
116{
117    [self logMessage:[NSString stringWithFormat:@"EEG device %@ connected", name]];   
118}
119
120#pragma mark - button press events
121
122- (IBAction) connectButtonPressed:(id) sender {
123   
124    if (signalConverter.running) {
125        [signalConverter stopProcessing];
126        connectButton.title = @"Connect";
127        [self resetViews];
128    } else {
129        [self logMessage:@"Searching for device"];
130        [signalConverter startProcessing];
131        connectButton.title = @"Disconnect";
132    }
133}
134
135@end
Note: See TracBrowser for help on using the repository browser.