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
|
//
// NT13BModule.m
// ReactNativeIOSLibrary
//
// Created by user on 2019/11/12.
// Copyright © 2019 daiqingquan. All rights reserved.
//
#import "NT13BModule.h"
#import "NT13BHeader.h"
#import "NT13BProfileModule.h"
@implementation NT13BModule
RCT_EXPORT_MODULE()
- (NSArray<NSString *> *)supportedEvents {
return @[@"event_notify", @"event_scan_device", @"event_scan_finish",
@"event_device_connected", @"event_device_connect_failed",
@"event_device_disconnect", @"event_authenticate_result",
@"event_notify_ts28b", @"event_notify_bg1",
@"action_connect_result_for_bg1"];
}
- (NSDictionary *)constantsToExport
{
return @{ @"Event_Notify": NT13B_EVENT_NOTIFY ,
};
}
+ (BOOL)requiresMainQueueSetup
{
return YES;
}
-(NT13B*)getDeviceWithMac:(NSString*)mac{
NT13BController *controller = [NT13BController shareIHNT13BController];
NSArray *nt13bDeviceArray = [controller getAllCurrentNT13BInstace];
for(NT13B *tempDevice in nt13bDeviceArray){
if([mac isEqualToString:tempDevice.serialNumber]){
return tempDevice;
}
}
return nil;
}
RCT_EXPORT_METHOD(getAllConnectedDevices){
NSArray*nt13bDeviceArray= [[NT13BController shareIHNT13BController] getAllCurrentNT13BInstace];
NSMutableArray*deviceMacArray=[NSMutableArray array];
for (int i=0; i<[nt13bDeviceArray count]; i++) {
NT13B *nt13b = [nt13bDeviceArray objectAtIndex:i];
[deviceMacArray addObject:nt13b.serialNumber];
}
NSDictionary* deviceInfo = @{NT13B_ACTION:kACTION_GET_ALL_CONNECTED_DEVICES,NT13B_DEVICE:deviceMacArray};
[self sendEventWithName:NT13B_EVENT_NOTIFY body:deviceInfo];
}
RCT_EXPORT_METHOD(measure:(nonnull NSString *)mac){
if ([self getDeviceWithMac:mac] != nil) {
[[self getDeviceWithMac:mac] commandStartMeasure:^(NSDictionary *result) {
NSDictionary* deviceInfo = @{NT13B_ACTION:@"action_measurement_result",NT13B_THERMOMETER_TYPE:[result objectForKey:@"bodyFlag"],NT13B_UNIT_FLAG:[result objectForKey:@"unit"],NT13B_RESULT:[result objectForKey:@"result"]};
[self sendEventWithName:NT13B_EVENT_NOTIFY body:deviceInfo];
}];
}
}
//断开连接
RCT_EXPORT_METHOD(disconnect:(nonnull NSString *)mac){
if ([self getDeviceWithMac:mac]!=nil) {
[[self getDeviceWithMac:mac] commandDisconnect:^(BOOL result) {
}];
}else{
}
}
@end
|