-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
OpenAcousticDevices
authored
Jul 31, 2017
1 parent
e04ab5b
commit 3b428ef
Showing
16 changed files
with
1,686 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.min.css"> | ||
<title>About AudioMoth</title> | ||
</head> | ||
<body style="text-align: center; -webkit-user-select: none; -webkit-app-region: drag;"> | ||
<div class="container"> | ||
<div class="row" style="margin-top: 5%;"><img src="icon-128.png"></div> | ||
<div class="row" style="font-weight: bold;">AudioMoth configuration app</div> | ||
<div class="row" id="version-display">Version 1.0</div> | ||
<div class="row" id="electron-version-display">Running on Electron version 1.0</div> | ||
<div class="row" id="audiomoth-hid-version-display">AudioMoth-HID module 1.0.0</div> | ||
<div class="row"><a id="website-link">www.openacousticdevices.info</a></div> | ||
</div> | ||
</body> | ||
<script src="about.js" charset="utf-8"></script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/**************************************************************************** | ||
* about.js | ||
* openacousticdevices.info | ||
* June 2017 | ||
*****************************************************************************/ | ||
|
||
'use strict'; | ||
|
||
/*global document */ | ||
|
||
var electron = require('electron'); | ||
var audiomoth = require('audiomoth-hid'); | ||
|
||
var versionDisplay = document.getElementById('version-display'); | ||
var electronVersionDisplay = document.getElementById('electron-version-display'); | ||
var audiomothHidVersionDisplay = document.getElementById('audiomoth-hid-version-display'); | ||
var websiteLink = document.getElementById('website-link'); | ||
|
||
versionDisplay.textContent = "Version " + electron.remote.app.getVersion(); | ||
electronVersionDisplay.textContent = "Running on Electron version " + electron.remote.process.versions.electron; | ||
audiomothHidVersionDisplay.textContent = "AudioMoth-HID module " + audiomoth.version; | ||
|
||
websiteLink.addEventListener('click', function () { | ||
electron.shell.openExternal("https://openacousticdevices.info"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,267 @@ | ||
/**************************************************************************** | ||
* app.js | ||
* openacousticdevices.info | ||
* June 2017 | ||
*****************************************************************************/ | ||
|
||
'use strict'; | ||
|
||
/*global document, Uint8Array*/ | ||
/*jslint bitwise: true*/ | ||
|
||
var audiomoth = require('audiomoth-hid'); | ||
|
||
var ui = require('./ui.js'); | ||
var timeHandler = require('./timePeriods.js'); | ||
var saveLoad = require('./saveLoad.js'); | ||
var lifeDisplay = require('./lifeDisplay.js'); | ||
|
||
var electron = require('electron'); | ||
var dialog = electron.remote.dialog; | ||
|
||
/* UI components */ | ||
|
||
var ledCheckbox = document.getElementById('led-checkbox'); | ||
|
||
var recordingDurationInput = document.getElementById('recording-duration-input'); | ||
var sleepDurationInput = document.getElementById('sleep-duration-input'); | ||
|
||
var configureButton = document.getElementById('configure-button'); | ||
|
||
var startTimeInput = document.getElementById('start-time-input'); | ||
var endTimeInput = document.getElementById('end-time-input'); | ||
|
||
/* Setting parameters */ | ||
|
||
var AM_HFRCO_21MHZ = 4; | ||
var AM_HFRCO_28MHZ = 5; | ||
var AM_HFXO = 6; | ||
|
||
var configurations = [{ | ||
sampleRate: 8000, | ||
clockBand: AM_HFRCO_21MHZ, | ||
clockDivider: 2, | ||
acquisitionCycles: 8, | ||
oversampleRate: 64, | ||
current: 5.6 | ||
}, { | ||
sampleRate: 16000, | ||
clockBand: AM_HFRCO_21MHZ, | ||
clockDivider: 2, | ||
acquisitionCycles: 8, | ||
oversampleRate: 32, | ||
current: 6.1 | ||
}, { | ||
sampleRate: 32000, | ||
clockBand: AM_HFRCO_21MHZ, | ||
clockDivider: 2, | ||
acquisitionCycles: 8, | ||
oversampleRate: 16, | ||
current: 7.1 | ||
}, { | ||
sampleRate: 48000, | ||
clockBand: AM_HFRCO_21MHZ, | ||
clockDivider: 2, | ||
acquisitionCycles: 2, | ||
oversampleRate: 16, | ||
current: 7.6 | ||
}, { | ||
sampleRate: 96000, | ||
clockBand: AM_HFRCO_21MHZ, | ||
clockDivider: 2, | ||
acquisitionCycles: 1, | ||
oversampleRate: 8, | ||
current: 10.4 | ||
}, { | ||
sampleRate: 192000, | ||
clockBand: AM_HFRCO_21MHZ, | ||
clockDivider: 2, | ||
acquisitionCycles: 1, | ||
oversampleRate: 4, | ||
current: 18.1 | ||
}]; | ||
|
||
function errorOccurred(err) { | ||
|
||
console.error(err); | ||
|
||
ui.disableDisplay(); | ||
|
||
} | ||
|
||
/* Request, receive and handle AudioMoth information packet */ | ||
|
||
function getAudioMothPacket() { | ||
|
||
var id, date, batteryState; | ||
|
||
audiomoth.getPacket(function (err, packet) { | ||
|
||
if (err) { | ||
|
||
errorOccurred(err); | ||
|
||
} else if (packet === null) { | ||
|
||
ui.disableDisplay(); | ||
|
||
} else { | ||
|
||
date = audiomoth.convertFourBytesFromBufferToDate(packet, 1); | ||
|
||
id = audiomoth.convertEightBytesFromBufferToID(packet, 1 + 4); | ||
|
||
batteryState = audiomoth.convertOneByteFromBufferToBatteryState(packet, 1 + 4 + 8); | ||
|
||
ui.enableDisplayAndShowTime(date); | ||
|
||
ui.updateIdDisplay(id); | ||
|
||
ui.updateBatteryDisplay(batteryState); | ||
|
||
} | ||
|
||
setTimeout(getAudioMothPacket, 1000); | ||
|
||
}); | ||
|
||
} | ||
|
||
/* Write bytes into a buffer for transmission */ | ||
|
||
function writeLittleEndianBytes(buffer, start, byteCount, value) { | ||
var i; | ||
|
||
for (i = 0; i < byteCount; i += 1) { | ||
buffer[start + i] = (value >> (i * 8)) & 255; | ||
} | ||
} | ||
|
||
/* Submit configuration packet and configure device */ | ||
|
||
function configureDevice() { | ||
|
||
var packet, index, date, configuration, i, timePeriods; | ||
|
||
/* Build configuration packet */ | ||
|
||
packet = new Uint8Array(62); | ||
index = 0; | ||
|
||
date = new Date(); | ||
writeLittleEndianBytes(packet, index, 4, date.valueOf() / 1000); | ||
index += 4; | ||
|
||
packet[index] = parseInt(ui.getSelectedRadioValue("gain-radio"), 10); | ||
index += 1; | ||
|
||
configuration = configurations[parseInt(ui.getSelectedRadioValue("sample-rate-radio"), 10)]; | ||
|
||
packet[index] = configuration.clockBand; | ||
index += 1; | ||
packet[index] = configuration.clockDivider; | ||
index += 1; | ||
packet[index] = configuration.acquisitionCycles; | ||
index += 1; | ||
packet[index] = configuration.oversampleRate; | ||
index += 1; | ||
writeLittleEndianBytes(packet, index, 4, configuration.sampleRate); | ||
index += 4; | ||
|
||
writeLittleEndianBytes(packet, index, 2, sleepDurationInput.value); | ||
index += 2; | ||
writeLittleEndianBytes(packet, index, 2, recordingDurationInput.value); | ||
index += 2; | ||
|
||
if (ledCheckbox.checked) { | ||
|
||
packet[index] = 0x01; | ||
|
||
} else { | ||
|
||
packet[index] = 0x00; | ||
|
||
} | ||
index += 1; | ||
|
||
timePeriods = timeHandler.getTimePeriods(); | ||
packet[index] = timePeriods.length; | ||
index += 1; | ||
|
||
for (i = 0; i < timePeriods.length; i += 1) { | ||
|
||
writeLittleEndianBytes(packet, index, 2, timePeriods[i].startMins); | ||
index += 2; | ||
writeLittleEndianBytes(packet, index, 2, timePeriods[i].endMins); | ||
index += 2; | ||
|
||
} | ||
|
||
/* Send packet to device */ | ||
|
||
audiomoth.setPacket(packet, function (err, data) { | ||
|
||
var j, matches, showError; | ||
|
||
showError = function () { | ||
dialog.showErrorBox("Configuration failed.", "Configuration was not applied to AudioMoth\nPlease reconnect device and try again."); | ||
}; | ||
|
||
if (err || data === null || data.length === 0) { | ||
|
||
showError(); | ||
|
||
} else { | ||
|
||
matches = true; | ||
|
||
for (j = 0; j < Math.min(packet.length, data.length - 1); j += 1) { | ||
if (packet[j] !== data[j + 1]) { | ||
console.log(packet[j] + ' - ' + data[j + 1]); | ||
matches = false; | ||
break; | ||
} | ||
} | ||
|
||
if (matches) { | ||
|
||
configureButton.style.color = "green"; | ||
setTimeout(function () { | ||
configureButton.style.color = ""; | ||
}, 1000); | ||
|
||
} else { | ||
|
||
showError(); | ||
|
||
} | ||
|
||
} | ||
|
||
}); | ||
|
||
} | ||
|
||
/* Initiliase lifeDisplay configuration data */ | ||
|
||
lifeDisplay.setConfigurationData(configurations); | ||
|
||
/* Initialise UI elements */ | ||
|
||
ui.drawTimeLabels(); | ||
|
||
timeHandler.updateTimeList(); | ||
|
||
ui.updateCanvasTimer(); | ||
|
||
ui.disableDisplay(); | ||
|
||
ui.initialiseDisplay(); | ||
|
||
ui.addRadioButtonListeners(); | ||
|
||
setTimeout(getAudioMothPacket, 1000); | ||
|
||
configureButton.addEventListener('click', function () { | ||
ui.checkInputs(configureDevice); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
for f in ./*.js; | ||
do | ||
js-beautify -j -f $f -o $f; | ||
jslint $f; | ||
done | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.