MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / configure

Method configure

modules/drivers/sensors/apds9960/apds9960.js:156–442  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

154 }
155
156 configure(options){
157 const {
158 enableALS, on, alsIntegrationCycles, alsGain, proximityGain, alsThresholdHigh,
159 alsThresholdLow, alsThresholdPersistence, proximityThresholdPersistence, enableProximity,
160 proximityThresholdLow, proximityThresholdHigh, enableGesture, gestureThresholdEnter, gestureThresholdExit,
161 enableWait, waitTime, LEDBoost, proximityPulseLength, proximityPulseCount, proximityOffsetUR, proximityOffsetDL,
162 gesturePulseLength, gesturePulseCount} = options;
163 const configuration = this.#configuration;
164 const enabled = this.#configuration.enabled
165 const io = this.#io;
166
167 if (enableALS !== undefined) {
168 enabled.AEN = enableALS;
169 }
170
171 if (enableProximity !== undefined) {
172 enabled.PEN = enableProximity;
173 }
174
175 if (enableGesture !== undefined) {
176 enabled.GEN = enableGesture;
177 }
178
179 if (enableWait !== undefined) {
180 enabled.WEN = enableWait
181 }
182
183 if (on !== undefined) {
184 enabled.PON = on;
185 }
186
187 if (alsGain !== undefined) {
188 configuration.alsGain = alsGain;
189 }
190
191 if (proximityGain !== undefined) {
192 configuration.proximityGain = proximityGain;
193 }
194
195 if (proximityPulseLength !== undefined) {
196 if (proximityPulseLength !== 4 && proximityPulseLength !== 8 && proximityPulseLength !== 16 && proximityPulseLength !== 32)
197 throw new RangeError("invalid proximityPulseLength");
198
199 configuration.proximityPulseLength = proximityPulseLength;
200 }
201
202 if (proximityPulseCount !== undefined) {
203 if (proximityPulseCount < 1 || proximityPulseCount > 64)
204 throw new RangeError("invalid proximityPulseCount");
205
206 configuration.proximityPulseCount = proximityPulseCount;
207 }
208
209 if (proximityPulseLength !== undefined || proximityPulseCount !== undefined) {
210 const LENfield = (configuration.proximityPulseLength == 32 ? 3 : Math.floor(configuration.proximityPulseLength / 8)) << 6;
211 const PULSEfield = configuration.proximityPulseCount - 1;
212 const reg = LENfield | PULSEfield;
213 io.writeUint8(Register.PROX_PULSE, reg);

Callers 1

constructorMethod · 0.95

Calls 4

apersFromCyclesFunction · 0.85
writeUint8Method · 0.45
writeUint16Method · 0.45
readUint8Method · 0.45

Tested by

no test coverage detected