当前位置: 首页 > news >正文

网站全程设计技术北京网站备案在哪

网站全程设计技术,北京网站备案在哪,百度搜索简洁版网址,网络游戏代理平台在飞速发展的可穿戴技术领域#xff0c;我们正处于一个十字路口——市场上充斥着各式时尚、功能丰富的设备#xff0c;声称能够彻底改变我们对健康和健身的方式。 然而#xff0c;在这些光鲜的外观和营销宣传背后#xff0c;隐藏着一个令人担忧的现实#xff1a;大多数这些… 在飞速发展的可穿戴技术领域我们正处于一个十字路口——市场上充斥着各式时尚、功能丰富的设备声称能够彻底改变我们对健康和健身的方式。 然而在这些光鲜的外观和营销宣传背后隐藏着一个令人担忧的现实大多数这些设备是封闭系统其内部运行被专有代码和封闭硬件所掩盖。作为消费者我们对这些设备如何收集、处理及可能共享我们的健康数据一无所知。 这时Halo 出现了它是一种旨在让健康追踪更加普惠化的开源替代方案。通过这系列文章我们将引导你从基础入手构建并使用完全透明、可定制的可穿戴设备。 需要说明的是Halo 的目标并不是在外观或功能完整性上与消费级可穿戴设备竞争。相反它提供了一种独特的、动手实践的方式来理解健康追踪设备背后的技术。 我们将使用 Swift 5 来构建对应的 iOS 界面Python 3.10。由于此项目的代码完全开源你可以随时提交 PR 拉取请求或者 Fork 分叉项目以探索全新的方向。 开源https://github.com/cyrilzakka/Halo-iOS 你将需要 获取COLMI R02实体设备价格在撰写时为 11 到 30 美金左右。https://www.aliexpress.us/item/3256806445134241.html?gatewayAdaptglo2usa4itemAdapt一个安装了 Xcode 16 的开发环境以及可选的 Apple 开发者计划会员资格。Python 3.10并安装了 pandas、numpy、torch 当然还有 transformers。 致谢 此项目基于Python 仓库的代码及我的学习成果构建。 Python 仓库https://tahnok.github.io/colmi_r02_client/ 免责声明 作为一名医生我有法律义务提醒你你即将阅读的内容并不是医学建议。现在让我们开始让一些可穿戴设备发出蜂鸣声吧 配对戒指 在进入代码之前让我们先了解蓝牙低能耗 (BLE) 的关键规格。BLE 基于一个简单的客户端-服务器模型使用三个核心概念中央设备 (Centrals) 、服务 (Services) 和 **特征 (Characteristics)**。以下是它们的具体介绍 中央设备 (例如你的 iPhone) 负责启动和管理与外设 (例如我们的 COLMI R02 戒指) 的连接。戒指通过广播自身信息等待手机连接每次仅支持一台手机连接。服务 是戒指上相关功能的集合例如心率监测服务或电池状态服务。每个服务都有一个唯一标识符 (UUID) 客户端通过它来找到对应服务。特征 是每个服务中的具体数据点或控制机制。例如它们可能是只读 (获取传感器数据) 、只写 (发送命令) 或两者兼有。有些特征还能在其值发生变化时自动通知手机这对于实时健康监测尤为重要。 当手机连接到戒指时会定位所需的服务并与特定特征交互以发送命令或接收数据。这种结构化的方法不仅确保了通信效率还能延长电池使用时间。了解了这些基础知识后让我们开始构建吧 设置 Xcode 项目 创建一个名为 Halo 的新项目目标平台为 iOS。组织标识符建议使用反向域名格式 (如 com.example) 。本项目中我们使用 com.FirstNameLastName。 接下来为应用启用必要的功能。在 Xcode 中打开 Signing Capabilities 选项卡启用以下 后台模式 (Background Modes)以确保应用在后台运行时能够保持与戒指的连接并处理数据。 然后我们将使用 Apple 提供的最新框架AccessorySetupKit用于将蓝牙和 Wi-Fi 配件连接到 iOS 应用。此框架自 iOS 18 推出替代了传统的广泛蓝牙权限请求方式专注于为用户明确批准的特定设备提供访问权限。 AccessorySetupKithttps://developer.apple.com/documentation/accessorysetupkit/ 当用户尝试将 COLMI R02 戒指连接到应用时AccessorySetupKit 会显示一个系统界面仅列出兼容的附近设备。用户选择设备后应用即可与戒指通信而无需请求完整的蓝牙权限。这大大提升了用户隐私同时简化了设备连接的管理流程。 打开 Info.plist 文件 (可以在左侧边栏中找到或通过 Project Navigator (⌘1) Your Target Info 定位) 。添加以下键值条目以支持与 COLMI R02 戒指的配对 添加 NSAccessorySetupKitSupports类型为 Array并将 Bluetooth 作为第一个项目。添加 NSAccessorySetupBluetoothServices类型为 Array并将以下 UUID 作为 String 项 6E40FFF0-B5A3-F393-E0A9-E50E24DCCA9E0000180A-0000-1000-8000-00805F9B34FB 至此初步配置完成 Ring Session Manager 类 接下来我们将创建一个 RingSessionManager 类用于管理所有与戒指的通信。此类的主要职责包括 扫描附近的戒指连接到戒指发现服务和特征实现数据读写操作 第一步创建 RingSessionManager 首先创建一个新的 Swift 文件 (⌘N) 命名为 RingSessionManager.swift。以下是类的定义以及需要实现的关键属性 Observable class RingSessionManager: NSObject {// 追踪连接状态var peripheralConnected  falsevar pickerDismissed  true// 存储当前连接的戒指var currentRing: ASAccessory?private var session  ASAccessorySession()// 核心蓝牙对象private var manager: CBCentralManager?private var peripheral: CBPeripheral? } 第二步发现戒指 戒指通过特定的蓝牙服务 UUID 进行广播。为了找到它我们需要创建一个 ASDiscoveryDescriptor 对象指定其蓝牙服务的 UUID。以下代码完成了这一功能 private static let ring: ASPickerDisplayItem  {let descriptor  ASDiscoveryDescriptor()descriptor.bluetoothServiceUUID  CBUUID(string: 6E40FFF0-B5A3-F393-E0A9-E50E24DCCA9E)return ASPickerDisplayItem(name: COLMI R02 Ring,productImage: UIImage(named: colmi)!,descriptor: descriptor) }() 确保将戒指图片添加到项目资源目录中或者用合适的占位符替换 UIImage(named: colmi)!。 第三步显示戒指选择器 为了让用户选择戒指我们调用系统内置的设备选择器界面 func presentPicker() {session.showPicker(for: [Self.ring]) { error inif let error {print(Failed to show picker: \(error.localizedDescription))}} } 第四步处理戒指选择 当用户从选择器中选定设备后应用需要处理连接和管理逻辑。以下代码实现了事件处理 private func handleSessionEvent(event: ASAccessoryEvent) {switch event.eventType {case .accessoryAdded:guard let ring  event.accessory else { return }saveRing(ring: ring)case .activated:// 重新连接已配对戒指guard let ring  session.accessories.first else { return }saveRing(ring: ring)case .accessoryRemoved:currentRing  nilmanager  nil} } 第五步建立连接 完成选择戒指后我们需要与其建立蓝牙连接 func connect() {guard let manager, manager.state  .poweredOn, let peripheral else { return }let options: [String: Any]  [CBConnectPeripheralOptionNotifyOnConnectionKey: true,CBConnectPeripheralOptionNotifyOnDisconnectionKey: true,CBConnectPeripheralOptionStartDelayKey: 1]manager.connect(peripheral, options: options) } 第六步理解委托方法 在 RingSessionManager 中我们实现了两个关键的委托协议用于管理蓝牙通信过程。 中央管理器委托 (CBCentralManagerDelegate)此委托主要处理蓝牙连接的整体状态。 func centralManagerDidUpdateState(_ central: CBCentralManager) {print(Central manager state: \(central.state))switch central.state {case .poweredOn:if let peripheralUUID  currentRing?.bluetoothIdentifier {if let knownPeripheral  central.retrievePeripherals(withIdentifiers: [peripheralUUID]).first {print(Found previously connected peripheral)peripheral  knownPeripheralperipheral?.delegate  selfconnect()} else {print(Known peripheral not found, starting scan)}}default:peripheral  nil} } 当蓝牙开启时程序会检查是否有已连接的戒指并尝试重新连接。成功连接后 func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {print(DEBUG: Connected to peripheral: \(peripheral))peripheral.delegate  selfprint(DEBUG: Discovering services...)peripheral.discoverServices([CBUUID(string: Self.ringServiceUUID)])peripheralConnected  true } 断开连接时 func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: (any Error)?) {print(Disconnected from peripheral: \(peripheral))peripheralConnected  falsecharacteristicsDiscovered  false } 外设委托 (CBPeripheralDelegate) 此委托主要处理与戒指的具体通信。首先发现戒指的服务 func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: (any Error)?) {print(DEBUG: Services discovery callback, error: \(String(describing: error)))guard error  nil, let services  peripheral.services else {print(DEBUG: No services found or error occurred)return}print(DEBUG: Found \(services.count) services)for service in services {if service.uuid  CBUUID(string: Self.ringServiceUUID) {print(DEBUG: Found ring service, discovering characteristics...)peripheral.discoverCharacteristics([CBUUID(string: Self.uartRxCharacteristicUUID),CBUUID(string: Self.uartTxCharacteristicUUID)], for: service)}} } 发现特征后 func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {print(DEBUG: Characteristics discovery callback, error: \(String(describing: error)))guard error  nil, let characteristics  service.characteristics else {print(DEBUG: No characteristics found or error occurred)return}print(DEBUG: Found \(characteristics.count) characteristics)for characteristic in characteristics {switch characteristic.uuid {case CBUUID(string: Self.uartRxCharacteristicUUID):print(DEBUG: Found UART RX characteristic)self.uartRxCharacteristic  characteristiccase CBUUID(string: Self.uartTxCharacteristicUUID):print(DEBUG: Found UART TX characteristic)self.uartTxCharacteristic  characteristicperipheral.setNotifyValue(true, for: characteristic)default:print(DEBUG: Found other characteristic: \(characteristic.uuid))}}characteristicsDiscovered  true } 接收数据时 func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {if characteristic.uuid  CBUUID(string: Self.uartTxCharacteristicUUID) {if let value  characteristic.value {print(Received value: \(value))}} } 发送命令后 func peripheral(_ peripheral: CBPeripheral, didWriteValueFor characteristic: CBCharacteristic, error: Error?) {if let error  error {print(Write to characteristic failed: \(error.localizedDescription))} else {print(Write to characteristic successful)} } 完整代码 完整的 RingSessionManager 类代码如下 import Foundation import AccessorySetupKit import CoreBluetooth import SwiftUIObservable class RingSessionManager: NSObject {var peripheralConnected  falsevar pickerDismissed  truevar currentRing: ASAccessory?private var session  ASAccessorySession()private var manager: CBCentralManager?private var peripheral: CBPeripheral?private var uartRxCharacteristic: CBCharacteristic?private var uartTxCharacteristic: CBCharacteristic?private static let ringServiceUUID  6E40FFF0-B5A3-F393-E0A9-E50E24DCCA9Eprivate static let uartRxCharacteristicUUID  6E400002-B5A3-F393-E0A9-E50E24DCCA9Eprivate static let uartTxCharacteristicUUID  6E400003-B5A3-F393-E0A9-E50E24DCCA9Eprivate static let deviceInfoServiceUUID  0000180A-0000-1000-8000-00805F9B34FBprivate static let deviceHardwareUUID  00002A27-0000-1000-8000-00805F9B34FBprivate static let deviceFirmwareUUID  00002A26-0000-1000-8000-00805F9B34FBprivate static let ring: ASPickerDisplayItem  {let descriptor  ASDiscoveryDescriptor()descriptor.bluetoothServiceUUID  CBUUID(string: ringServiceUUID)return ASPickerDisplayItem(name: COLMI R02 Ring,productImage: UIImage(named: colmi)!,descriptor: descriptor)}()private var characteristicsDiscovered  falseoverride init() {super.init()self.session.activate(on: DispatchQueue.main, eventHandler: handleSessionEvent(event:))}// MARK: - RingSessionManager actionsfunc presentPicker() {session.showPicker(for: [Self.ring]) { error inif let error {print(Failed to show picker due to: \(error.localizedDescription))}}}func removeRing() {guard let currentRing else { return }if peripheralConnected {disconnect()}session.removeAccessory(currentRing) { _ inself.currentRing  nilself.manager  nil}}func connect() {guardlet manager, manager.state  .poweredOn,let peripheralelse {return}let options: [String: Any]  [CBConnectPeripheralOptionNotifyOnConnectionKey: true,CBConnectPeripheralOptionNotifyOnDisconnectionKey: true,CBConnectPeripheralOptionStartDelayKey: 1]manager.connect(peripheral, options: options)}func disconnect() {guard let peripheral, let manager else { return }manager.cancelPeripheralConnection(peripheral)}// MARK: - ASAccessorySession functionsprivate func saveRing(ring: ASAccessory) {currentRing  ringif manager  nil {manager  CBCentralManager(delegate: self, queue: nil)}}private func handleSessionEvent(event: ASAccessoryEvent) {switch event.eventType {case .accessoryAdded, .accessoryChanged:guard let ring  event.accessory else { return }saveRing(ring: ring)case .activated:guard let ring  session.accessories.first else { return }saveRing(ring: ring)case .accessoryRemoved:self.currentRing  nilself.manager  nilcase .pickerDidPresent:pickerDismissed  falsecase .pickerDidDismiss:pickerDismissed  truedefault:print(Received event type \(event.eventType))}} }// MARK: - CBCentralManagerDelegate extension RingSessionManager: CBCentralManagerDelegate {func centralManagerDidUpdateState(_ central: CBCentralManager) {print(Central manager state: \(central.state))switch central.state {case .poweredOn:if let peripheralUUID  currentRing?.bluetoothIdentifier {if let knownPeripheral  central.retrievePeripherals(withIdentifiers: [peripheralUUID]).first {print(Found previously connected peripheral)peripheral  knownPeripheralperipheral?.delegate  selfconnect()} else {print(Known peripheral not found, starting scan)}}default:peripheral  nil}}func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {print(DEBUG: Connected to peripheral: \(peripheral))peripheral.delegate  selfprint(DEBUG: Discovering services...)peripheral.discoverServices([CBUUID(string: Self.ringServiceUUID)])peripheralConnected  true}func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: (any Error)?) {print(Disconnected from peripheral: \(peripheral))peripheralConnected  falsecharacteristicsDiscovered  false}func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: (any Error)?) {print(Failed to connect to peripheral: \(peripheral), error: \(error.debugDescription))} }// MARK: - CBPeripheralDelegate extension RingSessionManager: CBPeripheralDelegate {func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: (any Error)?) {print(DEBUG: Services discovery callback, error: \(String(describing: error)))guard error  nil, let services  peripheral.services else {print(DEBUG: No services found or error occurred)return}print(DEBUG: Found \(services.count) services)for service in services {if service.uuid  CBUUID(string: Self.ringServiceUUID) {print(DEBUG: Found ring service, discovering characteristics...)peripheral.discoverCharacteristics([CBUUID(string: Self.uartRxCharacteristicUUID),CBUUID(string: Self.uartTxCharacteristicUUID)], for: service)}}}func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {print(DEBUG: Characteristics discovery callback, error: \(String(describing: error)))guard error  nil, let characteristics  service.characteristics else {print(DEBUG: No characteristics found or error occurred)return}print(DEBUG: Found \(characteristics.count) characteristics)for characteristic in characteristics {switch characteristic.uuid {case CBUUID(string: Self.uartRxCharacteristicUUID):print(DEBUG: Found UART RX characteristic)self.uartRxCharacteristic  characteristiccase CBUUID(string: Self.uartTxCharacteristicUUID):print(DEBUG: Found UART TX characteristic)self.uartTxCharacteristic  characteristicperipheral.setNotifyValue(true, for: characteristic)default:print(DEBUG: Found other characteristic: \(characteristic.uuid))}}characteristicsDiscovered  true}func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {if characteristic.uuid  CBUUID(string: Self.uartTxCharacteristicUUID) {if let value  characteristic.value {print(Received value: \(value))}}}func peripheral(_ peripheral: CBPeripheral, didWriteValueFor characteristic: CBCharacteristic, error: Error?) {if let error  error {print(Write to characteristic failed: \(error.localizedDescription))} else {print(Write to characteristic successful)}} } 最后一步将其应用到我们的应用程序中 在 ContentView.swift 中粘贴以下代码作为主界面的一部分 import SwiftUI import AccessorySetupKitstruct ContentView: View {State var ringSessionManager  RingSessionManager()var body: some View {List {Section(MY DEVICE, content: {if ringSessionManager.pickerDismissed, let currentRing  ringSessionManager.currentRing {makeRingView(ring: currentRing)} else {Button {ringSessionManager.presentPicker()} label: {Text(Add Ring).frame(maxWidth: .infinity).font(Font.headline.weight(.semibold))}}})}.listStyle(.insetGrouped)}ViewBuilderprivate func makeRingView(ring: ASAccessory) - some View {HStack {Image(colmi).resizable().aspectRatio(contentMode: .fit).frame(height: 70)VStack(alignment: .leading) {Text(ring.displayName).font(Font.headline.weight(.semibold))}}} }#Preview {ContentView() } 如果一切配置正确你现在可以构建并运行应用。当点击“Add Ring”按钮时将弹出一个界面显示附近的兼容设备 (包括 COLMI R02 戒指) 。选择设备后应用即可完成连接。 连接演示 在后续的文章中我们将进一步探索如何与戒指交互包括读取电池电量、获取传感器数据 (如 PPG 和加速度计) 并基于这些数据开发实时心率监测、活动追踪及睡眠检测功能。敬请期待 英文原文:https://hf.co/blog/cyrilzakka/halo-introduction 原文作者: Cyril, ML Researcher, Health AI Lead Hugging Face 译者: Lu Cheng, Hugging Face Fellow
http://www.hkea.cn/news/14390801/

相关文章:

  • 移动端ui设计是什么wordpress 优化数据
  • 做静态网站的参考文献找个人做网站
  • 带数据库网站模板深圳有哪些做网站公司好
  • 云服务器怎么建网站五个跨境电商平台
  • 网网站制作开发谁用腾讯风铃做网站的
  • 盐城网站开发招代理网站建设需要什么软件
  • 图片站wordpress有哪些网站做外贸的
  • 网站设计制作系统哪个好wordpress 图文
  • 东港区建设局网站seo专员是什么职位
  • 小语种网站怎么设计沈阳专业做网站
  • 手机资讯网站源码建设企业网站管理的重要性
  • 学院网站建设的目的WordPress邮箱验证 注册
  • 宿松做网站策划运营
  • 做一个15页的网站怎么做如何做好网络营销工作
  • 网站建设网站推广网站建设各模块功能简述
  • 沧州做家装的公司网站邯郸网络用语
  • 北京海淀建设局搜索引擎优化的流程
  • 常州模板网站建设喜欢做木工 网站
  • 建站专家商贸公司网站建设极致发烧
  • 无锡开发网站建设o2o有哪些电商平台
  • 哪个商城网站建设好中国建设银行上海分行信息网站
  • 摄影师做展示的网站中国猎头公司前十名
  • 成功的微网站广州网站建设推广易尚
  • wordpress音乐网站主题个人网站icp
  • 上海网站建设 paiky图片处理软件
  • 舟山市普陀区建设局网站国外免费服务器ip大全
  • wordpress 网站禁用全屏代码中国房地产未来走向
  • 信阳网站建设哪家好上海闵行区邮编
  • 网站说服力-营销型网站策划网站开发开票交税
  • 什么网站做展板的多wordpress 电子书主题