Skip to content
This repository has been archived by the owner on Apr 5, 2019. It is now read-only.

Commit

Permalink
Language Translation Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
MrYsLab committed Nov 23, 2014
1 parent d4a63c1 commit 93bc542
Show file tree
Hide file tree
Showing 27 changed files with 2,562 additions and 72 deletions.
Binary file not shown.
138 changes: 97 additions & 41 deletions clients/scratch/xi4s/xi4s.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ new (function () {
if (webSocketsArray[index].id === boardID) {
// allow user to reset the board to the same value - for stop and start
if ((webSocketsArray[index].ip != ipAddress) || (webSocketsArray[index].port != port)) {
alert('An IP entry already exists for board ' + boardID + '!');
createAlert(12, boardID);
callback(); // release the scratch wait block
return; // no need to go further
}
Expand Down Expand Up @@ -140,9 +140,7 @@ new (function () {
};

function noServerAlert() {
alert('Server not responding. Did you start XiServer for board ' +
boardID + '? Start the server, reload this page and try again');
// we set the board status back to 0
createAlert(20, boardID);
boardStatus = 0;
}

Expand Down Expand Up @@ -180,10 +178,9 @@ new (function () {

// server detected a problem in setting the mode of this pin
case 'invalidSetMode':
alert(msg[1]);
break;
case 'invalidPinCommand':
alert(msg[1]);
console.log('invalid alerts:' + 'index: ' + msg[1] + 'board: ' + msg[2] + 'pin: ' + msg[3]);
createAlert(msg[1], msg[2], msg[3]);
break;
default:
if (debugLevel >= 1)
Expand All @@ -201,7 +198,7 @@ new (function () {
if (webSocketsArray[index].id === boardID) {
// send message to server to create device(input devices) or set the pin mode (output device)
var messageToServer; // message to be sent to server
mode = extractMode(mode) ;
mode = extractMode(mode);

// the mode is the value prescribed in block descriptor section
switch (mode) {
Expand Down Expand Up @@ -266,9 +263,7 @@ new (function () {
webSocketsArray[index].ws.send(messageToServer);
break;
case 'SONAR Distance - (Digital In)':

alert('If you are using an Arduino, this feature requires a special version of StandardFirmata.' +
'See: https://github.com/rwaldron/johnny-five/wiki/Sonar for details.');
createAlert(13);
messageToServer = 'setSonarMode/' + boardID + '/' + pin + '/' + sensorDataArray.length;
if (debugLevel >= 2)
console.log('pinMode Sonar Out Msg to server: ' + messageToServer);
Expand Down Expand Up @@ -298,7 +293,7 @@ new (function () {
}
}
// board not yet established
alert('Board ' + boardID + ' IP address must be set before a board is used');
createAlert(14, boardID)
};


Expand All @@ -321,14 +316,14 @@ new (function () {

// set servo position to position in degrees
ext.moveStandardServo = function (board, pin, degrees, inversion) {
inversion = extractInversion(inversion) ;
inversion = extractInversion(inversion);
var msg = 'moveStandardServo/' + board + '/' + pin + '/' + degrees + '/' + inversion;
sendCommand(msg, board, 'moveStandardServo');
};

// set servo position to position in degrees
ext.moveContinuousServo = function (board, pin, direction, inversion, speed) {
inversion = extractInversion(inversion) ;
inversion = extractInversion(inversion);
direction = extractDirection(direction);
var msg = 'moveContinuousServo/' + board + '/' + pin + '/' + direction + '/' + inversion + '/' + speed;
sendCommand(msg, board, 'moveContinuousServo');
Expand All @@ -348,8 +343,7 @@ new (function () {

ext.fourWireStepperPins = function (board, pinA, pinB, pinC, pinD, stepsPerRev) {

alert('If you are using an Arduino, this feature requires a special version of StandardFirmata.' +
'See: https://github.com/soundanalogous/AdvancedFirmata for details.');
createAlert(15);

var pinArray = [];
pinArray.push(pinA);
Expand All @@ -360,17 +354,16 @@ new (function () {
// check for 4 unique values
var unique = pinArray.filter(onlyUnique);
if (unique.length !== 4) {
alert("The Four Pin Values Must Be Unique. Try Again!");
createAlert(16);
return;
}
var msg = 'fourWireStepperPins/' + board + '/' + pinA + '/' + pinB + '/' + pinC + '/' + pinD + '/' + stepsPerRev;
var msg = 'fourWireStepperPins/' + board + '/' + pinA + '/' + pinB + '/' + pinC + '/' + pinD + '/' + stepsPerRev;
sendCommand(msg, board, 'fourWireStepperPins');
};

ext.stepperDriverPins = function (board, pinA, pinB, stepsPerRev) {

alert('If you are using an Arduino, this feature requires a special version of StandardFirmata.' +
'See: https://github.com/soundanalogous/AdvancedFirmata for details.');
createAlert(15);

var pinArray = [];
pinArray.push(pinA);
Expand All @@ -386,8 +379,7 @@ new (function () {
console.log('stepperDriverPins unique length = ' + unique.length);

if (unique.length !== 2) {
alert("The Two Pin Values Must Be Unique. Try Again!");
return;
createAlert(17);
}
var msg = 'stepperDriverPins/' + board + '/' + pinA + '/' + pinB + '/' + stepsPerRev;
sendCommand(msg, board, 'stepperDriverPins');
Expand Down Expand Up @@ -448,7 +440,7 @@ new (function () {
// generate a key for sensorDataArray
var key = genReporterKey(board, pin, 'd');
var distance = retrieveReporterData(board, pin, key);
units = extractDistance(units) ;
units = extractDistance(units);
if (units === 'CM') {
return (distance * 2.54).toFixed(2);
}
Expand All @@ -465,7 +457,7 @@ new (function () {
// generate a key for sensorDataArray
var key = genReporterKey(board, pin, 'a');
var distance = retrieveReporterData(board, pin, key);
units = extractDistance(units) ;
units = extractDistance(units);
if (units === 'CM') {
return (distance * 2.54).toFixed(2);
}
Expand Down Expand Up @@ -501,8 +493,7 @@ new (function () {
}
}
// did not find an entry in the array
alert('Did you set the pin mode for Board ' + board + ' Pin ' + pin +
'? No entry for this block in database');
createAlert(18, board, pin);
ext._shutdown();
}

Expand Down Expand Up @@ -553,7 +544,7 @@ new (function () {
}
}
// board was not established
alert(type + ' IP address for board ' + board + ' was not set');
createAlert(19, board);
}

// return unique values contained within an array
Expand All @@ -564,7 +555,7 @@ new (function () {
// strip off the text to accommodate translations
function extractOffOn(value) {
var offOn = value.split('.');
if( offOn[0] === '1') {
if (offOn[0] === '1') {
return "Off"
}
else {
Expand All @@ -574,38 +565,38 @@ new (function () {

function extractDirection(direction) {
var dirArray = direction.split('.');
if( dirArray[0] === '1') {
if (dirArray[0] === '1') {
return "CW";
}
else {
return "CCW" ;
return "CCW";
}
}

function extractDistance(distance) {
var distArray = distance.split('.');
if( distArray[0] === '1') {
if (distArray[0] === '1') {
return "CM";
}
else {
return "Inches" ;
return "Inches";
}
}

function extractInversion(inversion) {
var invArray = inversion.split('.');
if( invArray[0] === '1' ) {
if (invArray[0] === '1') {
return "False";
}
else {
return "True" ;
return "True";
}
}

function extractMode(mode) {
var modeArray = mode.split('.') ;
var modeArray = mode.split('.');
var serverMode = undefined;
switch( modeArray[0]) {
switch (modeArray[0]) {
case '1':
serverMode = 'Digital Input';
break;
Expand Down Expand Up @@ -639,9 +630,74 @@ new (function () {
return serverMode;
}

// usage example:
// var a = ['a', 1, 'a', 2, '1'];
// var unique = a.filter( onlyUnique ); // returns ['a', 1, 2, '1']
function createAlert(index, board, pin) {
console.log('createAlert' + index, board, pin);
var alertStrings = [
// 0
"exceeds Maximum Number of Pins on Board.",
// 1
"does not support the requested mode.",
//2
"was not configured for digital write.",
//3
"was not configured for analog write.",
//4
"was not configured for TONE OUTPUT Control.",
//5
"was not configured for Servo Control.",
//6
"was not configured for Standard Servo Control.",
//7
"was not configured for Continuous Servo Control.",
//8
"was not configured for Stepper Control.",
//9
"this pin has already been assigned.",
//10
"Speed must be in the range of 0.0 to 1.0.",
//11
"does not support analog operation",
//12
"An IP entry already exists for this board.",
//13
"If you are using an Arduino, this feature requires a special version of StandardFirmata." +
"See: https://github.com/rwaldron/johnny-five/wiki/Sonar for details.",
//14
"IP address must be set before a board is used",
//15
"If you are using an Arduino, this feature requires a special version of StandardFirmata." +
"See: https://github.com/soundanalogous/AdvancedFirmata for details.",
//16
"The Four Pin Values Must Be Unique. Try Again!",
//17
"The Two Pin Values Must Be Unique. Try Again!",
//18
"Pin Mode was not set. ",
//19
"IP Address for this board was not set.",
//20
"Server not responding. Did you start XiServer for this board?" +
"Please start the server, reload this page and try again"
];

var headerKeywords = {
board: "Board: ",
pin: "Pin: "
};

var alertInfo = "";
if (board != undefined) {
alertInfo = headerKeywords.board + board;
}
if (pin != undefined) {
alertInfo = alertInfo + ' ' + headerKeywords.pin + pin;
}
alertInfo += " ";

alert(alertInfo + alertStrings[index]);

}


// Block and block menu descriptions
var descriptor = {
Expand All @@ -666,7 +722,7 @@ new (function () {
[' ', 'Board: %m.bdNum Set Pins For Stepper Driver Board: Step %n Direction %n Steps Per Rev: %n', 'stepperDriverPins', '1', '8', '9', 500],
[' ', 'Board: %m.bdNum Move Stepper On Pin %n RPM: %n Dir: %m.motorDirection Accel: %n Decel: %n # of Steps: %n',
'moveStepper', '1', '8', '180', '1. CW', '1600', '1600', '2000'],
[' ', 'Board: %m.bdNum Stepper Stop! Pin: %n', 'stopStepper', '1', '8'],
[' ', 'Board: %m.bdNum Stepper Stop! Pin: %n', 'stopStepper', '1', '8']


],
Expand All @@ -688,6 +744,6 @@ new (function () {


// Register the extension
ScratchExtensions.register('Xi4S_v_003_15Nov14', descriptor, ext);
ScratchExtensions.register('Xi4S_v_003_19Nov14', descriptor, ext);

})();
Loading

0 comments on commit 93bc542

Please sign in to comment.