SensoriaHandler.swift
Purpose
SensoriaHandler.swift provides Bluetooth connection management and data handling for Sensoria smart footwear sensors within the HealthyWear iOS system. It connects to Sensoria devices, receives real-time telemetry, buffers the data, and prepares it for storage or transmission.
Imports
import Foundation
import SensoriaiOS
import BoltsSwift
SensoriaiOS: SDK for managing smart textile devices like foot sensors.BoltsSwift: For potential asynchronous task chaining (not actively used here).Foundation: Standard Swift utilities.
Class: SensoriaHandler
Singleton
static let shared = SensoriaHandler()
Provides a globally accessible instance for device management.
Properties
sacores: Array of two
SACoreinstances — each corresponds to one foot (left/right).activeScanningCore: The currently scanning core.
dataBuffer: Array of formatted sensor strings awaiting upload.
maxBufferSize: Threshold after which the buffer is flushed.
bufferQueue: A
DispatchQueueused for thread-safe buffer operations.
Initializer
override init()
Registers the handler as a delegate for both
SACoreinstances.Ensures real-time callbacks are routed to this class.
Method: startConnection(deviceIndex:)
func startConnection(deviceIndex: Int)
Starts scanning on the corresponding
SACore(left or right).Sets the
activeScanningCoreaccordingly.
Method: didScan(_:)
Callback triggered when a device is detected.
Infers device side (“Right” or “Left”).
Registers metadata using
DeviceRegistry.Connects to the detected device.
Method: didUpdateData()
Callback when new data is received.
Constructs a
formattedDatastring using all available sensor metrics.Appends to
dataBufferinside a background queue.Flushes the buffer via
processAndClearBuffer()when full.
Method: formatData(from:footIndicator:)
Returns a comma-separated string of:
Pressure sensors (s0, s1, s2)
IMU: Accelerometer, Magnetometer, Gyroscope
Timestamp and foot indicator
return "\(core.s0),\(core.s1),...(core.timestamp),\(footIndicator)"
Method: processAndClearBuffer()
Clears the dataBuffer. Placeholder for future implementation of upload logic (likely to server or file system).
Method: didError(_)
Prints error messages for debugging or telemetry failure.