cmd_key_event.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. // 枚举定义
  2. const EnumCmdEvent = {
  3. nextChannel: 'nextChannel',
  4. previousChannel: 'previousChannel',
  5. switchChannel: 'switchChannel',
  6. previousAlbum: 'previousAlbum',
  7. nextAlbum: 'nextAlbum',
  8. nextSong: 'nextSong',
  9. previousSong: 'previousSong',
  10. speed: 'speed',
  11. fastback: 'fastback',
  12. stopSpeed: 'stopSpeed',
  13. stopFastback: 'stopFastback',
  14. startRecord: 'startRecord',
  15. stopRecord: 'stopRecord',
  16. battery: 'battery',
  17. lowKwnSet: 'lowKwnSet',
  18. batteryEarphone: 'batteryEarphone',
  19. ctrlStatus: 'ctrlStatus',
  20. lowPowerOpen: 'lowPowerOpen',
  21. eq: 'eq',
  22. lowDelayMode: 'lowDelayMode',
  23. sleep: 'sleep',
  24. wake: 'wake',
  25. volume: 'volume',
  26. version: 'version',
  27. sim: 'sim',
  28. dsn: 'dsn',
  29. playInfo: 'playInfo',
  30. playStatus: 'playStatus',
  31. auth: 'auth',
  32. unbind: 'unbind',
  33. enableTTS: 'enableTTS',
  34. switchDeviceMode: 'switchDeviceMode',
  35. netModeAuto: 'netModeAuto',
  36. getDeviceInfo: 'getDeviceInfo',
  37. collectState: 'collectState',
  38. todayStep: 'todayStep',
  39. todayRates: 'todayRates',
  40. targetSteps: 'targetSteps',
  41. setTimeFormat: 'setTimeFormat',
  42. setNotDisturb: 'setNotDisturb',
  43. setQuickViewTime: 'setQuickViewTime',
  44. openPush: 'openPush',
  45. takeHandLight: 'takeHandLight',
  46. payId: 'payId',
  47. authSleepStatus: 'authSleepStatus',
  48. btMac: 'btMac'
  49. };
  50. // 枚举定义
  51. const EnumPlayStatus = {
  52. none: 'none',
  53. play: 'play',
  54. pause: 'pause',
  55. stop: 'stop',
  56. completed: 'completed',
  57. error: 'error',
  58. buffering: 'buffering', // APP自己定义的特殊处理中间状态
  59. };
  60. // 或者使用对象字面量
  61. const EnumSupplier = {
  62. shanJing: "ShanJing",
  63. jieLi: "JieLi",
  64. lingXin: "LingXin",
  65. qiXinWei: "QiXinWei"
  66. };
  67. // 设备操作类
  68. class CmdEvent {
  69. constructor({ cmdEvent }) {
  70. this.cmdEvent = cmdEvent;
  71. this.channelId = 1;
  72. this.wakeSwitch = null;
  73. this.wakeCycle = [0, 0, 0, 0, 0, 0, 0];
  74. this.ctrlStatus = [0, 0, 0];
  75. this.lowPowerOpen = null;
  76. this.wakeHour = null;
  77. this.wakeMinutes = null;
  78. this.sleepSwitch = null;
  79. this.sleepHour = null;
  80. this.sleepMinutes = null;
  81. this.kwh = 9;
  82. this.kwhLeft = 9;
  83. this.kwhRight = 9;
  84. this.kwhBox = 9;
  85. this.lowKwnSet = false;
  86. this.volume = 0;
  87. this.version = "1.0.0";
  88. this.dsn = null;
  89. this.playStatus = null;
  90. this.playInfo = null;
  91. this.authInfo = null;
  92. this.item = null;
  93. this.eSim = null;
  94. this.sim = null;
  95. this.simIndex = null;
  96. this.enableTTS = null;
  97. this.eqs = null;
  98. this.lowDelayMode = null;
  99. this.lowDelayModeOpen = null;
  100. this.netModeAuto = null;
  101. this.pauseSleep = null;
  102. this.collectStatus = null;
  103. this.audioInfoId = null;
  104. this.todayStep = null;
  105. this.todayRates = null;
  106. this.stepTarget = null;
  107. this.setTimeFormat = null;
  108. this.setQuickViewTime = null;
  109. this.setNotDisturb = null;
  110. this.openPush = null;
  111. this.takeHandLight = null;
  112. this.stepDistance = null;
  113. this.stepCalories = null;
  114. this.stepTime = null;
  115. this.payId = null;
  116. this.btMac = null;
  117. this.deviceMode = null;
  118. }
  119. static eventName = "cmdEventNotification"
  120. static wake({ wakeSwitch, wakeCycle, wakeHour, wakeMinutes }) {
  121. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.wake });
  122. event.wakeSwitch = wakeSwitch;
  123. event.wakeCycle = wakeCycle;
  124. event.wakeHour = wakeHour;
  125. event.wakeMinutes = wakeMinutes;
  126. return event;
  127. }
  128. static sim({ eSim, sim, simIndex }) {
  129. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.sim });
  130. event.eSim = eSim;
  131. event.sim = sim;
  132. event.simIndex = simIndex;
  133. return event;
  134. }
  135. static sleep({ sleepSwitch, sleepHour, sleepMinutes }) {
  136. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.sleep });
  137. event.sleepSwitch = sleepSwitch;
  138. event.sleepHour = sleepHour;
  139. event.sleepMinutes = sleepMinutes;
  140. return event;
  141. }
  142. static ctrlStatus({ ctrlStatus }) {
  143. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.ctrlStatus });
  144. event.ctrlStatus = ctrlStatus;
  145. return event;
  146. }
  147. static switchChannel({ channelId }) {
  148. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.switchChannel });
  149. event.channelId = channelId;
  150. return event;
  151. }
  152. static switchDeviceMode({ deviceMode }) {
  153. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.switchDeviceMode });
  154. event.deviceMode = deviceMode;
  155. return event;
  156. }
  157. static enableTTS({ enableTTS }) {
  158. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.enableTTS });
  159. event.enableTTS = enableTTS;
  160. return event;
  161. }
  162. static battery({ kwh }) {
  163. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.battery });
  164. event.kwh = kwh;
  165. return event;
  166. }
  167. static queryLowKwn({ kwh }) {
  168. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.lowKwnSet });
  169. event.kwh = kwh;
  170. return event;
  171. }
  172. static dsn({ dsn }) {
  173. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.dsn });
  174. event.dsn = dsn;
  175. return event;
  176. }
  177. static getDeviceInfo() {
  178. return new CmdEvent({ cmdEvent: EnumCmdEvent.getDeviceInfo });
  179. }
  180. static todayStep({ todayStep, stepDistance, stepCalories, stepTime }) {
  181. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.todayStep });
  182. event.todayStep = todayStep;
  183. event.stepDistance = stepDistance;
  184. event.stepCalories = stepCalories;
  185. event.stepTime = stepTime;
  186. return event;
  187. }
  188. static todaySport({ todayStep, stepDistance, stepCalories, stepTime }) {
  189. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.todayStep });
  190. event.todayStep = todayStep;
  191. event.stepDistance = stepDistance;
  192. event.stepCalories = stepCalories;
  193. event.stepTime = stepTime;
  194. return event;
  195. }
  196. static todayRates({ todayRates }) {
  197. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.todayRates });
  198. event.todayRates = todayRates;
  199. return event;
  200. }
  201. static pauseSleep({ pauseSleep }) {
  202. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.authSleepStatus });
  203. event.pauseSleep = pauseSleep;
  204. return event;
  205. }
  206. static targetSteps({ stepTarget }) {
  207. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.targetSteps });
  208. event.stepTarget = stepTarget;
  209. return event;
  210. }
  211. static setTimeFormat({ setTimeFormat }) {
  212. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.setTimeFormat });
  213. event.setTimeFormat = setTimeFormat;
  214. return event;
  215. }
  216. static setNotDisturb({ setNotDisturb }) {
  217. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.setNotDisturb });
  218. event.setNotDisturb = setNotDisturb;
  219. return event;
  220. }
  221. static setQuickViewTime({ setQuickViewTime }) {
  222. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.setQuickViewTime });
  223. event.setQuickViewTime = setQuickViewTime;
  224. return event;
  225. }
  226. static openPush({ openPush }) {
  227. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.openPush });
  228. event.openPush = openPush;
  229. return event;
  230. }
  231. static takeHandLight({ takeHandLight }) {
  232. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.takeHandLight });
  233. event.takeHandLight = takeHandLight;
  234. return event;
  235. }
  236. static batteryEarphone({ kwh, kwhLeft, kwhRight, kwhBox }) {
  237. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.batteryEarphone });
  238. event.kwh = kwh;
  239. event.kwhLeft = kwhLeft;
  240. event.kwhRight = kwhRight;
  241. event.kwhBox = kwhBox;
  242. return event;
  243. }
  244. static unbind({ item }) {
  245. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.unbind });
  246. event.item = item;
  247. return event;
  248. }
  249. static auth({ authInfo }) {
  250. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.auth });
  251. event.authInfo = authInfo;
  252. return event;
  253. }
  254. static eqs({ eqs }) {
  255. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.eq });
  256. event.eqs = eqs;
  257. return event;
  258. }
  259. static lowDelayMode({ lowDelayMode, lowDelayModeOpen }) {
  260. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.lowDelayMode });
  261. event.lowDelayMode = lowDelayMode;
  262. event.lowDelayModeOpen = lowDelayModeOpen;
  263. return event;
  264. }
  265. static lowPowerOpen({ lowPowerOpen }) {
  266. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.lowPowerOpen });
  267. event.lowPowerOpen = lowPowerOpen;
  268. return event;
  269. }
  270. static volume({ volume }) {
  271. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.volume });
  272. event.volume = volume;
  273. return event;
  274. }
  275. static version({ version }) {
  276. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.version });
  277. event.version = version;
  278. return event;
  279. }
  280. static btMac({ btMac }) {
  281. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.btMac });
  282. event.btMac = btMac;
  283. return event;
  284. }
  285. static netModeAuto({ netModeAuto }) {
  286. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.netModeAuto });
  287. event.netModeAuto = netModeAuto;
  288. return event;
  289. }
  290. static playInfo({ playInfo }) {
  291. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.playInfo });
  292. event.playInfo = playInfo;
  293. return event;
  294. }
  295. static payId({ payId }) {
  296. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.payId });
  297. event.payId = payId;
  298. return event;
  299. }
  300. static collectState({ collectStatus, audioInfoId }) {
  301. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.collectState });
  302. event.collectStatus = collectStatus;
  303. event.audioInfoId = audioInfoId;
  304. return event;
  305. }
  306. static playStatus({ playStatus }) {
  307. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.playStatus });
  308. switch (playStatus) {
  309. case 1:
  310. event.playStatus = EnumPlayStatus.play;
  311. break;
  312. case 2:
  313. event.playStatus = EnumPlayStatus.pause;
  314. break;
  315. case 3:
  316. event.playStatus = EnumPlayStatus.stop;
  317. break;
  318. case 4:
  319. event.playStatus = EnumPlayStatus.completed;
  320. break;
  321. default:
  322. }
  323. return event
  324. }
  325. toString() {
  326. return `CmdEvent{cmdEvent: ${this.cmdEvent}, channelId: ${this.channelId}, wakeSwitch: ${this.wakeSwitch}, wakeCycle: ${this.wakeCycle}, wakeHour: ${this.wakeHour}, wakeMinutes: ${this.wakeMinutes}, sleepSwitch: ${this.sleepSwitch}, sleepHour: ${this.sleepHour}, sleepMinutes: ${this.sleepMinutes}, kwh: ${this.kwh}, volume: ${this.volume}, version: ${this.version}}`;
  327. }
  328. }
  329. module.exports = {
  330. CmdEvent,
  331. EnumCmdEvent,
  332. EnumPlayStatus,
  333. EnumSupplier
  334. };