diff --git a/html/countdown.js b/html/countdown.js index 491b805213302070af21f429024f59797ffc92fe..3b240d0d102b998705b22010365257fecb349d8b 100644 --- a/html/countdown.js +++ b/html/countdown.js @@ -1,6 +1,8 @@ var countdown_timer; var countdown_running=false; +var countdown_paused=false; var flash=0; +var remaining_time=0; function startTimer(duration, display) { @@ -16,6 +18,8 @@ function startTimer(duration, display) localStorage.setItem('slot_timer_output', slot_time_string); display.textContent = slot_time_string; + remaining_time = minutes*60+seconds; + if (--timer < 0) { timer=0; @@ -28,22 +32,28 @@ function startTimer(duration, display) }, 1000); } -function slot_time() +function slot_time_start_stop() { if(!countdown_running) { - var time = document.getElementById("slot_time_input").value; + var time; + if(!countdown_paused) + time = document.getElementById("slot_time_input").value*60; + else + time = remaining_time; display = document.querySelector('#slot_timer_output'); + startTimer(time, display); document.getElementById("slot_time_button").innerHTML = "PAUSE"; document.getElementById('slot_time_button').style.backgroundColor="RoyalBlue"; - startTimer(time, display); countdown_running=true; } else { + countdown_running=false; clearTimeout(countdown_timer); - document.getElementById("slot_time_button").innerHTML = "START"; - document.getElementById('slot_time_button').style.backgroundColor="blue"; + document.getElementById("slot_time_button").innerHTML = "RESUME"; + document.getElementById('slot_time_button').style.backgroundColor="RoyalBlue"; + countdown_paused=true; } } @@ -51,23 +61,38 @@ function slot_time() function slot_time_reset() { clearTimeout(countdown_timer); + document.getElementById('slot_timer_output').style.backgroundColor="white"; + document.getElementById("slot_time_button").innerHTML = "START"; + document.getElementById('slot_time_button').style.backgroundColor="SeaGreen"; + remaining_time=document.getElementById("slot_time_input").value*60; + countdown_paused=false; + countdown_running=false; + show_time(); } -window.onload = function () +function show_time() { - var duration = document.getElementById("slot_time_input").value; - var timer = duration, minutes, seconds; - display = document.querySelector('#slot_timer_output'); - minutes = parseInt(timer / 60, 10); - seconds = parseInt(timer % 60, 10); + if(!countdown_running) + { + var duration = document.getElementById("slot_time_input").value*60; + var timer = duration, minutes, seconds; + display = document.querySelector('#slot_timer_output'); + minutes = parseInt(timer / 60, 10); + seconds = parseInt(timer % 60, 10); - minutes = minutes < 10 ? "0" + minutes : minutes; - seconds = seconds < 10 ? "0" + seconds : seconds; + minutes = minutes < 10 ? "0" + minutes : minutes; + seconds = seconds < 10 ? "0" + seconds : seconds; - var slot_timer_string = minutes+":"+seconds; + var slot_timer_string = minutes+":"+seconds; - localStorage.setItem('slot_timer_output', slot_timer_string); + localStorage.setItem('slot_timer_output', slot_timer_string); - display.textContent = minutes + ":" + seconds; + display.textContent = minutes + ":" + seconds; + } +} + +window.onload = function () +{ + show_time(); }; diff --git a/html/index.html b/html/index.html index 037648b4c1d0e0a3d0bf484868873bf304b32a10..d4200e868e8734547be03ecf4fc44e99ad1896cb 100644 --- a/html/index.html +++ b/html/index.html @@ -251,6 +251,7 @@ feedback_text = time + text + '
' + feedback_text ; document.getElementById("feedback_text").innerHTML = feedback_text; + localStorage.setItem('feedback_text_full', feedback_text); } last_feedback_line=text; } @@ -401,8 +402,8 @@ </div> <div class="column"> SLOT TIME - <input type="number" id="slot_time_input" min="1" max="60" step="1" style="width: 2.5em" value="12"> - <button class="btn btn-success" id ="slot_time_button" style="width:20%; height: 50px" onclick = "this.blur();slot_time()">START</button> + <input type="number" id="slot_time_input" min="1" max="60" step="1" style="width: 2.5em" value="12" onchange="show_time()"> + <button class="btn btn-success" id ="slot_time_button" style="width:20%; height: 50px" onclick = "this.blur();slot_time_start_stop()">START</button> <button class="btn btn-danger" id ="slot_time_reset_button" style="width:20%; height: 50px" onclick = "this.blur();slot_time_reset()">RESET</button> <span id="slot_timer_output">00:00</span> </div> diff --git a/html/public.html b/html/public.html index 4cf9c233618af92c28702d2b9c4deabe7b19139b..64e57be68fa5c49efda7aa6a604ca00c26ea5782 100644 --- a/html/public.html +++ b/html/public.html @@ -23,7 +23,7 @@ <script> - document.title="ADC GUI"; + document.title="ADC GUI PUBLIC"; var ip; ip = document.domain; @@ -35,311 +35,23 @@ var ros = new ROSLIB.Ros(); ros.connect('ws://'+ip+':9090'); - var goals_param = new ROSLIB.Param({ - ros : ros, - name : '/goals' - }); - - var adc_jury_service_client = new ROSLIB.Service({ - ros : ros, - name : '/jury/set_mode', - serviceType : 'iri_adc_msgs/jury_mode' - }); - - var srv_request = new ROSLIB.ServiceRequest({ - enable : false - }); - - var adc_jury_client = new ROSLIB.ActionClient({ - ros : ros, - serverName : '/jury/challenge', - actionName : 'iri_adc_msgs/adc_juryAction' - }); - - var goal_array_msg = new ROSLIB.Message( - { - }); var team; var challenge; - var feedback_text=""; - var last_feedback_line=""; - var i=0; - var service_answered=false; - var service_ok=false; - var received_feedback=false; - var feedback_timer; - var jury_mode_running=false; - var action_running=false; - var goals_loaded=false; - - function update_team() - { - team = document.getElementById("team_input").value; - localStorage.setItem('team', team); - } - - function update_challenge() - { - challenge = document.getElementById("challenge_input").value; - localStorage.setItem('challenge', challenge); - } - - function send_goal() - { - //load_goals_from_yaml(); //TODO: sync load. Now is async and done on input.onchange and at the beginning - - init_goal_msg(); - - action_goal.send(); - - document.getElementById("action_info").innerHTML = "Goal sent. Expecting feedback..."; - document.getElementById("action_info").style.backgroundColor = 'yellow' ; - - feedback_watchdog_timer(); - //action_running=true; //true when received feedback? - } - - function init_goal_msg() - { - action_goal = new ROSLIB.Goal( - { - actionClient : adc_jury_client, - goalMessage : goal_array_msg - } - ); - - action_goal.on('feedback', function(msg) - { - received_feedback=true; - action_running=true; - document.getElementById("action_info").innerHTML = "Feedback received!"; - document.getElementById("action_info").style.backgroundColor = 'green' ; - var feedback_new_line= msg.status; - add_feedback_line(feedback_new_line); - }); - - action_goal.on('result', function(result) - { - if(action_running) - { - finish_action(); - } - }); - - } - - function finish_action() - { - if(timer_running) - startStop(); - document.getElementById("action_info").innerHTML = "Action finished"; - document.getElementById("action_info").style.backgroundColor = 'white' ; - action_running=false; - clearTimeout(feedback_timer); - add_feedback_line("Finished"); - } - - function cancel_goal() - { - action_goal.cancel(); - document.getElementById("action_info").innerHTML = "Goal cancelled"; - document.getElementById("action_info").style.backgroundColor = 'white' ; - } - - function jury_mode() - { - if(!jury_mode_running) - jury_mode_enable(); - else - jury_mode_disable(); - } - - function jury_mode_enable() - { - document.getElementById("service_info").innerHTML = "Called service, waiting response..."; - document.getElementById("service_info").style.backgroundColor = 'yellow' ; - document.getElementById('jury_mode_button').disabled=true; - srv_request.enable=true; - adc_jury_service_client.callService(srv_request, - function(result) - { - service_answered=true; - service_ok=true; - jury_mode_answered(); - }, - function(result) - { - service_answered=true; - service_ok=false; - jury_mode_answered(); - }); - } - - function jury_mode_disable() - { - document.getElementById("service_info").innerHTML = "Called service server, waiting response..."; - document.getElementById("service_info").style.backgroundColor = 'yellow' ; - document.getElementById('jury_mode_button').disabled=true; - srv_request.enable=false; - adc_jury_service_client.callService(srv_request, - function(result) - { - service_answered=true; - service_ok=true; - jury_mode_answered(); - }, - function(result) - { - service_answered=true; - service_ok=false; - jury_mode_answered(); - }); - } - - function jury_mode_answered() - { - document.getElementById('jury_mode_button').disabled=false; - if(service_ok) - { - service_ok=false; - document.getElementById("service_info").innerHTML = "Service responded"; - document.getElementById("service_info").style.backgroundColor = 'green' ; - if(!jury_mode_running) - { - add_feedback_line("Jury mode enabled"); - jury_mode_running = true; - document.getElementById("jury_mode_button").innerHTML = "DISABLE"; - document.getElementById('jury_mode_button').style.backgroundColor="Red"; - if(document.getElementById("startStop").innerHTML=="START") - document.getElementById('startStop').disabled=true; - } - else - { - add_feedback_line("Jury mode disabled"); - jury_mode_running = false; - document.getElementById("jury_mode_button").innerHTML = "ENABLE"; - document.getElementById('jury_mode_button').style.backgroundColor="RoyalBlue"; - if(document.getElementById("startStop").innerHTML=="START") - document.getElementById('startStop').disabled=false; - } - } - else - { - document.getElementById("service_info").innerHTML = "ERROR: couldn't contact service server!!!"; - document.getElementById("service_info").style.backgroundColor = 'red' ; - console.error("ERROR: couldn't contact service server!!!"); - } - } - - // function add_fake_feedback() - // { - // feedback_new_line=document.getElementById("fake_feedback_text").value+" "+i; - // i=i+1; - // add_feedback_line(feedback_new_line); - // } - - function add_feedback_line(text) - { - if(text!=last_feedback_line) - { -// var currentTime = new Date(); -// var secs = Math.floor(currentTime.getTime()/1000); -// var nsecs = Math.round(1000000000*(currentTime.getTime()/1000-secs)); -// var time = "["+secs+","+nsecs+"]: "; - var time = "[" + time_string + "]: "; - - feedback_text = time + text + '
' + feedback_text ; - document.getElementById("feedback_text").innerHTML = feedback_text; - } - last_feedback_line=text; - } - - function clear_feedback() - { - feedback_text=""; - last_feedback_line=""; - i=0; - document.getElementById("feedback_text").innerHTML = feedback_text; - } - - function feedback_watchdog_timer() - { - feedback_timer = setTimeout( - function() - { - if(action_running) - { - if(received_feedback) - { - received_feedback=false; - document.getElementById("action_info").innerHTML = "Feedback received!"; - document.getElementById("action_info").style.backgroundColor = 'green' ; - feedback_watchdog_timer(); - } - else - { - //clearTimeout(feedback_timer); - console.warn("WARN: feedback not received!"); - document.getElementById("action_info").innerHTML = "WARN: feedback NOT received!"; - document.getElementById("action_info").style.backgroundColor = 'yellow' ; - //TODO: what to do then? - feedback_watchdog_timer(); - } - } - },2000); - } - - function load_goals_from_yaml() - { - document.getElementById("goals_info").innerHTML = "Loading file"; - document.getElementById("goals_info").style.backgroundColor = 'yellow' ; - goals_file = document.getElementById("goals_file").value; - var goals_from_yaml; - - $.ajax( - { - url: goals_file, - success: - function(result) - { - goals_from_yaml = jsyaml.load( result ); - - goal_array_msg = new ROSLIB.Message( - { - goals: goals_from_yaml - }); - - goals_loaded=true; - document.getElementById("goals_info").innerHTML = "Loaded"; - document.getElementById("goals_info").style.backgroundColor = 'green' ; - document.getElementById('startStop').disabled=false; - }, - error: - function (xhr, ajaxOptions, thrownError) - { - //alert(xhr.status); - //alert(thrownError); - document.getElementById("goals_info").innerHTML = "Error loading file"; - document.getElementById("goals_info").style.backgroundColor = 'red' ; - document.getElementById('startStop').disabled=true; - console.error("ERROR: couldn't load goals"); - } - } - ); - } function iteration() { public_timer_timeout = setTimeout( function() { - var public_time_string= localStorage.getItem('attempt_time'); - //console.log("time_string: ", time_string); - document.getElementById("timer_output").innerHTML = public_time_string ; - var public_slot_time_string = localStorage.getItem('slot_time'); - document.getElementById("slot_timer_output").innerHTML = public_slot_time_string ; + document.getElementById("timer_output").innerHTML = localStorage.getItem('attempt_time'); + document.getElementById("slot_timer_output").innerHTML = localStorage.getItem('slot_timer_output'); + + document.getElementById("feedback_text").innerHTML = localStorage.getItem('feedback_text_full'); + document.getElementById("team_id").innerHTML = localStorage.getItem('team'); + document.getElementById("challenge_id").innerHTML = localStorage.getItem('challenge'); + iteration(); },100); }