Skip to content

Commit d75b9d9

Browse files
committed
eepy v1.0.6
1 parent a49d2b8 commit d75b9d9

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

doodles/eepy-web/ble.js

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ let esp_pin_left_b = 16; // m1b
1919
let esp_pin_right_a = 23; // m2a
2020
let esp_pin_right_b = 22; // m2b
2121

22+
let queued_ble_write = null;
23+
2224
//===========================================
2325
// get handles to elements
2426
//===========================================
@@ -162,10 +164,31 @@ function generate_cmd(pin, state) {
162164
return `:w${pin}${state}`;
163165
}
164166

165-
function send_cmd(cmd) {
167+
function queue_cmd(cmd) {
168+
queued_ble_write = cmd;
169+
}
170+
171+
function send_cmd() {
172+
173+
// if no command is queued then return
174+
if (queued_ble_write == null) return
175+
176+
console.log("sending queued command: " + queued_ble_write);
177+
178+
// otherwise, send queued command
166179
const utf8encoder = new TextEncoder();
167-
let cmd_bytes = utf8encoder.encode(cmd);
168-
return ble_char_nrf_uart_rx.writeValueWithoutResponse(cmd_bytes);
180+
let cmd_bytes = utf8encoder.encode(queued_ble_write);
181+
182+
// command is about to be sent, clear queue
183+
queued_ble_write = null;
184+
185+
// send command
186+
ble_char_nrf_uart_rx.writeValueWithoutResponse(cmd_bytes).then(_ => {
187+
188+
// once command has written, write next command
189+
send_cmd();
190+
191+
})
169192
}
170193

171194
function write_pin(pin, state) {
@@ -181,50 +204,55 @@ function write_pin(pin, state) {
181204

182205
function drive_stop() {
183206
console.log("stopping");
184-
send_cmd(([
207+
queue_cmd(([
185208
generate_cmd(esp_pin_left_a, 0),
186209
generate_cmd(esp_pin_left_b, 0),
187210
generate_cmd(esp_pin_right_a, 0),
188211
generate_cmd(esp_pin_right_b, 0),
189212
]).join(";"))
213+
send_cmd();
190214
}
191215

192216
function drive_forward() {
193217
console.log("driving forward");
194-
send_cmd(([
218+
queue_cmd(([
195219
generate_cmd(esp_pin_left_a, 1),
196220
generate_cmd(esp_pin_left_b, 0),
197221
generate_cmd(esp_pin_right_a, 1),
198222
generate_cmd(esp_pin_right_b, 0),
199223
]).join(";"))
224+
send_cmd();
200225
}
201226

202227
function drive_backward() {
203228
console.log("driving backward");
204-
send_cmd(([
229+
queue_cmd(([
205230
generate_cmd(esp_pin_left_a, 0),
206231
generate_cmd(esp_pin_left_b, 1),
207232
generate_cmd(esp_pin_right_a, 0),
208233
generate_cmd(esp_pin_right_b, 1),
209234
]).join(";"))
235+
send_cmd();
210236
}
211237

212238
function drive_rot_right() {
213239
console.log("driving right");
214-
send_cmd(([
240+
queue_cmd(([
215241
generate_cmd(esp_pin_left_a, 0),
216242
generate_cmd(esp_pin_left_b, 1),
217243
generate_cmd(esp_pin_right_a, 1),
218244
generate_cmd(esp_pin_right_b, 0),
219245
]).join(";"))
246+
send_cmd();
220247
}
221248

222249
function drive_rot_left() {
223250
console.log("driving left");
224-
send_cmd(([
251+
queue_cmd(([
225252
generate_cmd(esp_pin_left_a, 1),
226253
generate_cmd(esp_pin_left_b, 0),
227254
generate_cmd(esp_pin_right_a, 0),
228255
generate_cmd(esp_pin_right_b, 1),
229256
]).join(";"))
257+
send_cmd();
230258
}

doodles/eepy-web/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ <h2>BLE Robot Controller</h2>
3939
</tr>
4040
</table>
4141

42-
<p class="version fs-6 text-secondary">v1.0.5</p>
42+
<p class="version fs-6 text-secondary">v1.0.6</p>
4343
</div>
4444

4545
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js" integrity="sha384-FKyoEForCGlyvwx9Hj09JcYn3nv7wiPVlz7YYwJrWVcXK/BmnVDxM+D2scQbITxI" crossorigin="anonymous"></script>

0 commit comments

Comments
 (0)