-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
js: finish tests and fully implement and test all classes
- Loading branch information
Showing
4 changed files
with
108 additions
and
100 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
var ev3dev = require('../bin/index.js'); | ||
|
||
|
||
console.log('Battery ------------'); | ||
var battery = new ev3dev.PowerSupply(); | ||
[ 'currentNow', 'voltageNow', 'voltageMaxDesign', | ||
'voltageMinDesign', 'technology', 'type', | ||
'currentAmps', 'voltageVolts' | ||
].forEach(function (value) { | ||
console.log(value + ": " + battery[value]); | ||
}); | ||
console.log('--------------------') | ||
console.log('LED ----------------'); | ||
console.log('fading LEDs from green to red...'); | ||
var leds = []; | ||
[ 'ev3:green:left', 'ev3:red:left', | ||
'ev3:green:right', 'ev3:red:right' | ||
].forEach(function (value) { | ||
leds.push(new ev3dev.LED(value)); | ||
}); | ||
|
||
//Just running through the properties isn't helpful as a test | ||
// This will transition through the range of colors | ||
|
||
for(var i = 0; i < 100; i++) { | ||
for(var ledI = 0; ledI < leds.length; ledI++) { | ||
var val = (i / 100) * leds[ledI].maxBrightness; | ||
if(ledI % 2 == 0) | ||
val = (100 - i) / 100 * leds[ledI].maxBrightness; | ||
|
||
leds[ledI].brightness = Math.round(val); | ||
} | ||
|
||
if(i % 10 == 0) | ||
console.log(i + '%'); | ||
|
||
{ //Hack to sleep for time | ||
// SHOULD NOT BE USED IN PRODUCTION CODE | ||
var stop = new Date().getTime(); | ||
while(new Date().getTime() < stop + 100) { | ||
; | ||
} | ||
} | ||
} | ||
|
||
console.log('done'); | ||
|
||
for(var i in leds) { | ||
leds[i].brightness = 0; | ||
} | ||
|
||
console.log('--------------------') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
var ev3dev = require('../bin/index.js'); | ||
|
||
// Run motor | ||
console.log('Motor --------------'); | ||
var motor = new ev3dev.Motor(); | ||
['dutyCycle', 'dutyCycleSp', 'portName', 'position', | ||
'positionSp', 'pulsesPerSecond', 'pulsesPerSecondSp', | ||
'rampDownSp', 'rampUpSp', 'regulationMode', 'run', | ||
'runMode', 'speedRegulationP', 'state', 'stopMode', | ||
'stopModes', 'timeSp', 'type' | ||
].forEach(function (value) { | ||
console.log(value + ": " + motor[value]); | ||
}); | ||
|
||
console.log('Setting motor properties...'); | ||
motor.rampUpSp = 100; | ||
motor.rampDownSp = 100; | ||
motor.runMode = 'time'; | ||
motor.timeSp = 1000; | ||
motor.dutyCycleSp = 50; | ||
console.log('Running motor...'); | ||
motor.run = 1; | ||
console.log('--------------------'); | ||
|
||
//Read sensor | ||
console.log('Sensor -------------'); | ||
var sensor = new ev3dev.Sensor(); | ||
[ 'portName', 'numValues', 'typeName', | ||
'mode', 'modes' | ||
].forEach(function (value) { | ||
console.log(value + ": " + sensor[value]); | ||
}); | ||
|
||
console.log('Testing sensor read...'); | ||
for(var i = 0; i < sensor.numValues; i++) { | ||
console.log('value ' + i + ': ' + sensor.getValue(i) + ', ' + sensor.getFloatValue(i)); | ||
} | ||
console.log('--------------------') | ||
console.log("Core motor and sensor test complete"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters