cmd_key_event.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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. play: 'play',
  53. pause: 'pause',
  54. stop: 'stop',
  55. completed: 'completed'
  56. };
  57. // 设备操作类
  58. class CmdEvent {
  59. constructor({ cmdEvent }) {
  60. this.cmdEvent = cmdEvent;
  61. this.channelId = 1;
  62. this.wakeSwitch = null;
  63. this.wakeCycle = [0, 0, 0, 0, 0, 0, 0];
  64. this.ctrlStatus = [0, 0, 0];
  65. this.lowPowerOpen = null;
  66. this.wakeHour = null;
  67. this.wakeMinutes = null;
  68. this.sleepSwitch = null;
  69. this.sleepHour = null;
  70. this.sleepMinutes = null;
  71. this.kwh = 9;
  72. this.kwhLeft = 9;
  73. this.kwhRight = 9;
  74. this.kwhBox = 9;
  75. this.lowKwnSet = false;
  76. this.volume = 0;
  77. this.version = "1.0.0";
  78. this.dsn = null;
  79. this.playStatus = null;
  80. this.playInfo = null;
  81. this.authInfo = null;
  82. this.item = null;
  83. this.eSim = null;
  84. this.sim = null;
  85. this.simIndex = null;
  86. this.enableTTS = null;
  87. this.eqs = null;
  88. this.lowDelayMode = null;
  89. this.lowDelayModeOpen = null;
  90. this.netModeAuto = null;
  91. this.pauseSleep = null;
  92. this.collectStatus = null;
  93. this.audioInfoId = null;
  94. this.todayStep = null;
  95. this.todayRates = null;
  96. this.stepTarget = null;
  97. this.setTimeFormat = null;
  98. this.setQuickViewTime = null;
  99. this.setNotDisturb = null;
  100. this.openPush = null;
  101. this.takeHandLight = null;
  102. this.stepDistance = null;
  103. this.stepCalories = null;
  104. this.stepTime = null;
  105. this.payId = null;
  106. this.btMac = null;
  107. this.deviceMode = null;
  108. }
  109. static wake({ wakeSwitch, wakeCycle, wakeHour, wakeMinutes }) {
  110. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.wake });
  111. event.wakeSwitch = wakeSwitch;
  112. event.wakeCycle = wakeCycle;
  113. event.wakeHour = wakeHour;
  114. event.wakeMinutes = wakeMinutes;
  115. return event;
  116. }
  117. static sim({ eSim, sim, simIndex }) {
  118. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.sim });
  119. event.eSim = eSim;
  120. event.sim = sim;
  121. event.simIndex = simIndex;
  122. return event;
  123. }
  124. static sleep({ sleepSwitch, sleepHour, sleepMinutes }) {
  125. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.sleep });
  126. event.sleepSwitch = sleepSwitch;
  127. event.sleepHour = sleepHour;
  128. event.sleepMinutes = sleepMinutes;
  129. return event;
  130. }
  131. static ctrlStatus({ ctrlStatus }) {
  132. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.ctrlStatus });
  133. event.ctrlStatus = ctrlStatus;
  134. return event;
  135. }
  136. static switchChannel({ channelId }) {
  137. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.switchChannel });
  138. event.channelId = channelId;
  139. return event;
  140. }
  141. static switchDeviceMode({ deviceMode }) {
  142. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.switchDeviceMode });
  143. event.deviceMode = deviceMode;
  144. return event;
  145. }
  146. static enableTTS({ enableTTS }) {
  147. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.enableTTS });
  148. event.enableTTS = enableTTS;
  149. return event;
  150. }
  151. static battery({ kwh }) {
  152. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.battery });
  153. event.kwh = kwh;
  154. return event;
  155. }
  156. static queryLowKwn({ kwh }) {
  157. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.lowKwnSet });
  158. event.kwh = kwh;
  159. return event;
  160. }
  161. static dsn({ dsn }) {
  162. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.dsn });
  163. event.dsn = dsn;
  164. return event;
  165. }
  166. static getDeviceInfo() {
  167. return new CmdEvent({ cmdEvent: EnumCmdEvent.getDeviceInfo });
  168. }
  169. static todayStep({ todayStep, stepDistance, stepCalories, stepTime }) {
  170. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.todayStep });
  171. event.todayStep = todayStep;
  172. event.stepDistance = stepDistance;
  173. event.stepCalories = stepCalories;
  174. event.stepTime = stepTime;
  175. return event;
  176. }
  177. static todaySport({ todayStep, stepDistance, stepCalories, stepTime }) {
  178. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.todayStep });
  179. event.todayStep = todayStep;
  180. event.stepDistance = stepDistance;
  181. event.stepCalories = stepCalories;
  182. event.stepTime = stepTime;
  183. return event;
  184. }
  185. static todayRates({ todayRates }) {
  186. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.todayRates });
  187. event.todayRates = todayRates;
  188. return event;
  189. }
  190. static pauseSleep({ pauseSleep }) {
  191. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.authSleepStatus });
  192. event.pauseSleep = pauseSleep;
  193. return event;
  194. }
  195. static targetSteps({ stepTarget }) {
  196. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.targetSteps });
  197. event.stepTarget = stepTarget;
  198. return event;
  199. }
  200. static setTimeFormat({ setTimeFormat }) {
  201. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.setTimeFormat });
  202. event.setTimeFormat = setTimeFormat;
  203. return event;
  204. }
  205. static setNotDisturb({ setNotDisturb }) {
  206. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.setNotDisturb });
  207. event.setNotDisturb = setNotDisturb;
  208. return event;
  209. }
  210. static setQuickViewTime({ setQuickViewTime }) {
  211. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.setQuickViewTime });
  212. event.setQuickViewTime = setQuickViewTime;
  213. return event;
  214. }
  215. static openPush({ openPush }) {
  216. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.openPush });
  217. event.openPush = openPush;
  218. return event;
  219. }
  220. static takeHandLight({ takeHandLight }) {
  221. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.takeHandLight });
  222. event.takeHandLight = takeHandLight;
  223. return event;
  224. }
  225. static batteryEarphone({ kwh, kwhLeft, kwhRight, kwhBox }) {
  226. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.batteryEarphone });
  227. event.kwh = kwh;
  228. event.kwhLeft = kwhLeft;
  229. event.kwhRight = kwhRight;
  230. event.kwhBox = kwhBox;
  231. return event;
  232. }
  233. static unbind({ item }) {
  234. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.unbind });
  235. event.item = item;
  236. return event;
  237. }
  238. static auth({ authInfo }) {
  239. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.auth });
  240. event.authInfo = authInfo;
  241. return event;
  242. }
  243. static eqs({ eqs }) {
  244. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.eq });
  245. event.eqs = eqs;
  246. return event;
  247. }
  248. static lowDelayMode({ lowDelayMode, lowDelayModeOpen }) {
  249. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.lowDelayMode });
  250. event.lowDelayMode = lowDelayMode;
  251. event.lowDelayModeOpen = lowDelayModeOpen;
  252. return event;
  253. }
  254. static lowPowerOpen({ lowPowerOpen }) {
  255. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.lowPowerOpen });
  256. event.lowPowerOpen = lowPowerOpen;
  257. return event;
  258. }
  259. static volume({ volume }) {
  260. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.volume });
  261. event.volume = volume;
  262. return event;
  263. }
  264. static version({ version }) {
  265. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.version });
  266. event.version = version;
  267. return event;
  268. }
  269. static btMac({ btMac }) {
  270. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.btMac });
  271. event.btMac = btMac;
  272. return event;
  273. }
  274. static netModeAuto({ netModeAuto }) {
  275. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.netModeAuto });
  276. event.netModeAuto = netModeAuto;
  277. return event;
  278. }
  279. static playInfo({ playInfo }) {
  280. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.playInfo });
  281. event.playInfo = playInfo;
  282. return event;
  283. }
  284. static payId({ payId }) {
  285. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.payId });
  286. event.payId = payId;
  287. return event;
  288. }
  289. static collectState({ collectStatus, audioInfoId }) {
  290. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.collectState });
  291. event.collectStatus = collectStatus;
  292. event.audioInfoId = audioInfoId;
  293. return event;
  294. }
  295. static playStatus({ playStatus }) {
  296. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.playStatus });
  297. switch (playStatus) {
  298. case 1:
  299. event.playStatus = EnumPlayStatus.play;
  300. break;
  301. case 2:
  302. event.playStatus = EnumPlayStatus.pause;
  303. break;
  304. case 3:
  305. event.playStatus = EnumPlayStatus.stop;
  306. break;
  307. case 4:
  308. event.playStatus = EnumPlayStatus.completed;
  309. break;
  310. default:
  311. }
  312. return event
  313. }
  314. toString() {
  315. 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}}`;
  316. }
  317. }