1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.formatOutgoingCharacteristicValue = formatOutgoingCharacteristicValue;
|
4 | exports.isNumericFormat = isNumericFormat;
|
5 | exports.isUnsignedNumericFormat = isUnsignedNumericFormat;
|
6 | exports.isIntegerNumericFormat = isIntegerNumericFormat;
|
7 | exports.numericLowerBound = numericLowerBound;
|
8 | exports.numericUpperBound = numericUpperBound;
|
9 | function formatOutgoingCharacteristicValue(value, props) {
|
10 | if (typeof value === "boolean") {
|
11 | return value ? 1 : 0;
|
12 | }
|
13 | else if (typeof value === "number") {
|
14 | if (!props.minStep || props.minStep >= 1) {
|
15 | return value;
|
16 | }
|
17 | const base = props.minValue ?? 0;
|
18 | const inverse = 1 / props.minStep;
|
19 | return Math.round(((Math.round((value - base) * inverse) / inverse) + base) * 10000) / 10000;
|
20 | }
|
21 | return value;
|
22 | }
|
23 |
|
24 |
|
25 |
|
26 | function isNumericFormat(format) {
|
27 | switch (format) {
|
28 | case "int" :
|
29 | case "float" :
|
30 | case "uint8" :
|
31 | case "uint16" :
|
32 | case "uint32" :
|
33 | case "uint64" :
|
34 | return true;
|
35 | default:
|
36 | return false;
|
37 | }
|
38 | }
|
39 |
|
40 |
|
41 |
|
42 | function isUnsignedNumericFormat(format) {
|
43 | switch (format) {
|
44 | case "uint8" :
|
45 | case "uint16" :
|
46 | case "uint32" :
|
47 | case "uint64" :
|
48 | return true;
|
49 | default:
|
50 | return false;
|
51 | }
|
52 | }
|
53 |
|
54 |
|
55 |
|
56 | function isIntegerNumericFormat(format) {
|
57 | switch (format) {
|
58 | case "int" :
|
59 | case "uint8" :
|
60 | case "uint16" :
|
61 | case "uint32" :
|
62 | case "uint64" :
|
63 | return true;
|
64 | default:
|
65 | return false;
|
66 | }
|
67 | }
|
68 |
|
69 |
|
70 |
|
71 | function numericLowerBound(format) {
|
72 | switch (format) {
|
73 | case "int" :
|
74 | return -2147483648;
|
75 | case "float" :
|
76 | return -Number.MAX_VALUE;
|
77 | case "uint8" :
|
78 | case "uint16" :
|
79 | case "uint32" :
|
80 | case "uint64" :
|
81 | return 0;
|
82 | default:
|
83 | throw new Error("Unable to determine numeric lower bound for " + format);
|
84 | }
|
85 | }
|
86 |
|
87 |
|
88 |
|
89 | function numericUpperBound(format) {
|
90 | switch (format) {
|
91 | case "int" :
|
92 | return 2147483647;
|
93 | case "float" :
|
94 | return Number.MAX_VALUE;
|
95 | case "uint8" :
|
96 | return 255;
|
97 | case "uint16" :
|
98 | return 65535;
|
99 | case "uint32" :
|
100 | return 4294967295;
|
101 | case "uint64" :
|
102 |
|
103 | return 18446744073709551615;
|
104 | default:
|
105 | throw new Error("Unable to determine numeric lower bound for " + format);
|
106 | }
|
107 | }
|
108 |
|
\ | No newline at end of file |