Browse Source

send messages

main
Hendrik Langer 4 years ago
parent
commit
b607293496
  1. 16
      raspberry/roberto/views/frontend/templates/index.html
  2. 9
      raspberry/roberto/views/websocket/routes.py
  3. 5
      trigorilla/src/main.cpp

16
raspberry/roberto/views/frontend/templates/index.html

@ -23,6 +23,12 @@
position: relative; position: relative;
z-index: 1; z-index: 1;
} }
#message {
position: absolute;
z-index: 1;
top: 20px;
right: 50px
}
</style> </style>
</head> </head>
<body> <body>
@ -34,7 +40,10 @@
<canvas id="textoverlay"></canvas> <canvas id="textoverlay"></canvas>
<div id="controls"></div> <div id="controls"></div>
</div> </div>
<form id="message" method="POST" action='#'>
<input type="text" name="message_data" id="message_data" placeholder="Message">
<input type="submit" value="Send">
</form>
<!--<h2 id="start">Press a button on your controller to start</h2>--> <!--<h2 id="start">Press a button on your controller to start</h2>-->
@ -148,6 +157,11 @@ socket.on('data', (data) => {
ctx.font = "24px Arial"; ctx.font = "24px Arial";
ctx.fillStyle = "blue"; ctx.fillStyle = "blue";
//ctx.fillText("Hello World", canvas.width/3, 30); //ctx.fillText("Hello World", canvas.width/3, 30);
$('form#message').submit(function(event) {
gp_socket.emit('text', {data: $('#message_data').val()});
return false;
});
}; };
</script> </script>

9
raspberry/roberto/views/websocket/routes.py

@ -53,6 +53,15 @@ def applyDeadZone(value, threshold):
new_value = new_value * -1 new_value = new_value * -1
return new_value return new_value
@socketio.on('text', namespace='/gamepad')
def display_text(text):
print("display_text()")
print(text['data'])
if isinstance(text['data'], str):
if len(text['data']) < 250:
from roberto import serial
command = 'T '+str(text['data'])
serial.write(bytes(command, "utf8"))
# https://pfertyk.me/2020/03/webrtc-a-working-example/ # https://pfertyk.me/2020/03/webrtc-a-working-example/

5
trigorilla/src/main.cpp

@ -158,6 +158,11 @@ void loop()
Serial.print(values[2]); Serial.print(", "); Serial.print(values[2]); Serial.print(", ");
Serial.print(values[3]); Serial.print("\n"); Serial.print(values[3]); Serial.print("\n");
} }
} else if (command.charAt(0) == 'T') {
String message = command.substring(3);
char* text = message.c_str();
lcd.setCursor(0,2);
lcd.print(text);
} }
} }

Loading…
Cancel
Save