Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add read data feature #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CNAME
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dotmatrixtool.com
#dotmatrixtool.com
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Dot Matrix Tool

Edited version, with feature of read back data
https://hxlvelectronicclub.github.io/dotmatrixtool/


Below is from the oringinal repo.

A web application for generating character or image byte arrays for dot matrix style OLED or LCD displays.

Use it live at http://dotmatrixtool.com
Expand Down
42 changes: 38 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function updateTable() {
var height = matrix.length;

$('#_grid').html('');
$('#_grid').append(populateTable(null, height, width, ""));
$('#_grid').append(populateTable(null, height, width, matrix));

// events
$table.on("mousedown", "td", toggle);
Expand All @@ -25,9 +25,10 @@ function updateTable() {
}

function initOptions() {
$('#clearButton').click(function() { matrix = createArray(matrix.length,matrix[0].length); updateTable(); $('#_output').hide(); });
$('#clearButton').click(function() { matrix = createArray(matrix.length,matrix[0].length); updateTable(); $('#_output').hide();});
$('#generateButton').click(updateCode);

$('#readButton').click(readData);

$('#widthDropDiv li a').click(function () {
var width = parseInt($(this).html());
var height = matrix.length;
Expand Down Expand Up @@ -82,6 +83,36 @@ function updateCode() {
prettyPrint();
}

function readData() {
var bytestr = prompt("Input your data here, in hex format: 0x1, 0x2");
if (!bytestr) return;
var width = matrix.length;
stefangordon marked this conversation as resolved.
Show resolved Hide resolved
var height = matrix[0].length;
var bytes = bytestr.split(',').map(function (x) { return parseInt(x)});

var byteinarow=Math.ceil(width/8);
var byteinacol=Math.ceil(height/8);
var byteindex ;
var bitindex;
for (var y=0;y<height;y++) {
for(var x=0;x<width;x++) {
if (rowMajor) {
byteindex = y*byteinarow + Math.floor(x/8);
bitindex = x%8;
} else {
byteindex = x*byteinacol + Math.floor(y/8);
bitindex = y%8;
}
if (msbendian) bitindex = 7-bitindex;
matrix[y][x] = (bytes[byteindex] >> bitindex) & 0x1;
}
}
updateTable();
updateSummary();
updateCode();
}


function generateByteArray() {
var width = matrix[0].length;
var height = matrix.length;
Expand Down Expand Up @@ -157,8 +188,11 @@ function populateTable(table, rows, cells, content) {
row.appendChild(document.createElement('td'));
$(row.cells[j]).data('i', i);
$(row.cells[j]).data('j', j);
if (content[i][j]) {
$(row.cells[j]).addClass('on');
}
}
table.appendChild(row);
table.appendChild(row);
}
$table = $(table);
return table;
Expand Down
20 changes: 4 additions & 16 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,6 @@

<!-- Custom styles for this template -->
<link href="cover.css" rel="stylesheet">

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-276334-9', 'auto');
ga('send', 'pageview');
</script>
</head>

<body>
Expand Down Expand Up @@ -59,7 +44,10 @@
<div class="col-xs-12" style="height:20px;"></div>
<!-- Options -->
<div class="btn-group">
<button type="button" class="btn btn-default" id="generateButton">Generate</button>
<button type="button" class="btn btn-default" id="generateButton">Generate Data</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-default" id="readButton">Read Data</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-default" id="clearButton">Clear</button>
Expand Down