@ray-js/lamp-schedule-core 1.0.0-beta-1 → 1.0.0-beta-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/dpParser/cycle/index.d.ts +6 -0
- package/lib/dpParser/cycle/index.js +74 -68
- package/lib/dpParser/random/index.d.ts +6 -0
- package/lib/dpParser/random/index.js +108 -97
- package/lib/dpParser/rhythms.d.ts +1 -32
- package/lib/dpParser/rhythms.js +41 -36
- package/lib/dpParser/rtcTimer.js +201 -191
- package/lib/dpParser/sleep/sleepCommon.js +88 -91
- package/lib/dpParser/timerReport.js +22 -10
- package/lib/dpParser/wakeup/wakeupCommon.js +85 -75
- package/package.json +1 -1
|
@@ -2,6 +2,8 @@ import "core-js/modules/esnext.iterator.constructor.js";
|
|
|
2
2
|
import "core-js/modules/esnext.iterator.for-each.js";
|
|
3
3
|
import "core-js/modules/esnext.iterator.map.js";
|
|
4
4
|
import _padStart from 'lodash/padStart';
|
|
5
|
+
import { scheduleLogger as ScheduleLogger } from '../utils/ScheduleLogger';
|
|
6
|
+
|
|
5
7
|
// 补充工具函数
|
|
6
8
|
const numToHexString = function () {
|
|
7
9
|
let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
@@ -15,7 +17,10 @@ export class TimerReportFormatter {
|
|
|
15
17
|
}
|
|
16
18
|
parser() {
|
|
17
19
|
let val = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
18
|
-
if (val) {
|
|
20
|
+
if (!val) {
|
|
21
|
+
return this.defaultValue;
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
19
24
|
const arr = [];
|
|
20
25
|
const strArr = val.match(/[a-z0-9]{2}/g);
|
|
21
26
|
strArr.forEach(item => {
|
|
@@ -26,18 +31,25 @@ export class TimerReportFormatter {
|
|
|
26
31
|
});
|
|
27
32
|
});
|
|
28
33
|
return arr;
|
|
34
|
+
} catch (error) {
|
|
35
|
+
ScheduleLogger.error('TimerReportFormatter parser error', error);
|
|
36
|
+
return this.defaultValue;
|
|
29
37
|
}
|
|
30
|
-
return this.defaultValue;
|
|
31
38
|
}
|
|
32
39
|
formatter(tasks) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
try {
|
|
41
|
+
return tasks.map(task => {
|
|
42
|
+
// 组装ABBBBBBB
|
|
43
|
+
const binStr = (task.status ? '1' : '0') +
|
|
44
|
+
// A位
|
|
45
|
+
(+task.id).toString(2).padStart(7, '0'); // BBBBBBB
|
|
46
|
+
const hexStr = numToHexString(parseInt(binStr, 2));
|
|
47
|
+
return hexStr;
|
|
48
|
+
}).join('');
|
|
49
|
+
} catch (error) {
|
|
50
|
+
ScheduleLogger.error('TimerReportFormatter formatter error', error);
|
|
51
|
+
return '';
|
|
52
|
+
}
|
|
41
53
|
}
|
|
42
54
|
}
|
|
43
55
|
export const timerReportParser = new TimerReportFormatter();
|
|
@@ -17,90 +17,100 @@ export class WakeUp {
|
|
|
17
17
|
nodes: []
|
|
18
18
|
};
|
|
19
19
|
parser(dpStr) {
|
|
20
|
-
var _dpStr$slice;
|
|
21
20
|
scheduleLogger.debug('WakeUp parser dpStr: ', dpStr);
|
|
22
21
|
if (!dpStr) {
|
|
23
22
|
return this.defaultValue;
|
|
24
23
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
24
|
+
try {
|
|
25
|
+
var _dpStr$slice;
|
|
26
|
+
const step = generateDpStrStep(dpStr);
|
|
27
|
+
const version = step(2).value;
|
|
28
|
+
let number = step(2).value;
|
|
29
|
+
const nodeLen = (_dpStr$slice = dpStr.slice(4)) === null || _dpStr$slice === void 0 ? void 0 : _dpStr$slice.length;
|
|
30
|
+
if (nodeLen % 24 !== 0) {
|
|
31
|
+
scheduleLogger.error('wakeup dpStr error nodeLen:', nodeLen);
|
|
32
|
+
}
|
|
33
|
+
const nodes = [];
|
|
34
|
+
number = Math.min(number, 4);
|
|
35
|
+
// 解析循环节点
|
|
36
|
+
for (let i = 0; i < number; i++) {
|
|
37
|
+
const onOff = !!step(2).value;
|
|
38
|
+
const repeatInt = step(2).value; // 单次定时任务bit0-bit6全为0,bit0-bit6某位为1时,表示对应周几周期定时 bit0 => 周日
|
|
39
|
+
const loops = padEnd(repeatInt.toString(2).split('').reverse().join(''), 7, '0');
|
|
40
|
+
const stepNum = step(2).value;
|
|
41
|
+
const hour = step(2).value;
|
|
42
|
+
const minute = step(2).value;
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
44
|
+
// 解析色相值(组合百位和十个位)
|
|
45
|
+
const hundreds = step(2).value;
|
|
46
|
+
const tensOnes = step(2).value;
|
|
47
|
+
const saturation = step(2).value;
|
|
48
|
+
const val = step(2).value;
|
|
49
|
+
const brightness = step(2).value;
|
|
50
|
+
const temperature = step(2).value;
|
|
51
|
+
const durationStep = step(2);
|
|
52
|
+
const duration = durationStep.value;
|
|
53
|
+
nodes.push({
|
|
54
|
+
onOff,
|
|
55
|
+
loops,
|
|
56
|
+
step: stepNum,
|
|
57
|
+
hour,
|
|
58
|
+
minute,
|
|
59
|
+
hue: Math.round(hundreds * 100 + tensOnes),
|
|
60
|
+
// 0-360
|
|
61
|
+
saturation,
|
|
62
|
+
value: val,
|
|
63
|
+
brightness,
|
|
64
|
+
temperature,
|
|
65
|
+
duration,
|
|
66
|
+
index: i
|
|
67
|
+
});
|
|
68
|
+
if (durationStep.done) {
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
69
71
|
}
|
|
72
|
+
return {
|
|
73
|
+
version,
|
|
74
|
+
number,
|
|
75
|
+
nodes
|
|
76
|
+
};
|
|
77
|
+
} catch (error) {
|
|
78
|
+
scheduleLogger.error('wakeup parser error', error);
|
|
79
|
+
return this.defaultValue;
|
|
70
80
|
}
|
|
71
|
-
return {
|
|
72
|
-
version,
|
|
73
|
-
number,
|
|
74
|
-
nodes
|
|
75
|
-
};
|
|
76
81
|
}
|
|
77
82
|
formatter(data) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
83
|
+
try {
|
|
84
|
+
var _data$nodes, _data$nodes2;
|
|
85
|
+
const result = [numToHexString(data.version), numToHexString((_data$nodes = data.nodes) === null || _data$nodes === void 0 ? void 0 : _data$nodes.length)];
|
|
86
|
+
scheduleLogger.debug('wakeup formatter data', data);
|
|
87
|
+
data === null || data === void 0 || (_data$nodes2 = data.nodes) === null || _data$nodes2 === void 0 || _data$nodes2.forEach(node => {
|
|
88
|
+
// 拆分色相值为百位和十个位
|
|
89
|
+
const hueHundreds = Math.floor(node.hue / 100);
|
|
90
|
+
const hueTensOnes = node.hue % 100;
|
|
91
|
+
const {
|
|
92
|
+
saturation,
|
|
93
|
+
value,
|
|
94
|
+
brightness,
|
|
95
|
+
temperature
|
|
96
|
+
} = node;
|
|
97
|
+
let saturation1 = node.saturation;
|
|
98
|
+
let value1 = node.value;
|
|
99
|
+
let brightness1 = node.brightness;
|
|
100
|
+
let temperature1 = node.temperature;
|
|
101
|
+
if (saturation === 0 && value === 0 && brightness === 0 && temperature === 0) {
|
|
102
|
+
saturation1 = defaultColor.saturation;
|
|
103
|
+
value1 = defaultColor.value;
|
|
104
|
+
brightness1 = defaultColor.brightness;
|
|
105
|
+
temperature1 = defaultColor.temperature;
|
|
106
|
+
}
|
|
107
|
+
result.push(numToHexString(node.onOff ? 1 : 0), numToHexString(parseInt(node.loops.split('').reverse().join(''), 2), 2), numToHexString(node.step), numToHexString(node.hour), numToHexString(node.minute), numToHexString(hueHundreds), numToHexString(hueTensOnes), numToHexString(saturation1), numToHexString(value1), numToHexString(brightness1), numToHexString(temperature1), numToHexString(node.duration));
|
|
108
|
+
});
|
|
109
|
+
return result.join('');
|
|
110
|
+
} catch (error) {
|
|
111
|
+
scheduleLogger.error('wakeup formatter error', error);
|
|
112
|
+
return '';
|
|
113
|
+
}
|
|
104
114
|
}
|
|
105
115
|
}
|
|
106
116
|
export const wakeupParser = new WakeUp();
|