BleControl.m
4.17キロバイト
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//
// BleControl.m
// jacket_ios
//
// Created by ドラッサル 亜嵐 on 2016/04/27.
// Copyright © 2016年 ドラッサル 亜嵐. All rights reserved.
//
#import "BleControl.h"
@interface BleControl ()
@property (nonatomic) NSInteger slotCounter;
@property (nonatomic) NSInteger slotCounterMin;
@property (nonatomic) NSInteger slotCounterMax;
@property (nonatomic) NSTimer * tmr;
@end
@implementation BleControl
@synthesize ble;
@synthesize protocol;
- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
self.slotCounterMin = 0;
self.slotCounterMax = 5;
self.slotCounter = self.slotCounterMin;
}
- (void)viewWillAppear:(BOOL)animated {
protocol.delegate = self;
self.tmr = [NSTimer timerWithTimeInterval:0.1
target:self
selector:@selector(tmrMethod:)
userInfo:nil
repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:self.tmr forMode:NSRunLoopCommonModes];
}
- (void)viewWillDisappear:(BOOL)animated {
[self.tmr invalidate];
}
- (void)tmrMethod:(NSTimer *)timer {
[self getNextSlot];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)getNextSlot {
// TODO: Fix
/*
if(self.slotCounter == 0) {
[protocol getTime];
} else if(self.slotCounter == 1) {
[protocol getUsetime];
} else if(self.slotCounter == 2) {
[protocol getState];
} else if(self.slotCounter == 3) {
[protocol getSleep];
} else if(self.slotCounter == 4) {
[protocol getWake];
} else if(self.slotCounter == 5) {
[protocol getWalking];
}
*/
self.slotCounter++;
if(self.slotCounter > self.slotCounterMax) {
self.slotCounter = self.slotCounterMin;
}
}
- (IBAction)btnEditState:(id)sender {
[self performSegueWithIdentifier:@"idSegueEditState" sender:self];
}
- (IBAction)btnEditTime:(id)sender {
[self performSegueWithIdentifier:@"idSegueEditTime" sender:self];
}
- (IBAction)btnEditSleep:(id)sender {
[self performSegueWithIdentifier:@"idSegueEditSleep" sender:self];
}
- (IBAction)btnEditWake:(id)sender {
[self performSegueWithIdentifier:@"idSegueEditWake" sender:self];
}
- (IBAction)btnEditWalking:(id)sender {
// TODO: Fix
if(stateCurrentWalking == false) {
//[protocol setWalking:true];
} else {
//[protocol setWalking:false];
}
}
- (IBAction)btnResetUsetime:(id)sender {
// TODO: Fix
//[protocol resetUsetime];
}
- (IBAction)btnUsetime:(id)sender {
[self performSegueWithIdentifier:@"idSegueUsetime" sender:self];
}
- (IBAction)btnCaseUnlock:(id)sender {
// TODO: Fix
//[protocol setUnlock];
}
- (void) protocolDidReceiveState:(NSString *)data text:(NSString *)text {
[currentState setText:text];
}
- (void) protocolDidReceiveTime:(NSString *) data {
[currentTime setText:data];
}
- (void) protocolDidReceiveSleepingBegin:(NSString *) data {
[currentSleep setText:data];
}
- (void) protocolDidReceiveSleepingEnd:(NSString *) data {
[currentWake setText:data];
}
- (void) protocolDidReceiveUsetime:(NSInteger) data {
int seconds = data % 60;
int minutes = (data / 60) % 60;
int hours = (int)data / 3600;
NSString *strUsetime = [NSString stringWithFormat:@"%02d:%02d:%02d",hours, minutes, seconds];
[currentUsetime setText:strUsetime];
}
- (void) protocolDidReceiveUsetimeSlot:(NSInteger) dataSlot dataStamp:(NSTimeInterval) dataStamp dataUsetime: (NSInteger) dataUsetime {
}
- (void) protocolDidReceiveWalking:(BOOL)data {
stateCurrentWalking = data;
NSString *strData = [NSString alloc];
if(stateCurrentWalking == false) {
strData = @"無効";
} else {
strData = @"有効";
}
[currentWalking setText:strData];
}
@end