ilabs-flir 1.0.5 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,35 @@
1
1
  package flir.android
2
2
 
3
+ import android.util.Log
3
4
  import com.facebook.react.bridge.Promise
4
5
  import com.facebook.react.bridge.ReactApplicationContext
5
6
  import com.facebook.react.bridge.ReactContextBaseJavaModule
6
7
  import com.facebook.react.bridge.ReactMethod
8
+ import com.facebook.react.modules.core.DeviceEventManagerModule
7
9
 
8
10
  class FlirModule(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
11
+
12
+ companion object {
13
+ private const val TAG = "FlirModule"
14
+ }
15
+
9
16
  override fun getName(): String = "FlirModule"
17
+
18
+ // Required for RN event emitter support
19
+ private var listenerCount = 0
20
+
21
+ @ReactMethod
22
+ fun addListener(eventName: String) {
23
+ listenerCount++
24
+ Log.d(TAG, "addListener: $eventName (count: $listenerCount)")
25
+ }
26
+
27
+ @ReactMethod
28
+ fun removeListeners(count: Int) {
29
+ listenerCount -= count
30
+ if (listenerCount < 0) listenerCount = 0
31
+ Log.d(TAG, "removeListeners: $count (remaining: $listenerCount)")
32
+ }
10
33
 
11
34
  // Simple placeholder conversion: converts an ARGB color to a pseudo-temperature value.
12
35
  // Replace with SDK call when integrating thermalsdk APIs.
@@ -103,4 +126,132 @@ class FlirModule(private val reactContext: ReactApplicationContext) : ReactConte
103
126
  promise.reject("ERR_FLIR_SDK_STATUS", e)
104
127
  }
105
128
  }
129
+
130
+ @ReactMethod
131
+ fun getDiscoveredDevices(promise: Promise) {
132
+ try {
133
+ val devices = FlirManager.getDiscoveredDevices()
134
+ val result = com.facebook.react.bridge.Arguments.createArray()
135
+
136
+ devices.forEach { identity ->
137
+ val deviceMap = com.facebook.react.bridge.Arguments.createMap()
138
+ deviceMap.putString("id", identity.deviceId)
139
+ deviceMap.putString("name", identity.deviceId)
140
+ deviceMap.putString("communicationType", identity.communicationInterface.name)
141
+ deviceMap.putBoolean("isEmulator", identity.communicationInterface.name == "EMULATOR")
142
+ result.pushMap(deviceMap)
143
+ }
144
+
145
+ promise.resolve(result)
146
+ } catch (e: Exception) {
147
+ promise.reject("ERR_FLIR_DEVICES", e)
148
+ }
149
+ }
150
+
151
+ @ReactMethod
152
+ fun startEmulator(emulatorType: String, promise: Promise) {
153
+ try {
154
+ // Ensure SDK is initialized with context before starting discovery
155
+ FlirManager.init(reactContext)
156
+ // With simplified API, just start discovery - emulators are discovered like any device
157
+ FlirManager.startDiscovery(true)
158
+ promise.resolve(true)
159
+ } catch (e: Exception) {
160
+ promise.reject("ERR_FLIR_EMULATOR", e)
161
+ }
162
+ }
163
+
164
+ @ReactMethod
165
+ fun connectToDevice(deviceId: String, promise: Promise) {
166
+ try {
167
+ // Ensure SDK is initialized with context before connecting
168
+ FlirManager.init(reactContext)
169
+ FlirManager.connectToDevice(deviceId)
170
+ promise.resolve(true)
171
+ } catch (e: Exception) {
172
+ promise.reject("ERR_FLIR_CONNECT", e)
173
+ }
174
+ }
175
+
176
+ @ReactMethod
177
+ fun startDiscovery(promise: Promise) {
178
+ try {
179
+ // Ensure SDK is initialized with context before starting discovery
180
+ FlirManager.init(reactContext)
181
+ FlirManager.startDiscovery(true)
182
+ promise.resolve(true)
183
+ } catch (e: Exception) {
184
+ promise.reject("ERR_FLIR_DISCOVERY", e)
185
+ }
186
+ }
187
+
188
+ @ReactMethod
189
+ fun stopDiscovery(promise: Promise) {
190
+ try {
191
+ FlirManager.stopDiscovery()
192
+ promise.resolve(true)
193
+ } catch (e: Exception) {
194
+ promise.reject("ERR_FLIR_STOP_DISCOVERY", e)
195
+ }
196
+ }
197
+
198
+ @ReactMethod
199
+ fun stopFlir(promise: Promise) {
200
+ try {
201
+ FlirManager.stop()
202
+ promise.resolve(true)
203
+ } catch (e: Exception) {
204
+ promise.reject("ERR_FLIR_STOP", e)
205
+ }
206
+ }
207
+
208
+ @ReactMethod
209
+ fun initializeSDK(promise: Promise) {
210
+ try {
211
+ FlirManager.init(reactContext)
212
+
213
+ val result = com.facebook.react.bridge.Arguments.createMap()
214
+ result.putBoolean("initialized", true)
215
+ result.putString("message", "SDK initialized successfully")
216
+ promise.resolve(result)
217
+ } catch (e: Exception) {
218
+ val result = com.facebook.react.bridge.Arguments.createMap()
219
+ result.putBoolean("initialized", false)
220
+ result.putString("error", e.message ?: "Unknown error")
221
+ result.putString("errorType", e.javaClass.simpleName)
222
+ promise.resolve(result)
223
+ }
224
+ }
225
+
226
+ @ReactMethod
227
+ fun getDebugInfo(promise: Promise) {
228
+ try {
229
+ val result = com.facebook.react.bridge.Arguments.createMap()
230
+
231
+ // SDK availability
232
+ result.putBoolean("sdkAvailable", FlirSDKLoader.isSDKAvailable(reactContext))
233
+ result.putString("arch", FlirSDKLoader.getDeviceArch())
234
+
235
+ // Check if FLIR SDK classes are loadable
236
+ val classesLoaded = try {
237
+ Class.forName("com.flir.thermalsdk.androidsdk.ThermalSdkAndroid")
238
+ Class.forName("com.flir.thermalsdk.live.discovery.DiscoveryFactory")
239
+ true
240
+ } catch (e: ClassNotFoundException) {
241
+ false
242
+ }
243
+ result.putBoolean("sdkClassesLoaded", classesLoaded)
244
+
245
+ // Discovery state
246
+ val devices = FlirManager.getDiscoveredDevices()
247
+ result.putInt("discoveredDeviceCount", devices.size)
248
+ result.putBoolean("isConnected", FlirManager.isConnected())
249
+ result.putBoolean("isStreaming", FlirManager.isStreaming())
250
+ result.putString("connectedDevice", FlirManager.getConnectedDeviceInfo())
251
+
252
+ promise.resolve(result)
253
+ } catch (e: Exception) {
254
+ promise.reject("ERR_DEBUG_INFO", e)
255
+ }
256
+ }
106
257
  }