cmd_key_event.js 12 KB

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