enhance car web control

This commit is contained in:
Alfonso Gamboa
2022-07-21 22:08:34 -07:00
parent 16def56fc9
commit b59823b61e
6 changed files with 129 additions and 39 deletions

View File

@@ -1 +1 @@
Wed Jul 20 07:33:26 PM PDT 2022
Thu Jul 21 10:08:24 PM PDT 2022

View File

@@ -11,6 +11,19 @@
cursor: pointer;
}
.wz_car_BUTTON_N {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 14px;
margin: 4px 2px;
cursor: pointer;
}
.wz_car_TABLE {
width: 55%;
border-collapse: collapse;

View File

@@ -3,7 +3,7 @@
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="car.js"></script>
<script type="text/javascript" src="car.js"></script>
<link rel="stylesheet" href="car.css">
</head>
@@ -27,14 +27,31 @@
<tr style="height: 18px;">
<td style="width: 33.3333%; height: 18px; text-align: left;"><button id="reverse_left" class="wz_car_BUTTON">z: rear left</button></td>
<td style="width: 33.3333%; height: 18px; text-align: center;"><button id="all_stop" class="wz_car_BUTTON">x: all stop</button></td>
<td style="width: 33.3333%; height: 18px; text-align: right;"><button id="reverse_right" class="wz_car_BUTTON">c: rear right</button></td>
<td style="width: 33.3333%; height: 18px; text-align: right;"><button id="reverse_right" class="wz_car_BUTTON">c: rear right</button></td>
</tr>
<td style="width: 33.3333%; height: 21px; text-align: left;"><button id="headlight" class="wz_car_BUTTON">H: headlight</button></td>
<td style="width: 33.3333%; height: 18px; text-align: center;"><button id="irled" class="wz_car_BUTTON">j: ir led</button></td>
<td style="width: 33.3333%; height: 18px; text-align: center;"><button id="honk" class="wz_car_BUTTON">b: honk</button></td>
<td style="width: 33.3333%; height: 18px; text-align: center;">
<button id="headlight_on" class="wz_car_BUTTON_N">h: headlight on</button>
<button id="headlight_off" class="wz_car_BUTTON_N">g: headlight off</button>
</td>
<td style="width: 33.3333%; height: 18px; text-align: center;"><button id="irled_on" class="wz_car_BUTTON">j: ir led on</button><button id="irled_off" class="wz_car_BUTTON">k: ir led off</button></td>
<td style="width: 33.3333%; height: 18px; text-align: right;"><button id="honk" class="wz_car_BUTTON">b: honk</button></td>
</tr>
</tbody>
</table>
<p><img id="car_feed" src="/cgi-bin/jpeg.cgi?channel=1" /></p>
Speed Sleep: <input type="text" size=5 id="sleep_timer" name="sleep_timer" value="0.15">
Car Speed:
<input type="radio" id="speed_fast" class="speed" name="fast" value="fast">
<label for="fast">Fast</label>
<input type="radio" id="speed_slow" class="speed" name="slow" value="slow">
<label for="slow">Slow</label>
<button onclick="set_vars()">Set Variables</button>
</body>
</html>

View File

@@ -1,12 +1,34 @@
const queryString = window.location.search;
console.log(queryString);
const urlParams = new URLSearchParams(queryString);
const speed = urlParams.get('speed')
console.log("speed is", speed);
const sleep_timer = urlParams.get('sleep_time')
console.log("sleep_timer is", sleep_timer);
function set_sleep() {
sleep_timer2 = document.getElementById("sleep_timer").value;
window.location = "car.html?sleep_time=" + sleep_timer2;
}
function set_vars() {
sleep_timer2 = document.getElementById("sleep_timer").value;
var speed = $('input[class="speed"]:checked').val();
window.location = "car.html?sleep_time=" + sleep_timer2 + "&speed=" + speed;
}
var wz_mini_car = {
post: function(action)
{
$.post("../cgi-bin/car.sh", action);
$.post( "../cgi-bin/car.sh", { speed: speed, action: action, sleep_time: sleep_timer } );
} ,
init: function() {
this.logarray = [];
$('.wz_car_BUTTON').on('click',function(e){
$("[class*='BUTTON']").on('click',function(e) {
var action = $(this).attr('id');
wz_mini_car.post(action);
});
@@ -27,10 +49,11 @@ var wz_mini_car = {
case "z": action = "reverse_left"; break;
case "c": action = "reverse_right" ; break;
case "x": action = "all_stop" ; break;
/* everything was "x" below here ... assigned other letters */
case "h": action = "headlight" ; break;
case "i": action = "irled" ; break;
case "k": action = "honk" ; break;
case "h": action = "headlight_on" ; break;
case "g": action = "headlight_off" ; break;
case "j": action = "irled_on" ; break;
case "k": action = "irled_off" ; break;
case "b": action = "honk" ; break;
}
if (action) {
wz_mini_car.post(action);
@@ -47,3 +70,8 @@ var wz_mini_car = {
$(document).ready(function() {
wz_mini_car.init();
});
setInterval(function() {
var myImageElement = document.getElementById('car_feed');
myImageElement.src = '/cgi-bin/jpeg.cgi?channel=1&rand=' + Math.random();
}, 1000);

View File

@@ -1,59 +1,91 @@
#!/bin/sh
SLEEP_TIME=0.1
set -x
echo "HTTP/1.1 200"
echo -e "Content-type: text/html\n\n"
echo ""
read POST_STRING
if [ "$POST_STRING" = "forward" ]; then
SPEED=$(echo $POST_STRING | sed 's/.*speed=//;s/\&.*//')
ACTION=$(echo $POST_STRING | sed 's/.*action=//;s/\&.*//')
SLEEP_TIME=$(echo $POST_STRING | sed 's/.*sleep_time=//;s/\&.*//')
echo "raw post string: $POST_STRING"
echo "speed: $SPEED"
echo "action: $ACTION"
echo "sleep: $SLEEP_TIME"
if [ "$ACTION" = "forward" ]; then
if [ "$SPEED" = "slow" ]; then
echo "slow"
echo -ne "\xaa\x55\x43\x06\x29\x80\xca\x00\x02\xbb" > /dev/ttyUSB0
else
echo "forward"
echo -ne "\xaa\x55\x43\x06\x29\x80\xe3\x00\x02\xd4" > /dev/ttyUSB0
sleep $SLEEP_TIME
echo -ne "\xaa\x55\x43\x06\x29\x80\x80\x00\x02\x71" > /dev/ttyUSB0
elif [ "$POST_STRING" = "reverse" ]; then
echo -ne "\xaa\x55\x43\x06\x29\x80\xe3\x00\x02\xd4" > /dev/ttyUSB0
fi
sleep $SLEEP_TIME
echo -ne "\xaa\x55\x43\x06\x29\x80\x80\x00\x02\x71" > /dev/ttyUSB0
elif [ "$ACTION" = "reverse" ]; then
echo "reverse"
echo -ne "\xaa\x55\x43\x06\x29\x80\x36\x00\x02\x27" > /dev/ttyUSB0
sleep $SLEEP_TIME
echo -ne "\xaa\x55\x43\x06\x29\x80\x80\x00\x02\x71" > /dev/ttyUSB0
elif [ "$POST_STRING" = "left" ]; then
elif [ "$ACTION" = "left" ]; then
echo "left"
echo -ne "\xaa\x55\x43\x06\x29\x76\x81\x00\x02\x68" > /dev/ttyUSB0
sleep $SLEEP_TIME
echo -ne "\xaa\x55\x43\x06\x29\x80\x80\x00\x02\x71" > /dev/ttyUSB0
elif [ "$POST_STRING" = "right" ]; then
elif [ "$ACTION" = "right" ]; then
echo "right"
echo -ne "\xaa\x55\x43\x06\x29\x8a\x81\x00\x02\x7c" > /dev/ttyUSB0
sleep $SLEEP_TIME
echo -ne "\xaa\x55\x43\x06\x29\x80\x80\x00\x02\x71" > /dev/ttyUSB0
elif [ "$POST_STRING" = "forward_left" ]; then
elif [ "$ACTION" = "forward_left" ]; then
echo "left_forward"
echo -ne "\xaa\x55\x43\x06\x29\x76\xe3\x00\x02\xca" > /dev/ttyUSB0
sleep $SLEEP_TIME
echo -ne "\xaa\x55\x43\x06\x29\x80\x80\x00\x02\x71" > /dev/ttyUSB0
elif [ "$POST_STRING" = "forward_right" ]; then
elif [ "$ACTION" = "forward_right" ]; then
echo "right_forward"
echo -ne "\xaa\x55\x43\x06\x29\x8a\xe3\x00\x02\xde" > /dev/ttyUSB0
sleep $SLEEP_TIME
echo -ne "\xaa\x55\x43\x06\x29\x80\x80\x00\x02\x71" > /dev/ttyUSB0
elif [ "$POST_STRING" = "reverse_left" ]; then
elif [ "$ACTION" = "reverse_left" ]; then
echo "left_reverse"
echo -ne "\xaa\x55\x43\x06\x29\x76\x36\x00\x02\x1d" > /dev/ttyUSB0
sleep $SLEEP_TIME
echo -ne "\xaa\x55\x43\x06\x29\x80\x80\x00\x02\x71" > /dev/ttyUSB0
elif [ "$POST_STRING" = "reverse_right" ]; then
elif [ "$ACTION" = "reverse_right" ]; then
echo "right_reverse"
echo -ne "\xaa\x55\x43\x06\x29\x8a\x36\x00\x02\x31" > /dev/ttyUSB0
sleep $SLEEP_TIME
echo -ne "\xaa\x55\x43\x06\x29\x80\x80\x00\x02\x71" > /dev/ttyUSB0
elif [ "$POST_STRING" = "all_stop" ]; then
elif [ "$ACTION" = "all_stop" ]; then
echo "all stop"
echo -ne "\xaa\x55\x43\x06\x29\x80\x80\x00\x02\x71" > /dev/ttyUSB0
elif [ "$POST_STRING" = "headlight" ]; then
echo "headlight"
headlight
elif [ "$POST_STRING" = "irled" ]; then
echo "irled"
irled
elif [ "$POST_STRING" = "honk" ]; then
elif [ "$ACTION" = "headlight_on" ]; then
echo "headlight_on"
echo -ne "\xaa\x55\x43\x04\x1e\x01\x01\x65" > /dev/ttyUSB0
elif [ "$ACTION" = "headlight_off" ]; then
echo "headlight_off"
echo -ne "\xaa\x55\x43\x04\x1e\x02\x01\x66" > /dev/ttyUSB0
elif [ "$ACTION" = "irled_on" ]; then
echo "irled_on"
cmd irled on > /dev/null
elif [ "$ACTION" = "irled_off" ]; then
echo "irled_off"
cmd irled off > /dev/null
elif [ "$ACTION" = "honk" ]; then
echo "honk"
/opt/wz_mini/bin/cmd aplay /opt/wz_mini/usr/share/audio/honk.wav 70 > /dev/null 2>&1 &