* add @angular/cli to the project * increase nodejs version -> 8.2.1 * add lerna * merge web and shared module * move electron module into packages as uhk-agent Electron agent functionality is not working * delete symlinker * convert private properties to public of component if used in html * revert uhk-message.component * fix component path * fix the correct name of the uhk-message.component.scss * building web and electron module * delete uhk-renderer package * handle device connect disconnect state * add privilege detection * fix set privilege functionality * turn back download keymap functionality * add bootstrap, select2 js and fix null pointer exception * turn back upload data to keyboard * fix send keymap * fix test-serializer * add missing package.json * merging * fix appveyor build * fix linting * turn back electron storage service * commit the missing electron-datastorage-repository * update node to 8.3.0 in .nvmrc and log node version in appveyor build * set exact version number in appveyor build * vertical align privilege and missing device components * set back node version to 8 in appveyor * move node-usb dependency from usb dir to root maybe it is fix the appveyor build * revert usb to root * fix electron builder script * fix electron builder script * turn off electron devtools * remove CTRL+U functionality * fix CTRL+o * fix lint error * turnoff store freeze * start process when got `Error: EPERM: operation not permitted` error * move files from root usb dir -> packages/usb
102 lines
3.6 KiB
JavaScript
Executable File
102 lines
3.6 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
'use strict';
|
|
|
|
var UhkConnection = require('./UhkConnection');
|
|
var R = require('ramda');
|
|
var path = require('path');
|
|
|
|
var ENUMERATION_MODE_IDS = R.pluck('id', UhkConnection.ENUMERATION_MODES);
|
|
var commands = getTypistFriendlyObjectKeys(R.keys(UhkConnection.COMMANDS));
|
|
var args = process.argv.slice(1);
|
|
var programName = path.basename(args.shift());
|
|
var commandArg = args.shift();
|
|
|
|
if (!R.contains(commandArg, commands)) {
|
|
console.error('Usage: ' + programName + ' COMMAND [ARG]');
|
|
console.error(commandArg === undefined
|
|
? 'No command has been specified.'
|
|
: 'Command "' + commandArg + '" is invalid.');
|
|
console.error('Valid commands: ' + commands.join(', '));
|
|
exitWithError();
|
|
}
|
|
|
|
var command = UhkConnection.COMMANDS[getTypistUnfriendlyObjectKey(commandArg)];
|
|
var uhkConnection;
|
|
|
|
switch (command) {
|
|
case UhkConnection.COMMANDS.DETECT:
|
|
uhkConnection = new UhkConnection(/*UhkConnection.LOG_LEVELS.TRANSFER*/);
|
|
uhkConnection.connect(function(error) {
|
|
if (error) {
|
|
console.error(error);
|
|
exitWithError();
|
|
}
|
|
});
|
|
break;
|
|
case UhkConnection.COMMANDS.REENUMERATE:
|
|
var enumerationModeArg = args.shift();
|
|
var enumerationModes = getTypistFriendlyObjectKeys(ENUMERATION_MODE_IDS);
|
|
if (!R.contains(enumerationModeArg, enumerationModes)) {
|
|
console.error('Usage: %s %s {%s}', programName, commandArg, enumerationModes.join(' | '));
|
|
console.error(enumerationModeArg === undefined
|
|
? 'No enumeration mode has been specified.'
|
|
: 'Enumeration mode "%s" is invalid.', enumerationModeArg);
|
|
exitWithError();
|
|
}
|
|
var enumerationMode = R.find(R.propEq('id', getTypistUnfriendlyObjectKey(enumerationModeArg)),
|
|
UhkConnection.ENUMERATION_MODES);
|
|
sendRequest(command, enumerationMode.enumerationId, function(error, data) {
|
|
console.log('Reenumerating the UHK in %s mode...', getTypistUnfriendlyObjectKey(enumerationMode.id));
|
|
uhkConnection.waitUntilDisconnect(function() {}, function() {
|
|
console.log('UHK disconnected.');
|
|
uhkConnection.connect(function() {});
|
|
});
|
|
}, false);
|
|
break;
|
|
case UhkConnection.COMMANDS.READ_EEPROM:
|
|
sendRequest(command, null, function(error, data) {
|
|
console.log(data);
|
|
});
|
|
break;
|
|
case UhkConnection.COMMANDS.WRITE_EEPROM:
|
|
var stringToBeSaved = args.shift();
|
|
if (!stringToBeSaved) {
|
|
console.error('A string has to be specified to be saved into the EEPROM.');
|
|
exitWithError();
|
|
}
|
|
sendRequest(command, stringToBeSaved, function(error, data) {});
|
|
break;
|
|
}
|
|
|
|
// Helper functions
|
|
|
|
function sendRequest(command, arg, callback, shouldReceiveResponse) {
|
|
if (uhkConnection) {
|
|
uhkConnection.sendRequest(command, arg, callback, shouldReceiveResponse);
|
|
} else {
|
|
uhkConnection = new UhkConnection(/*UhkConnection.LOG_LEVELS.TRANSFER*/);
|
|
uhkConnection.connect(function(error) {
|
|
if (error) {
|
|
console.error(error);
|
|
exitWithError();
|
|
}
|
|
|
|
uhkConnection.sendRequest(command, arg, callback, shouldReceiveResponse);
|
|
});
|
|
}
|
|
}
|
|
|
|
function getTypistFriendlyObjectKeys(object) {
|
|
return object.map(function(command) {
|
|
return command.toLowerCase().replace(/_/g, '-');
|
|
});
|
|
}
|
|
|
|
function getTypistUnfriendlyObjectKey(key) {
|
|
return key.toUpperCase().replace(/-/g, '_');
|
|
}
|
|
|
|
function exitWithError() {
|
|
process.exit(1);
|
|
}
|