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

NanoVNA-H 4 screen capture #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 index.html
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ <h3 class="md-title" style="flex: 1">NanoVNA</h3>
<md-dialog :md-active.async="showCaptureDialog">
<md-dialog-title>Capture</md-dialog-title>
<md-dialog-content>
<canvas ref="capture" width="320" height="240" style="image-rendering: pixelated;"></canvas>
<canvas ref="capture" style="image-rendering: pixelated;"></canvas>
<md-progress-bar md-mode="indeterminate" v-show="capturing"></md-progress-bar>
</md-dialog-content>
<md-dialog-actions>
Expand Down
5 changes: 1 addition & 4 deletions nanovna.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,7 @@ class NanoVNA_Base {
return await this.sendCommand(`version\r`, async () => await this.readline());
}

async getCapture() {
const width = 320;
const height = 240;

async getCapture(width = 320, height = 240) {
const string = await this.sendCommand(`capture\r`, async () => await this.read(width * height * 2));
const uint16view = new Uint16Array(width * height);
for (var i = 0, len = width * height; i < len; i++) {
Expand Down
28 changes: 26 additions & 2 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,23 @@ function formatFrequency(freq, f) {
}
}

function deserializeInfo(infoStr) {
return Object.fromEntries(
infoStr.split('\n').map(row => {
let [key, val] = row.split(/:\s+/);
key = key.toLowerCase().replace(/\s+/, '');
return [key, val.trim()];
})
)
}

function resolution(board) {
if(board === 'NanoVNA-H 4') {
return [480, 320];
}
return [320, 240];
}

async function downloadFile(url, name) {
if (typeof Capacitor === 'undefined') {
const a = document.createElement('a');
Expand Down Expand Up @@ -328,6 +345,8 @@ new Vue({
buildTimeStr: '',
buildTime: null,
info: '',
board: '',
resolution: null,
},
webVersion: "",
serialMode: NanoVNA.name.replace(/^NanoVNA_/, ''),
Expand Down Expand Up @@ -408,9 +427,11 @@ new Vue({

this.deviceInfo.version = await this.backend.getVersion();
this.deviceInfo.info = await this.backend.getInfo();
this.deviceInfo.board = deserializeInfo(this.deviceInfo.info).board;
this.deviceInfo.buildTimeStr = this.deviceInfo.info.match(/Build time:\s*(([a-z]{3})\s*(\d?\d) (\d{4}) - (\d?\d):(\d?\d):(\d?\d))/i)[1] || '';
this.deviceInfo.buildTimeStr = this.deviceInfo.buildTimeStr.replace(/\s+/g, ' ');
this.deviceInfo.buildTime = strptime(this.deviceInfo.buildTimeStr, '%B %d %Y - %H:%M:%S');
this.deviceInfo.resolution = resolution(this.deviceInfo.board);
this.deviceInfo.versionNumber = versionNumber(this.deviceInfo.version);

const v = this.deviceInfo.versionNumber || 0;
Expand Down Expand Up @@ -705,11 +726,14 @@ new Vue({
capture: async function () {
this.showCaptureDialog = true;
this.capturing = true;
const data = await this.backend.getCapture();
const [width, height] = this.deviceInfo.resolution;
const data = await this.backend.getCapture(width, height);

const canvas = this.$refs.capture;
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext('2d');
const imd = ctx.createImageData(320, 240);
const imd = ctx.createImageData(width, height);
const rgba = imd.data;
for (var i = 0, len = data.length; i < len; i++) {
const c565 = data[i];
Expand Down
4 changes: 2 additions & 2 deletions worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ class Worker {
return await this.nanovna.scan(start, stop, length);
}

async getCapture() {
return await this.nanovna.getCapture();
async getCapture(width, height) {
return await this.nanovna.getCapture(width, height);
}

async recall(n) {
Expand Down