device_controller_manager.dart 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import 'package:vitalapp/pages/medical/controllers/base.dart';
  2. import 'package:vnote_device_plugin/consts/types.dart';
  3. import 'package:vnote_device_plugin/devices/base.dart';
  4. import 'package:fis_common/logger/logger.dart';
  5. import 'package:vnote_device_plugin/devices/heart.dart';
  6. import 'package:vnote_device_plugin/devices/ic_reader.dart';
  7. import 'package:vnote_device_plugin/devices/nibp.dart';
  8. import 'package:vnote_device_plugin/devices/sp_o2.dart';
  9. import 'package:vnote_device_plugin/devices/sugar.dart';
  10. import 'package:vnote_device_plugin/devices/temp.dart';
  11. import 'package:vnote_device_plugin/devices/twelve_heart.dart';
  12. import 'package:vnote_device_plugin/devices/urine.dart';
  13. import 'package:vnote_device_plugin/devices/weight.dart';
  14. import 'package:vnote_device_plugin/devices/weight_height.dart';
  15. class DeviceControllerManager extends BaseDeviceController<DeviceWorkerBase> {
  16. DeviceControllerManager(
  17. this.type,
  18. super.model,
  19. super.mac,
  20. ) : super();
  21. final String type;
  22. DeviceWorkerBase? deviceWorker;
  23. @override
  24. DeviceWorkerBase createWorker() {
  25. if (deviceWorker != null) {
  26. logger.i('DeviceControllerManager:$type disconnect start');
  27. deviceWorker?.disconnect().then((value) {
  28. logger.i('DeviceControllerManager:$type disconnect end');
  29. deviceWorker?.dispose();
  30. logger.i('DeviceControllerManager:$type dispose');
  31. });
  32. }
  33. logger.i('DeviceControllerManager:$type create');
  34. print('DeviceControllerManager:$type create');
  35. return _createWorker();
  36. }
  37. @override
  38. void dispose() {
  39. super.dispose();
  40. deviceWorker = null;
  41. logger.i('DeviceControllerManager:$type dispose');
  42. print('DeviceControllerManager:$type dispose');
  43. }
  44. DeviceWorkerBase _createWorker() {
  45. switch (type) {
  46. //体重
  47. case DeviceTypes.WEIGHT:
  48. deviceWorker = WeightDeviceWorker(mac: super.mac, model: model);
  49. break;
  50. //心率
  51. case DeviceTypes.HEART:
  52. deviceWorker = HeartDeviceWorker(mac: super.mac, model: model);
  53. break;
  54. //血压
  55. case DeviceTypes.NIBP:
  56. deviceWorker = NibpDeviceWorker(mac: super.mac, model: model);
  57. break;
  58. //血氧
  59. case DeviceTypes.SPO2:
  60. deviceWorker = SpO2DeviceWorker(mac: super.mac, model: model);
  61. break;
  62. //血糖
  63. case DeviceTypes.SUGAR:
  64. deviceWorker = SugarDeviceWorker(mac: super.mac, model: model);
  65. break;
  66. //温度
  67. case DeviceTypes.TEMP:
  68. deviceWorker = TempDeviceWorker(mac: super.mac, model: model);
  69. break;
  70. //尿常规
  71. case DeviceTypes.URINE:
  72. deviceWorker = UrineDeviceWorker(mac: super.mac, model: model);
  73. break;
  74. case DeviceTypes.IC_READER:
  75. deviceWorker = ICReaderDeviceWorker(mac: super.mac, model: model);
  76. break;
  77. case DeviceTypes.TWELVEHEART:
  78. deviceWorker = TwelveHeartDeviceWorker(mac: super.mac, model: model);
  79. break;
  80. case DeviceTypes.WEIGHTHEIGHT:
  81. deviceWorker = WeightHeightDeviceWorker(mac: super.mac, model: model);
  82. break;
  83. }
  84. return deviceWorker!;
  85. }
  86. }