| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,135 @@ |
| 1 |
+'use strict'; |
|
| 2 |
+ |
|
| 3 |
+/** |
|
| 4 |
+ * Batch update all the properties of an object. |
|
| 5 |
+ * @param {Object} obj
|
|
| 6 |
+ * @param {Object} descriptor
|
|
| 7 |
+ * @param {boolean} [descriptor.configurable]
|
|
| 8 |
+ * @param {boolean} [descriptor.enumerable]
|
|
| 9 |
+ * @param {*} [descriptor.value]
|
|
| 10 |
+ * @param {boolean} [descriptor.writable]
|
|
| 11 |
+ * @param {function} [descriptor.get]
|
|
| 12 |
+ * @param {function} [descriptor.set]
|
|
| 13 |
+ * @return {void}
|
|
| 14 |
+ */ |
|
| 15 |
+module.exports.updateProperties = function(obj, descriptor) {
|
|
| 16 |
+ Object.getOwnPropertyNames(obj).forEach(function(prop) {
|
|
| 17 |
+ Object.defineProperty(obj, prop, descriptor); |
|
| 18 |
+ }); |
|
| 19 |
+}; |
|
| 20 |
+ |
|
| 21 |
+module.exports.capabilityMap = {
|
|
| 22 |
+ PLATFORM_APLITE: {
|
|
| 23 |
+ platforms: ['aplite'], |
|
| 24 |
+ minFwMajor: 0, |
|
| 25 |
+ minFwMinor: 0 |
|
| 26 |
+ }, |
|
| 27 |
+ PLATFORM_BASALT: {
|
|
| 28 |
+ platforms: ['basalt'], |
|
| 29 |
+ minFwMajor: 0, |
|
| 30 |
+ minFwMinor: 0 |
|
| 31 |
+ }, |
|
| 32 |
+ PLATFORM_CHALK: {
|
|
| 33 |
+ platforms: ['chalk'], |
|
| 34 |
+ minFwMajor: 0, |
|
| 35 |
+ minFwMinor: 0 |
|
| 36 |
+ }, |
|
| 37 |
+ PLATFORM_DIORITE: {
|
|
| 38 |
+ platforms: ['diorite'], |
|
| 39 |
+ minFwMajor: 0, |
|
| 40 |
+ minFwMinor: 0 |
|
| 41 |
+ }, |
|
| 42 |
+ PLATFORM_EMERY: {
|
|
| 43 |
+ platforms: ['emery'], |
|
| 44 |
+ minFwMajor: 0, |
|
| 45 |
+ minFwMinor: 0 |
|
| 46 |
+ }, |
|
| 47 |
+ BW: {
|
|
| 48 |
+ platforms: ['aplite', 'diorite'], |
|
| 49 |
+ minFwMajor: 0, |
|
| 50 |
+ minFwMinor: 0 |
|
| 51 |
+ }, |
|
| 52 |
+ COLOR: {
|
|
| 53 |
+ platforms: ['basalt', 'chalk', 'emery'], |
|
| 54 |
+ minFwMajor: 0, |
|
| 55 |
+ minFwMinor: 0 |
|
| 56 |
+ }, |
|
| 57 |
+ MICROPHONE: {
|
|
| 58 |
+ platforms: ['basalt', 'chalk', 'diorite', 'emery'], |
|
| 59 |
+ minFwMajor: 0, |
|
| 60 |
+ minFwMinor: 0 |
|
| 61 |
+ }, |
|
| 62 |
+ SMARTSTRAP: {
|
|
| 63 |
+ platforms: ['basalt', 'chalk', 'diorite', 'emery'], |
|
| 64 |
+ minFwMajor: 3, |
|
| 65 |
+ minFwMinor: 4 |
|
| 66 |
+ }, |
|
| 67 |
+ SMARTSTRAP_POWER: {
|
|
| 68 |
+ platforms: ['basalt', 'chalk', 'emery'], |
|
| 69 |
+ minFwMajor: 3, |
|
| 70 |
+ minFwMinor: 4 |
|
| 71 |
+ }, |
|
| 72 |
+ HEALTH: {
|
|
| 73 |
+ platforms: ['basalt', 'chalk', 'diorite', 'emery'], |
|
| 74 |
+ minFwMajor: 3, |
|
| 75 |
+ minFwMinor: 10 |
|
| 76 |
+ }, |
|
| 77 |
+ RECT: {
|
|
| 78 |
+ platforms: ['aplite', 'basalt', 'diorite', 'emery'], |
|
| 79 |
+ minFwMajor: 0, |
|
| 80 |
+ minFwMinor: 0 |
|
| 81 |
+ }, |
|
| 82 |
+ ROUND: {
|
|
| 83 |
+ platforms: ['chalk'], |
|
| 84 |
+ minFwMajor: 0, |
|
| 85 |
+ minFwMinor: 0 |
|
| 86 |
+ }, |
|
| 87 |
+ DISPLAY_144x168: {
|
|
| 88 |
+ platforms: ['aplite', 'basalt', 'diorite'], |
|
| 89 |
+ minFwMajor: 0, |
|
| 90 |
+ minFwMinor: 0 |
|
| 91 |
+ }, |
|
| 92 |
+ DISPLAY_180x180_ROUND: {
|
|
| 93 |
+ platforms: ['chalk'], |
|
| 94 |
+ minFwMajor: 0, |
|
| 95 |
+ minFwMinor: 0 |
|
| 96 |
+ }, |
|
| 97 |
+ DISPLAY_200x228: {
|
|
| 98 |
+ platforms: ['emery'], |
|
| 99 |
+ minFwMajor: 0, |
|
| 100 |
+ minFwMinor: 0 |
|
| 101 |
+ } |
|
| 102 |
+}; |
|
| 103 |
+ |
|
| 104 |
+/** |
|
| 105 |
+ * Checks if all of the provided capabilities are compatible with the watch |
|
| 106 |
+ * @param {Object} activeWatchInfo
|
|
| 107 |
+ * @param {Array<string>} [capabilities]
|
|
| 108 |
+ * @return {boolean}
|
|
| 109 |
+ */ |
|
| 110 |
+module.exports.includesCapability = function(activeWatchInfo, capabilities) {
|
|
| 111 |
+ var notRegex = /^NOT_/; |
|
| 112 |
+ var result = []; |
|
| 113 |
+ |
|
| 114 |
+ if (!capabilities || !capabilities.length) {
|
|
| 115 |
+ return true; |
|
| 116 |
+ } |
|
| 117 |
+ |
|
| 118 |
+ for (var i = capabilities.length - 1; i >= 0; i--) {
|
|
| 119 |
+ var capability = capabilities[i]; |
|
| 120 |
+ var mapping = module.exports.capabilityMap[capability.replace(notRegex, '')]; |
|
| 121 |
+ |
|
| 122 |
+ if (!mapping || |
|
| 123 |
+ mapping.platforms.indexOf(activeWatchInfo.platform) === -1 || |
|
| 124 |
+ mapping.minFwMajor > activeWatchInfo.firmware.major || |
|
| 125 |
+ mapping.minFwMajor === activeWatchInfo.firmware.major && |
|
| 126 |
+ mapping.minFwMinor > activeWatchInfo.firmware.minor |
|
| 127 |
+ ) {
|
|
| 128 |
+ result.push(!!capability.match(notRegex)); |
|
| 129 |
+ } else {
|
|
| 130 |
+ result.push(!capability.match(notRegex)); |
|
| 131 |
+ } |
|
| 132 |
+ } |
|
| 133 |
+ |
|
| 134 |
+ return result.indexOf(false) === -1; |
|
| 135 |
+}; |