Integrate Winkey using Web Serial into the general QSO area

这个提交包含在:
Peter Goodhall 2023-08-01 16:25:31 +01:00 提交者 GitHub
当前提交 fc687978f8
找不到此签名对应的密钥
GPG 密钥 ID: 4AEE18F83AFDEB23
共有 10 个文件被更改,包括 768 次插入1 次删除

查看文件

@ -21,7 +21,8 @@ $config['migration_enabled'] = TRUE;
| be upgraded / downgraded to.
|
*/
$config['migration_version'] = 131;
$config['migration_version'] = 132;
/*
|--------------------------------------------------------------------------

查看文件

@ -151,6 +151,72 @@ class QSO extends CI_Controller {
}
}
function winkeysettings() {
// Load model Winkey
$this->load->model('winkey');
// call settings from model winkey
$data['result'] = $this->winkey->settings($this->session->userdata('user_id'), $this->session->userdata('station_profile_id'));
if ($data['result'] == false) {
$this->load->view('qso/components/winkeysettings', $data);
} else {
$this->load->view('qso/components/winkeysettings_results', $data);
}
}
function cwmacrosave(){
// Get the data from the form
$function1_name = xss_clean($this->input->post('function1_name'));
$function1_macro = xss_clean($this->input->post('function1_macro'));
$function2_name = xss_clean($this->input->post('function2_name'));
$function2_macro = xss_clean($this->input->post('function2_macro'));
$function3_name = xss_clean($this->input->post('function3_name'));
$function3_macro = xss_clean($this->input->post('function3_macro'));
$function4_name = xss_clean($this->input->post('function4_name'));
$function4_macro = xss_clean($this->input->post('function4_macro'));
$function5_name = xss_clean($this->input->post('function5_name'));
$function5_macro = xss_clean($this->input->post('function5_macro'));
$data = [
'user_id' => $this->session->userdata('user_id'),
'station_location_id' => $this->session->userdata('station_profile_id'),
'function1_name' => $function1_name,
'function1_macro' => $function1_macro,
'function2_name' => $function2_name,
'function2_macro' => $function2_macro,
'function3_name' => $function3_name,
'function3_macro' => $function3_macro,
'function4_name' => $function4_name,
'function4_macro' => $function4_macro,
'function5_name' => $function5_name,
'function5_macro' => $function5_macro,
];
// Load model Winkey
$this->load->model('winkey');
// save the data
$this->winkey->save($data);
echo "Macros Saved, Press Close and lets get sending!";
}
function cwmacros_json() {
// Load model Winkey
$this->load->model('winkey');
header('Content-Type: application/json; charset=utf-8');
// Call settings_json from model winkey
echo $this->winkey->settings_json($this->session->userdata('user_id'), $this->session->userdata('station_profile_id'));
}
function edit_ajax() {
$this->load->model('logbook_model');

查看文件

@ -0,0 +1,116 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
* This migration creates a table called thirdparty_logins
* This table is used to store third party login details
*/
class Migration_create_cwmacros_table extends CI_Migration {
public function up()
{
if (!$this->db->table_exists('cwmacros')) {
$this->dbforge->add_field(array(
'id' => array(
'type' => 'BIGINT',
'constraint' => 20,
'unsigned' => TRUE,
'auto_increment' => TRUE,
'unique' => TRUE
),
'user_id' => array(
'type' => 'BIGINT',
'constraint' => 20,
'unsigned' => TRUE,
'auto_increment' => FALSE
),
'station_location_id' => array(
'type' => 'BIGINT',
'constraint' => 20,
'unsigned' => TRUE,
'auto_increment' => FALSE
),
'function1_name' => array(
'type' => 'VARCHAR',
'constraint' => '255',
'null' => TRUE
),
'function1_macro' => array(
'type' => 'VARCHAR',
'constraint' => '255',
'null' => TRUE
),
'function2_name' => array(
'type' => 'VARCHAR',
'constraint' => '255',
'null' => TRUE
),
'function2_macro' => array(
'type' => 'VARCHAR',
'constraint' => '255',
'null' => TRUE
),
'function3_name' => array(
'type' => 'VARCHAR',
'constraint' => '255',
'null' => TRUE
),
'function3_macro' => array(
'type' => 'VARCHAR',
'constraint' => '255',
'null' => TRUE
),
'function4_name' => array(
'type' => 'VARCHAR',
'constraint' => '255',
'null' => TRUE
),
'function4_macro' => array(
'type' => 'VARCHAR',
'constraint' => '255',
'null' => TRUE
),
'function5_name' => array(
'type' => 'VARCHAR',
'constraint' => '255',
'null' => TRUE
),
'function5_macro' => array(
'type' => 'VARCHAR',
'constraint' => '255',
'null' => TRUE
),
'modified' => array(
'type' => 'timestamp',
'null' => TRUE,
)
));
$this->dbforge->add_key('id', TRUE);
$this->dbforge->add_key('user_id', TRUE);
$this->dbforge->add_key('station_location_id', TRUE);
$this->dbforge->create_table('cwmacros');
}
}
public function down()
{
$this->dbforge->drop_table('cwmacros');
}
}

查看文件

@ -0,0 +1,49 @@
<?php
class Winkey extends CI_Model
{
public function settings($user_id, $station_location_id)
{
$this->db->where('user_id', $user_id);
$this->db->where('station_location_id', $station_location_id);
$query = $this->db->get('cwmacros');
if ($query->num_rows() > 0) {
return $query->row();
} else {
return false;
}
}
public function settings_json($user_id, $station_location_id)
{
$this->db->where('user_id', $user_id);
$this->db->where('station_location_id', $station_location_id);
$query = $this->db->get('cwmacros');
if ($query->num_rows() > 0) {
// return $query->row() as json
return json_encode($query->row());
} else {
// return json with status not found
return json_encode(array('status' => 'not found'));
}
}
public function save($data)
{
$this->db->where('user_id', $data['user_id']);
$this->db->where('station_location_id', $data['station_location_id']);
$query = $this->db->get('cwmacros');
if ($query->num_rows() > 0) {
$this->db->where('user_id', $data['user_id']);
$this->db->where('station_location_id', $data['station_location_id']);
$this->db->update('cwmacros', $data);
} else {
$this->db->insert('cwmacros', $data);
}
}
}
?>

查看文件

@ -7,6 +7,8 @@
var base_url = "<?php echo base_url(); ?>"; // Base URL
var site_url = "<?php echo site_url(); ?>"; // Site URL
var icon_dot_url = "<?php echo base_url();?>assets/images/dot.png";
// get the user_callsign from session
var my_call = "<?php echo $this->session->userdata('user_callsign'); ?>".toUpperCase();
</script>
<!-- General JS Files used across Cloudlog -->
@ -936,7 +938,9 @@ $(document).on('keypress',function(e) {
<?php } ?>
<?php if ($this->uri->segment(1) == "qso") { ?>
<script src="<?php echo base_url() ;?>assets/js/sections/qso.js"></script>
<script src="<?php echo base_url() ;?>assets/js/winkey.js"></script>
<?php
if ($this->optionslib->get_option('dxcache_url') != ''){ ?>
@ -953,6 +957,7 @@ $(document).on('keypress',function(e) {
});
});
</script>
<?php
}

查看文件

@ -0,0 +1,96 @@
<div id="modal-backdrop" class="modal-backdrop fade show" style="display:block;"></div>
<div id="modal" class="modal fade show" tabindex="-1" style="display:block;">
<form hx-post="/index.php/qso/cwmacrosave" hx-target=".modal-body">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Winkey Macros</h5>
</div>
<div class="modal-body">
<div class="form-group row">
<label for="function1_name" class="col-sm-5 col-form-label">Function 1 - Name</label>
<div class="col-sm-7">
<input name="function1_name" type="text" class="form-control" id="function1_name" maxlength="6">
</div>
</div>
<div class="form-group row">
<label for="function1_macro" class="col-sm-5 col-form-label">Function 1 - Macro</label>
<div class="col-sm-7">
<input name="function1_macro" type="text" class="form-control" id="function1_macro">
</div>
</div>
<hr>
<div class="form-group row">
<label for="function2_name" class="col-sm-5 col-form-label">Function 2 - Name</label>
<div class="col-sm-7">
<input name="function2_name" type="text" class="form-control" id="function2_name" maxlength="6">
</div>
</div>
<div class="form-group row">
<label for="function2_macro" class="col-sm-5 col-form-label">Function 2 - Macro</label>
<div class="col-sm-7">
<input name="function2_macro" type="text" class="form-control" id="function2_macro">
</div>
</div>
<hr>
<div class="form-group row">
<label for="function3_name" class="col-sm-5 col-form-label">Function 3 - Name</label>
<div class="col-sm-7">
<input name="function3_name" type="text" class="form-control" id="function3_name" maxlength="6">
</div>
</div>
<div class="form-group row">
<label for="function3_macro" class="col-sm-5 col-form-label">Function 3 - Macro</label>
<div class="col-sm-7">
<input name="function3_macro" type="text" class="form-control" id="function3_macro">
</div>
</div>
<hr>
<div class="form-group row">
<label for="function4_name" class="col-sm-5 col-form-label">Function 4 - Name</label>
<div class="col-sm-7">
<input name="function4_name" type="text" class="form-control" id="function4_name" maxlength="6">
</div>
</div>
<div class="form-group row">
<label for="function4_macro" class="col-sm-5 col-form-label">Function 4 - Macro</label>
<div class="col-sm-7">
<input name="function4_macro" type="text" class="form-control" id="function4_macro">
</div>
</div>
<hr>
<div class="form-group row">
<label for="function5_name" class="col-sm-5 col-form-label">Function 5 - Name</label>
<div class="col-sm-7">
<input name="function5_name" type="text" class="form-control" id="function5_name" maxlength="6">
</div>
</div>
<div class="form-group row">
<label for="function5_macro" class="col-sm-5 col-form-label">Function 5 - Macro</label>
<div class="col-sm-7">
<input name="function5_macro" type="text" class="form-control" id="function5_macro">
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Save</button>
<button type="button" class="btn btn-secondary" onclick="closeModal()">Close</button>
</div>
</div>
</div>
</form>
</div>

查看文件

@ -0,0 +1,96 @@
<div id="modal-backdrop" class="modal-backdrop fade show" style="display:block;"></div>
<div id="modal" class="modal fade show" tabindex="-1" style="display:block;">
<form hx-post="/index.php/qso/cwmacrosave" hx-target=".modal-body">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Winkey Macros</h5>
</div>
<div class="modal-body">
<div class="form-group row">
<label for="function1_name" class="col-sm-5 col-form-label">Function 1 - Name</label>
<div class="col-sm-7">
<input name="function1_name" type="text" class="form-control" id="function1_name" maxlength="6" value="<?php echo $result->function1_name; ?>">
</div>
</div>
<div class="form-group row">
<label for="function1_macro" class="col-sm-5 col-form-label">Function 1 - Macro</label>
<div class="col-sm-7">
<input name="function1_macro" type="text" class="form-control" id="function1_macro" value="<?php echo $result->function1_macro; ?>">
</div>
</div>
<hr>
<div class="form-group row">
<label for="function2_name" class="col-sm-5 col-form-label">Function 2 - Name</label>
<div class="col-sm-7">
<input name="function2_name" type="text" class="form-control" id="function2_name" maxlength="6" value="<?php echo $result->function2_name; ?>">
</div>
</div>
<div class="form-group row">
<label for="function2_macro" class="col-sm-5 col-form-label">Function 2 - Macro</label>
<div class="col-sm-7">
<input name="function2_macro" type="text" class="form-control" id="function2_macro" value="<?php echo $result->function2_macro; ?>">
</div>
</div>
<hr>
<div class="form-group row">
<label for="function3_name" class="col-sm-5 col-form-label">Function 3 - Name</label>
<div class="col-sm-7">
<input name="function3_name" type="text" class="form-control" id="function3_name" maxlength="6" value="<?php echo $result->function3_name; ?>">
</div>
</div>
<div class="form-group row">
<label for="function3_macro" class="col-sm-5 col-form-label">Function 3 - Macro</label>
<div class="col-sm-7">
<input name="function3_macro" type="text" class="form-control" id="function3_macro" value="<?php echo $result->function3_macro; ?>">
</div>
</div>
<hr>
<div class="form-group row">
<label for="function4_name" class="col-sm-5 col-form-label">Function 4 - Name</label>
<div class="col-sm-7">
<input name="function4_name" type="text" class="form-control" id="function4_name" maxlength="6" value="<?php echo $result->function4_name; ?>">
</div>
</div>
<div class="form-group row">
<label for="function4_macro" class="col-sm-5 col-form-label">Function 4 - Macro</label>
<div class="col-sm-7">
<input name="function4_macro" type="text" class="form-control" id="function4_macro" value="<?php echo $result->function4_macro; ?>">
</div>
</div>
<hr>
<div class="form-group row">
<label for="function5_name" class="col-sm-5 col-form-label">Function 5 - Name</label>
<div class="col-sm-7">
<input name="function5_name" type="text" class="form-control" id="function5_name" maxlength="6" value="<?php echo $result->function5_name; ?>">
</div>
</div>
<div class="form-group row">
<label for="function5_macro" class="col-sm-5 col-form-label">Function 5 - Macro</label>
<div class="col-sm-7">
<input name="function5_macro" type="text" class="form-control" id="function5_macro" value="<?php echo $result->function5_macro; ?>">
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Save</button>
<button type="button" class="btn btn-secondary" onclick="closeModal()">Close</button>
</div>
</div>
</div>
</form>
</div>

查看文件

@ -518,6 +518,36 @@
<div id="qsomap" style="width: 100%; height: 200px;"></div>
</div>
<div id="winkey" class="card winkey-settings">
<div class="card-header">
<h4 style="font-size: 16px; font-weight: bold;" class="card-title">Winkey
<button id="connectButton" class="btn btn-primary">Connect</button>
<button type="button" class="btn btn-light"
hx-get="/index.php/qso/winkeysettings"
hx-target="#modals-here"
hx-trigger="click"
class="btn btn-primary"
_="on htmx:afterOnLoad wait 10ms then add .show to #modal then add .show to #modal-backdrop"><i class="fas fa-cog"></i> Settings</button>
</h4>
</div>
<div class="card-body">
<div id="modals-here"></div>
<button id="morsekey_func1" onclick="morsekey_func1()" class="btn btn-warning">F1</button>
<button id="morsekey_func2" onclick="morsekey_func2()" class="btn btn-warning">F2</button>
<button id="morsekey_func3" onclick="morsekey_func3()" class="btn btn-warning">F3</button>
<button id="morsekey_func4" onclick="morsekey_func4()" class="btn btn-warning">F4</button>
<button id="morsekey_func5" onclick="morsekey_func5()" class="btn btn-warning">F5</button>
<br><br>
<input id="sendText" type="text"><input id="sendButton" type="button" value="Send" class="btn btn-success">
<span id="statusBar"></span><br>
</div>
</div>
<div class="card callsign-suggest">
<div class="card-header"><h4 style="font-size: 16px; font-weight: bold;" class="card-title"><?php echo lang('qso_title_suggestions'); ?></h4></div>

查看文件

@ -854,3 +854,17 @@ function resetDefaultQSOFields() {
$('#callsign-image-content').text("");
$('.dxccsummary').remove();
}
function closeModal() {
var container = document.getElementById("modals-here")
var backdrop = document.getElementById("modal-backdrop")
var modal = document.getElementById("modal")
modal.classList.remove("show")
backdrop.classList.remove("show")
setTimeout(function() {
container.removeChild(backdrop)
container.removeChild(modal)
}, 200)
}

294
assets/js/winkey.js 普通文件
查看文件

@ -0,0 +1,294 @@
// Lets see if CW is selected
const ModeSelected = document.getElementById('mode');
if (location.protocol == 'http:') {
// Do something if the page is being served over SSL
$('#winkey').hide(); // Hide the CW buttons
}
if (ModeSelected.value == 'CW') {
// Show the CW buttons
$('#winkey').show();
} else {
// Hide the CW buttons
$('#winkey').hide();
}
ModeSelected.addEventListener('change', (event) => {
if (event.target.value == 'CW') {
// Show the CW buttons
$('#winkey').show();
} else {
// Hide the CW buttons
$('#winkey').hide();
}
});
let function1Name, function1Macro, function2Name, function2Macro, function3Name, function3Macro, function4Name, function4Macro, function5Name, function5Macro;
getMacros();
document.addEventListener('keydown', function(event) {
if (event.key === 'F1') {
event.preventDefault();
morsekey_func1();
}
if (event.key === 'F2') {
event.preventDefault();
morsekey_func2();
}
if (event.key === 'F3') {
event.preventDefault();
morsekey_func3();
}
if (event.key === 'F4') {
event.preventDefault();
morsekey_func4();
}
if (event.key === 'F5') {
event.preventDefault();
morsekey_func5();
}
});
let sendText = document.getElementById("sendText");
let sendButton = document.getElementById("sendButton");
let receiveText = document.getElementById("receiveText");
let connectButton = document.getElementById("connectButton");
let statusBar = document.getElementById("statusBar");
//Couple the elements to the Events
connectButton.addEventListener("click", clickConnect)
sendButton.addEventListener("click", clickSend)
helpButton.addEventListener("click", clickHelp)
statusButton.addEventListener("click", clickStatus)
//When the connectButton is pressed
async function clickConnect() {
if (port) {
//if already connected, disconnect
disconnect();
} else {
//otherwise connect
await connect();
}
}
//Define outputstream, inputstream and port so they can be used throughout the sketch
var outputStream, inputStream, port;
navigator.serial.addEventListener('connect', e => {
statusBar.innerText = `Connected to ${e.port}`;
connectButton.innerText = "Disconnect"
});
navigator.serial.addEventListener('disconnect', e => {
statusBar.innerText = `Disconnected`;
connectButton.innerText = "Connect"
});
//Connect to the serial
async function connect() {
//Optional filter to only see relevant boards
const filter = {
usbVendorId: 0x2341 // Arduino SA
};
//Try to connect to the Serial port
try {
port = await navigator.serial.requestPort(/*{ filters: [filter] }*/);
// Continue connecting to |port|.
// - Wait for the port to open.
await port.open({ baudRate: 1200 });
statusBar.innerText = "Connected";
connectButton.innerText = "Disconnect"
let decoder = new TextDecoderStream();
inputDone = port.readable.pipeTo(decoder.writable);
inputStream = decoder.readable;
const encoder = new TextEncoderStream();
outputDone = encoder.readable.pipeTo(port.writable);
outputStream = encoder.writable;
reader = inputStream.getReader();
readLoop();
} catch (e) {
//If the pipeTo error appears; clarify the problem by giving suggestions.
if (e == "TypeError: Cannot read property 'pipeTo' of undefined") {
e += "\n Use Google Chrome and enable-experimental-web-platform-features"
}
connectButton.innerText = "Connect"
statusBar.innerText = e;
}
}
//Write to the Serial port
async function writeToStream(line) {
var enc = new TextEncoder(); // always utf-8
const writer = outputStream.getWriter();
writer.write(line);
writer.releaseLock();
}
//Disconnect from the Serial port
async function disconnect() {
if (reader) {
await reader.cancel();
await inputDone.catch(() => { });
reader = null;
inputDone = null;
}
if (outputStream) {
await outputStream.getWriter().close();
await outputDone;
outputStream = null;
outputDone = null;
}
statusBar.innerText = "Disconnected";
connectButton.innerText = "Connect"
//Close the port.
await port.close();
port = null;
}
//When the send button is pressed
function clickSend() {
writeToStream(sendText.value);
writeToStream("\r");
//and clear the input field, so it's clear it has been sent
sendText.value = "";
}
function morsekey_func1() {
console.log("F1: " + UpdateMacros(function1Macro));
writeToStream(UpdateMacros(function1Macro));
//and clear the input field, so it's clear it has been sent
sendText.value = "";
}
function morsekey_func2() {
console.log("F2: " + UpdateMacros(function2Macro));
writeToStream(UpdateMacros(function2Macro));
//and clear the input field, so it's clear it has been sent
sendText.value = "";
}
function morsekey_func3() {
console.log("F3: " + UpdateMacros(function3Macro));
writeToStream(UpdateMacros(function3Macro));
//and clear the input field, so it's clear it has been sent
sendText.value = "";
}
function morsekey_func4() {
console.log("F4: " + UpdateMacros(function4Macro));
writeToStream(UpdateMacros(function4Macro));
//and clear the input field, so it's clear it has been sent
sendText.value = "";
}
function morsekey_func5() {
console.log("F5: " + UpdateMacros(function5Macro));
writeToStream(UpdateMacros(function5Macro));
//and clear the input field, so it's clear it has been sent
sendText.value = "";
}
//Read the incoming data
async function readLoop() {
while (true) {
const { value, done } = await reader.read();
if (done === true){
break;
}
console.log(value);
//When recieved something add it to the big textarea
receiveText.value += value;
//Scroll to the bottom of the text field
receiveText.scrollTop = receiveText.scrollHeight;
}
}
function closeModal() {
var container = document.getElementById("modals-here")
var backdrop = document.getElementById("modal-backdrop")
var modal = document.getElementById("modal")
modal.classList.remove("show")
backdrop.classList.remove("show")
getMacros();
setTimeout(function() {
container.removeChild(backdrop)
container.removeChild(modal)
}, 200)
}
function UpdateMacros(macrotext) {
// Get the values from the form set to uppercase
let CALL = document.getElementById("callsign").value.toUpperCase();
let RSTS = document.getElementById("rst_sent").value;
let newString;
newString = macrotext.replace(/\[MYCALL\]/g, my_call);
newString = newString.replace(/\[CALL\]/g, CALL);
newString = newString.replace(/\[RSTS\]/g, RSTS);
console.log(newString);
return newString;
}
// Call url and store the returned json data as variables
function getMacros() {
fetch(base_url + 'index.php/qso/cwmacros_json')
.then(response => response.json())
.then(data => {
function1Name = data.function1_name;
function1Macro = data.function1_macro;
function2Name = data.function2_name;
function2Macro = data.function2_macro;
function3Name = data.function3_name;
function3Macro = data.function3_macro;
function4Name = data.function4_name;
function4Macro = data.function4_macro;
function5Name = data.function5_name;
function5Macro = data.function5_macro;
const morsekey_func1_Button = document.getElementById('morsekey_func1');
morsekey_func1_Button.textContent = 'F1 (' + function1Name + ')';
const morsekey_func2_Button = document.getElementById('morsekey_func2');
morsekey_func2_Button.textContent = 'F2 (' + function2Name + ')';
const morsekey_func3_Button = document.getElementById('morsekey_func3');
morsekey_func3_Button.textContent = 'F3 (' + function3Name + ')';
const morsekey_func4_Button = document.getElementById('morsekey_func4');
morsekey_func4_Button.textContent = 'F4 (' + function4Name + ')';
const morsekey_func5_Button = document.getElementById('morsekey_func5');
morsekey_func5_Button.textContent = 'F5 (' + function5Name + ')';
});
}