-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathDJIDRootViewController.m
More file actions
142 lines (114 loc) · 3.7 KB
/
DJIDRootViewController.m
File metadata and controls
142 lines (114 loc) · 3.7 KB
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
//
// DJIDRootViewController.m
// DJIDebuger
//
// Created by DJI on 15/10/13.
// Copyright © 2015年 DJI. All rights reserved.
//
#import "DJIDRootViewController.h"
#import <DJISDK/DJISDK.h>
#include <pthread.h>
#include <ifaddrs.h>
#include <arpa/inet.h>
#define weakSelf(__TARGET__) __weak typeof(self) __TARGET__=self
#define weakReturn(__TARGET__) if(__TARGET__==nil)return;
#define DJI_SERVICE_OPTION_KEY @"DJI_SERVICE_OPTION_KEY"
#define DJI_DEBUG_ID_NAME_KEY @"DJI_DEBUG_ID_NAME_KEY"
#define GREEN_IMAGE_1 [UIImage imageNamed:@"icon_circle_green_1"]
#define GREEN_IMAGE_2 [UIImage imageNamed:@"icon_circle_green_2"]
#define RED_IMAGE_1 [UIImage imageNamed:@"icon_circle_red_1"]
#define RED_IMAGE_2 [UIImage imageNamed:@"icon_circle_red_2"]
@interface DJIDRootViewController ()<DJISDKDebugServerDelegate>
// UI
@property (weak,nonatomic) IBOutlet UILabel* debugIdLabel;
@property (weak,nonatomic) IBOutlet UILabel* debugTitleLabel;
@property (weak,nonatomic) IBOutlet UIImageView* rcImageView1;
@property (weak,nonatomic) IBOutlet UIImageView* rcImageView2;
@property (weak,nonatomic) IBOutlet UIImageView* wifiImageView1;
@property (weak,nonatomic) IBOutlet UIImageView* wifiImageView2;
@end
@implementation DJIDRootViewController
- (void) updateIPAddress:(NSString*) ipaddress {
weakSelf(target);
dispatch_async(dispatch_get_main_queue(), ^{
weakReturn(target);
target.debugIdLabel.text = ipaddress;
});
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initUI];
weakSelf(target);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
weakReturn(target);
[DJISDKManager startSDKDebugServerWithCompletion:^(NSString* ipaddress){
[target updateIPAddress:ipaddress];
}];
[DJISDKManager setDebugServerDelegate:target];
});
}
- (UIStatusBarStyle) preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[UIApplication sharedApplication].idleTimerDisabled = YES;
}
-(void) viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[UIApplication sharedApplication].idleTimerDisabled = NO;
}
-(void) initUI
{
[self setWiFiConnectionStatus:NO];
[self setRCConnectionStatus:NO];
self.debugIdLabel.text = @"";
}
-(void) setRCConnectionStatus:(BOOL)connected
{
if (connected) {
self.rcImageView1.image = GREEN_IMAGE_1;
self.rcImageView2.image = GREEN_IMAGE_2;
}
else
{
self.rcImageView1.image = RED_IMAGE_1;
self.rcImageView2.image = RED_IMAGE_2;
}
}
-(void) setWiFiConnectionStatus:(BOOL)connected
{
if (connected) {
self.wifiImageView1.image = GREEN_IMAGE_1;
self.wifiImageView2.image = GREEN_IMAGE_2;
}
else
{
self.wifiImageView1.image = RED_IMAGE_1;
self.wifiImageView2.image = RED_IMAGE_2;
}
}
#pragma mark - UI Action
-(IBAction) onResetButtonClicked:(id)sender
{
[self setWiFiConnectionStatus:NO];
weakSelf(target);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
weakReturn(target);
[DJISDKManager setDebugServerDelegate:target];
[DJISDKManager startSDKDebugServerWithCompletion:^(NSString * ipaddress){
[target updateIPAddress:ipaddress];
}];
});
}
-(void) sdkDebugServerWithRCConnectionStatus:(BOOL)isRCConnected andDebugClientConnectionStatus:(BOOL)isWifiConnected{
weakSelf(target);
dispatch_async(dispatch_get_main_queue(), ^{
weakReturn(target);
[target setRCConnectionStatus:isRCConnected];
[target setWiFiConnectionStatus:isWifiConnected];
});
}
@end