summaryrefslogtreecommitdiff
path: root/js/codeq/robot.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/codeq/robot.js')
-rw-r--r--js/codeq/robot.js22
1 files changed, 15 insertions, 7 deletions
diff --git a/js/codeq/robot.js b/js/codeq/robot.js
index ffccc62..ee6eda6 100644
--- a/js/codeq/robot.js
+++ b/js/codeq/robot.js
@@ -108,6 +108,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
var robotHandler; //created when we enter the robot state and destroyed once we leave it
codeq.globalStateMachine.register('robot', {
+ 'jqScreen': jqScreen,
+
//'enter': function (problemDef, commonDef, currentSolution) {
'enter': function (ref, data) {//function (problemDef, commonDef, currentSolution) {//
@@ -174,13 +176,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
var makeRobotTerminalHandler = function (jqConsole, editor, problem_id, activityHandler) {
var terminal = codeq.makeConsole(jqConsole, {
- 'greeting': 'CodeQ Robot terminal proxy',
- 'autoHistory': true
+ 'greeting': 'Robot messages\n--------------\n\n',
});
-
- terminal.onInput = function (text) {
- terminal.append('Not implemented.\n', 'output');
- };
+ terminal.inputDisable();
return terminal;
};
@@ -191,7 +189,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
var createRobotHandler = function (problemDef, commonDef, currentSolution) {
var jqDescriptionContent = jqDescription.find('.description'),
jqEditor = jqCode.find('.code_editor'),
+ jqTerminal = jqConsole.find('.console'),
jqHints = jqInfo.find('.hints'),
+ jqStatus = jqConsole.find('.status'),
editor = codeq.makeEditor(jqEditor[0],
{
mode: 'python',
@@ -202,6 +202,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
jqBtnRun.focus();
}),
activityHandler = codeq.makeActivityHandler(editor, problemDef.id),
+ terminal = makeRobotTerminalHandler(jqTerminal, editor, problemDef.id, activityHandler),
hinter = codeq.makeHinter(jqHints, jqEditor, editor, 'robot_hints', problemDef, commonDef),
commError = function (error) {
alert(error);
@@ -213,6 +214,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
// set up the websocket events
socket.on('close', function (data) {
console.log('websocket closed, trying to reopen in 1 s');
+ jqStatus.html('Not connected.');
reconnectTimer = setTimeout(function () {
reconnectTimer = null;
socket.open();
@@ -228,7 +230,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
if (!sensors.hasOwnProperty(sensor)) continue;
text += sensor + ': ' + sensors[sensor] + '<br />\n'
}
- $('div.console').html('<p style="color: lightgreen; font-family: monospace;">'+text+'</p>');
+ jqStatus.html(text);
+ }
+ else if (json_obj.event == 'output') {
+ text = json_obj.text;
+ terminal.append(text, 'output');
}
});
@@ -286,10 +292,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
var program = editor.getDoc().getValue();
activityHandler.queueTrace({'typ': 'robot_run', 'program': program});
socket.send(JSON.stringify({action: 'run', program: program}));
+ terminal.append('<run>\n', 'output');
});
jqBtnStop.on('click', function () {
activityHandler.queueTrace({'typ': 'robot_stop'});
socket.send(JSON.stringify({action: 'stop'}));
+ terminal.append('<stop>\n', 'output');
});
codeq.comms.loadProblem(problemDef.id).done();