Skip to content

Commit

Permalink
Handle Emulator Notification: {"nuttxemu":{"gpio29":1}}
Browse files Browse the repository at this point in the history
  • Loading branch information
lupyuen committed Feb 12, 2024
1 parent 6d11fa6 commit 2cadf80
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 17 deletions.
40 changes: 24 additions & 16 deletions docs/quickjs/index.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>JSLinux</title>
<link href="style.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<div id="term_wrap">
<div id="term_container">
</div>
<div id="term_bar">
<label>
<img title="Upload files" src="images/upload-icon.png"><input type="file" id="files" multiple onchange="on_update_files(this.files)">
</label>
<progress id="net_progress">
</progress>
</div>
</div>
<script type="text/javascript" src="term.js"></script>
<script type="text/javascript" src="jslinux.js"></script>
<div id="copyright"><a href="https://github.com/lupyuen/nuttx-tinyemu">Apache NuttX RTOS on TinyEMU: How it works</a></div>
<div id="copyright">&copy; 2011-2021 Fabrice Bellard</div>
<div id="term_wrap">
<div id="term_container">
</div>
<div id="term_bar">
<label>
<img title="Upload files" src="images/upload-icon.png"><input type="file" id="files" multiple onchange="on_update_files(this.files)">
</label>
<progress id="net_progress">
</progress>
</div>
</div>
<script type="text/javascript" src="term.js"></script>
<script type="text/javascript" src="jslinux.js"></script>
<table id="status">
<tr>
<td>
<div id="copyright"><a href="https://github.com/lupyuen/nuttx-tinyemu">Apache NuttX RTOS on TinyEMU: How it works</a></div>
<div id="copyright">&copy; 2011-2021 Fabrice Bellard</div>
</td>
<td id="gpio29" style="text-align: center; display: none">GPIO29</td>
</tr>
</table>
</body>
</html>
Binary file modified docs/quickjs/riscvemu64-wasm.wasm
Binary file not shown.
14 changes: 13 additions & 1 deletion docs/quickjs/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,16 @@ label {
#net_progress {
visibility: hidden;
width: 80px;
}
}

/* NuttX Emulator Status */

.gpio_off {
color: black;
background-color: transparent;
}

.gpio_on {
color: white;
background-color: green;
}
18 changes: 18 additions & 0 deletions docs/quickjs/term.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,24 @@ Term.prototype.scroll_disp = function(n)

Term.prototype.write = function(str)
{
//// Begin Test: Handle Emulator Notification: {"nuttxemu":{"gpio29":1}}
if (str.indexOf(`{"nuttxemu":`) == 0) {
const notify = JSON.parse(str).nuttxemu; // {gpio29:1}
console.log({ notify });
const gpio = Object.keys(notify)[0]; // "gpio29"
const val = notify[gpio]; // 0 or 1
console.log({ gpio, val });

document.getElementById("status").style.width = document.getElementById("term_wrap").style.width;
const gpio_status = document.getElementById(gpio);
gpio_status.style.display = "block";
gpio_status.className = (val == 0)
? "gpio_off"
: "gpio_on";
return;
}
//// End Test

var s, ymin, ymax;

function update(y)
Expand Down

0 comments on commit 2cadf80

Please sign in to comment.