Skip to content

Commit

Permalink
Allow control of the ignition from the web interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
ianrenton committed Apr 11, 2014
1 parent d3b54c7 commit d3f3d7c
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 160 deletions.
27 changes: 15 additions & 12 deletions rt_http/rt_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ int main(int argc, char **argv) {

int g,rep,i;
char inchar;
userCommand = malloc(sizeof(char)*10);
autonomyCommand = malloc(sizeof(char)*10);
char* copiedCommand = malloc(sizeof(char)*10);
userCommand = malloc(sizeof(char)*11);
autonomyCommand = malloc(sizeof(char)*11);
char* copiedCommand = malloc(sizeof(char)*11);

// Set up gpio pointer for direct register access
setup_io();
Expand Down Expand Up @@ -144,7 +144,7 @@ int main(int argc, char **argv) {
strcpy(&copiedCommand[0], &userCommand[0]);
pthread_mutex_unlock( &userCommandMutex );

if (copiedCommand[8] == '1') {
if (copiedCommand[9] == '1') {
// Autonomy requested, so obey autonomy's commands not the user commands.
pthread_mutex_lock( &autonomyCommandMutex );
strcpy(&copiedCommand[0], &autonomyCommand[0]);
Expand Down Expand Up @@ -175,6 +175,9 @@ int main(int argc, char **argv) {
} else if (copiedCommand[7] == '1') {
// Fire
sendCode(FIRE);
} else if (copiedCommand[8] == '1') {
// Ignition (in case it drops out)
sendCode(IGNITION);
} else {
// Idle
sendCode(IDLE);
Expand Down Expand Up @@ -305,17 +308,17 @@ static int http_callback(struct mg_connection *conn) {

const struct mg_request_info *request_info = mg_get_request_info(conn);

char* tempCommand = malloc(sizeof(char)*13);
strncpy(&tempCommand[0], &request_info->query_string[0], 12);
tempCommand[12] = 0;
//printf("Received command from HTTP: %.*s\n", 12, tempCommand);
char* tempCommand = malloc(sizeof(char)*14);
strncpy(&tempCommand[0], &request_info->query_string[0], 13);
tempCommand[13] = 0;
//printf("Received command from HTTP: %.*s\n", 13, tempCommand);

// Set received, so send it over to the control thread
if ((tempCommand[0] == 's') && (tempCommand[1] == 'e') && (tempCommand[2] == 't')) {
pthread_mutex_lock( &userCommandMutex );
strncpy(&userCommand[0], &tempCommand[3], 9);
strncpy(&userCommand[0], &tempCommand[3], 10);
pthread_mutex_unlock( &userCommandMutex );
//printf("Set motion command: %.*s\n", 9, userCommand);
//printf("Set motion command: %.*s\n", 10, userCommand);

// Send an HTTP header back to the client
mg_printf(conn, "HTTP/1.1 200 OK\r\n"
Expand Down Expand Up @@ -501,7 +504,7 @@ void* launch_autonomy() {
// Send a command from autonomy to the main control thread
void* autonomySendCommand(char* cmd) {
pthread_mutex_lock( &autonomyCommandMutex );
strncpy(&autonomyCommand[0], &cmd[0], 8);
autonomyCommand[9] = 0;
strncpy(&autonomyCommand[0], &cmd[0], 9);
autonomyCommand[10] = 0;
pthread_mutex_unlock( &autonomyCommandMutex );
}
2 changes: 1 addition & 1 deletion web-ui/fps/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
<body onload="load()" onkeyup="keyup(event)" onkeydown="keydown(event)" style="background-color:black;">
<div id="webcam" style="width:640px;height:480px;background-color:gray;margin:0 auto;">
</div>
<div><p style="text-align:center; color:gray">Move/turn: W S A D, Turret turn: Q E, Elevate: Z, Fire: Space, All stop: Enter</p></div>
<div><p style="text-align:center; color:gray">Move/turn: W S A D, Turret turn: Q E, Elevate: Z, Fire: Space, Ignition: I, All stop: Enter</p></div>
</body>
</html>
4 changes: 4 additions & 0 deletions web-ui/js/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var command = {
'turret_right' : false,
'turret_elev' : false,
'fire' : false,
'ignition' : false,
'autonomy' : false
}

Expand Down Expand Up @@ -115,6 +116,9 @@ function keychanged(e, val) {
case 32:
set('fire', val);
break;
case 73:
set('ignition', val);
break;
case 13:
stop();
break;
Expand Down
151 changes: 76 additions & 75 deletions web-ui/laptop/index.html
Original file line number Diff line number Diff line change
@@ -1,75 +1,76 @@
<!-- Raspberry Tank Web UI, February 2013, by Ian Renton. Released under the BSD licence. -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<head>
<title>Raspberry Tank</title>
<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="../js/mjpg-streamer.js"></script>
<script type="text/javascript" src="../js/javascript.js"></script>
</head>
<body onload="load()">
<div style="width:1250px; margin:0 auto;">
<table border="0"><tr><td>
<div id="webcam" style="width:640px;height:480px;background-color:gray;">
</div>
</td><td>
<table border="0" style="width:600px;height:600px;margin: 0 auto;">
<tr height="33%">
<td width="33%" style="text-align:center;">
<a href="#" onmousedown="set('turret_left', true);" onmouseup="set('turret_left', false);" >
<img src="../img/turret-left.png" style="border:none;" />
</a>
</td>
<td width="33%" style="text-align:center;">
<a href="#" onmousedown="set('forward', true);" onmouseup="set('forward', false);" >
<img src="../img/forward.png" style="border:none;" />
</a>
</td>
<td width="33%" style="text-align:center;">
<a href="#" onmousedown="set('turret_right', true);" onmouseup="set('turret_right', false);" >
<img src="../img/turret-right.png" style="border:none;" />
</a>
</td>
</tr>
<tr height="33%">
<td width="33%" style="text-align:center;">
<a href="#" onmousedown="set('left', true);" onmouseup="set('left', false);" >
<img src="../img/left.png" style="border:none;" />
</a>
</td>
<td width="33%" style="text-align:center;">
<a href="#" onmousedown="stop();">
<img src="../img/stop.png" style="border:none;" />
</a>
</td>
<td width="33%" style="text-align:center;">
<a href="#" onmousedown="set('right', true);" onmouseup="set('right', false);" >
<img src="../img/right.png" style="border:none;" />
</a>
</td>
</tr>
<tr height="33%">
<td width="33%" style="text-align:center;">
<a href="#" onmousedown="set('turret_elev', true);" onmouseup="set('turret_elev', false);">
<img src="../img/turret-elev.png" style="border:none;" />
</a>
</td>
<td width="33%" style="text-align:center;">
<a href="#" onmousedown="set('reverse', true);" onmouseup="set('reverse', false);" >
<img src="../img/reverse.png" style="border:none;" />
</a>
</td>
<td width="33%" style="text-align:center;">
<a href="#" onmousedown="set('fire', true);" onmouseup="set('fire', false);" >
<img src="../img/fire.png" style="border:none;" />
</a>
</td>
</tr>
<tr><td colspan="3"><h3><center>Autonomy <span class="autonomystate">OFF</span>. <a href="#" onclick="toggleAutonomy()"><span class="autonomybutton">Switch ON</span></a></center></td></tr>
</table>
</td></tr>
<tr><td colspan="2"><div class="data"></div></td></tr></table>
</div>
</body>
</html>
<!-- Raspberry Tank Web UI, February 2013, by Ian Renton. Released into public domain without licence. -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<head>
<title>Raspberry Tank</title>
<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="../js/mjpg-streamer.js"></script>
<script type="text/javascript" src="../js/javascript.js"></script>
</head>
<body onload="load()">
<div style="width:1250px; margin:0 auto;">
<table border="0"><tr><td>
<div id="webcam" style="width:640px;height:480px;background-color:gray;">
</div>
</td><td>
<table border="0" style="width:600px;height:600px;margin: 0 auto;">
<tr height="33%">
<td width="33%" style="text-align:center;">
<a href="#" onmousedown="set('turret_left', true);" onmouseup="set('turret_left', false);" >
<img src="../img/turret-left.png" style="border:none;" />
</a>
</td>
<td width="33%" style="text-align:center;">
<a href="#" onmousedown="set('forward', true);" onmouseup="set('forward', false);" >
<img src="../img/forward.png" style="border:none;" />
</a>
</td>
<td width="33%" style="text-align:center;">
<a href="#" onmousedown="set('turret_right', true);" onmouseup="set('turret_right', false);" >
<img src="../img/turret-right.png" style="border:none;" />
</a>
</td>
</tr>
<tr height="33%">
<td width="33%" style="text-align:center;">
<a href="#" onmousedown="set('left', true);" onmouseup="set('left', false);" >
<img src="../img/left.png" style="border:none;" />
</a>
</td>
<td width="33%" style="text-align:center;">
<a href="#" onmousedown="stop();">
<img src="../img/stop.png" style="border:none;" />
</a>
</td>
<td width="33%" style="text-align:center;">
<a href="#" onmousedown="set('right', true);" onmouseup="set('right', false);" >
<img src="../img/right.png" style="border:none;" />
</a>
</td>
</tr>
<tr height="33%">
<td width="33%" style="text-align:center;">
<a href="#" onmousedown="set('turret_elev', true);" onmouseup="set('turret_elev', false);">
<img src="../img/turret-elev.png" style="border:none;" />
</a>
</td>
<td width="33%" style="text-align:center;">
<a href="#" onmousedown="set('reverse', true);" onmouseup="set('reverse', false);" >
<img src="../img/reverse.png" style="border:none;" />
</a>
</td>
<td width="33%" style="text-align:center;">
<a href="#" onmousedown="set('fire', true);" onmouseup="set('fire', false);" >
<img src="../img/fire.png" style="border:none;" />
</a>
</td>
</tr>
<tr><td colspan="1"><h3><center><a href="#" onmousedown="set('ignition', true);" onmouseup="set('ignition', false);" >Ignition
</a></center></td><td colspan="2"><h3><center>Autonomy <span class="autonomystate">OFF</span>. <a href="#" onclick="toggleAutonomy()"><span class="autonomybutton">Switch ON</span></a></center></td></tr>
</table>
</td></tr>
<tr><td colspan="2"><div class="data"></div></td></tr></table>
</div>
</body>
</html>
145 changes: 73 additions & 72 deletions web-ui/touch/index.html
Original file line number Diff line number Diff line change
@@ -1,72 +1,73 @@
<!-- Raspberry Tank Web UI, February 2013, by Ian Renton. Released under the BSD licence. -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<head>
<title>Raspberry Tank - Touch Interface</title>
<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="../js/mjpg-streamer.js"></script>
<script type="text/javascript" src="../js/javascript.js"></script>
</head>
<body onload="load()">
<div style="width:640px;margin:0 auto;">
<div id="webcam" style="width:640px;height:480px;background-color:gray;">
</div>
<table border="0" style="width:600px;height:600px;margin: 0 auto;">
<tr height="33%">
<td width="33%" style="text-align:center;">
<a href="#" onclick="set('turret_left', true);" >
<img src="../img/turret-left.png" style="border:none;" />
</a>
</td>
<td width="33%" style="text-align:center;">
<a href="#" onclick="set('forward', true);" >
<img src="../img/forward.png" style="border:none;" />
</a>
</td>
<td width="33%" style="text-align:center;">
<a href="#" onclick="set('turret_right', true);" >
<img src="../img/turret-right.png" style="border:none;" />
</a>
</td>
</tr>
<tr height="33%">
<td width="33%" style="text-align:center;">
<a href="#" onclick="set('left', true);" >
<img src="../img/left.png" style="border:none;" />
</a>
</td>
<td width="33%" style="text-align:center;">
<a href="#" onclick="stop();" >
<img src="../img/stop.png" style="border:none;" />
</a>
</td>
<td width="33%" style="text-align:center;">
<a href="#" onclick="set('right', true);" >
<img src="../img/right.png" style="border:none;" />
</a>
</td>
</tr>
<tr height="33%">
<td width="33%" style="text-align:center;">
<a href="#" onclick="set('turret_elev', true);">
<img src="../img/turret-elev.png" style="border:none;" />
</a>
</td>
<td width="33%" style="text-align:center;">
<a href="#" onclick="set('reverse', true);" >
<img src="../img/reverse.png" style="border:none;" />
</a>
</td>
<td width="33%" style="text-align:center;">
<a href="#" onclick="set('fire', true);" >
<img src="../img/fire.png" style="border:none;" />
</a>
</td>
</tr>
<tr><td colspan="3"><h3><center>Autonomy <span class="autonomystate">OFF</span>. <a href="#" onclick="toggleAutonomy()"><span class="autonomybutton">Switch ON</span></a></center></td></tr>
<tr><td colspan="3"><div class="data"></div></td></tr>
</table>
</div>
</body>
</html>
<!-- Raspberry Tank Web UI, February 2013, by Ian Renton. Released into public domain without licence. -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<head>
<title>Raspberry Tank - Touch Interface</title>
<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="../js/mjpg-streamer.js"></script>
<script type="text/javascript" src="../js/javascript.js"></script>
</head>
<body onload="load()">
<div style="width:640px;margin:0 auto;">
<div id="webcam" style="width:640px;height:480px;background-color:gray;">
</div>
<table border="0" style="width:600px;height:600px;margin: 0 auto;">
<tr height="33%">
<td width="33%" style="text-align:center;">
<a href="#" onclick="set('turret_left', true);" >
<img src="../img/turret-left.png" style="border:none;" />
</a>
</td>
<td width="33%" style="text-align:center;">
<a href="#" onclick="set('forward', true);" >
<img src="../img/forward.png" style="border:none;" />
</a>
</td>
<td width="33%" style="text-align:center;">
<a href="#" onclick="set('turret_right', true);" >
<img src="../img/turret-right.png" style="border:none;" />
</a>
</td>
</tr>
<tr height="33%">
<td width="33%" style="text-align:center;">
<a href="#" onclick="set('left', true);" >
<img src="../img/left.png" style="border:none;" />
</a>
</td>
<td width="33%" style="text-align:center;">
<a href="#" onclick="stop();" >
<img src="../img/stop.png" style="border:none;" />
</a>
</td>
<td width="33%" style="text-align:center;">
<a href="#" onclick="set('right', true);" >
<img src="../img/right.png" style="border:none;" />
</a>
</td>
</tr>
<tr height="33%">
<td width="33%" style="text-align:center;">
<a href="#" onclick="set('turret_elev', true);">
<img src="../img/turret-elev.png" style="border:none;" />
</a>
</td>
<td width="33%" style="text-align:center;">
<a href="#" onclick="set('reverse', true);" >
<img src="../img/reverse.png" style="border:none;" />
</a>
</td>
<td width="33%" style="text-align:center;">
<a href="#" onclick="set('fire', true);" >
<img src="../img/fire.png" style="border:none;" />
</a>
</td>
</tr>
<tr><td colspan="1"><h3><center><a href="#" onmousedown="set('ignition', true);" onmouseup="set('ignition', false);" >Ignition
</a></center></td><td colspan="2"><h3><center>Autonomy <span class="autonomystate">OFF</span>. <a href="#" onclick="toggleAutonomy()"><span class="autonomybutton">Switch ON</span></a></center></td></tr>
<tr><td colspan="3"><div class="data"></div></td></tr>
</table>
</div>
</body>
</html>

0 comments on commit d3f3d7c

Please sign in to comment.