From fda30f424c8e91df32d591eafea0eaca8e864ae9 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Mon, 15 May 2023 14:28:14 +0100 Subject: [PATCH 01/17] added winkey js --- application/views/interface_assets/footer.php | 2 +- application/views/qso/index.php | 147 ++++++++++++++++++ assets/js/winkey.js | 131 ++++++++++++++++ 3 files changed, 279 insertions(+), 1 deletion(-) create mode 100644 assets/js/winkey.js diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 202b8787..a454ad5e 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -908,7 +908,7 @@ $(document).on('keypress',function(e) { uri->segment(1) == "qso") { ?> - + Connect
+ +
+ +
@@ -516,6 +655,14 @@
+
+

Winkey

+ +
+ +
+
+

diff --git a/assets/js/winkey.js b/assets/js/winkey.js new file mode 100644 index 00000000..e5949bed --- /dev/null +++ b/assets/js/winkey.js @@ -0,0 +1,131 @@ +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(enc); + 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 = ""; + +} + +//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; + } +} \ No newline at end of file From 1f944571714897cf2dfa423e4a2a3300878aeb1e Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Mon, 15 May 2023 14:35:09 +0100 Subject: [PATCH 02/17] Update index.php --- application/views/qso/index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/views/qso/index.php b/application/views/qso/index.php index 4bc30e27..010185a1 100755 --- a/application/views/qso/index.php +++ b/application/views/qso/index.php @@ -42,8 +42,8 @@ //Connect to the serial async function connect() { - //Optional filter to only see relevant boards - + //Optional filter to only see relevant board + //Try to connect to the Serial port try { From 4478c8fb7803d5d4bd53cbb99d294e7a8c73d7db Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Mon, 15 May 2023 14:38:33 +0100 Subject: [PATCH 03/17] moved to js file --- application/views/interface_assets/footer.php | 2 +- application/views/qso/index.php | 143 +----------------- 2 files changed, 4 insertions(+), 141 deletions(-) diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index a454ad5e..6628a27b 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -909,7 +909,7 @@ $(document).on('keypress',function(e) { uri->segment(1) == "qso") { ?> - + load->model('stations'); diff --git a/application/views/qso/index.php b/application/views/qso/index.php index 010185a1..961039fa 100755 --- a/application/views/qso/index.php +++ b/application/views/qso/index.php @@ -1,142 +1,3 @@ -
- -
- -
@@ -659,7 +520,9 @@

Winkey

- +
+ +
From ac5bb52cd45a2535fd33815cac65aba5233c3221 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Mon, 15 May 2023 14:42:53 +0100 Subject: [PATCH 04/17] test button --- application/views/qso/index.php | 1 + assets/js/winkey.js | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/application/views/qso/index.php b/application/views/qso/index.php index 961039fa..c5b75df8 100755 --- a/application/views/qso/index.php +++ b/application/views/qso/index.php @@ -522,6 +522,7 @@

+
diff --git a/assets/js/winkey.js b/assets/js/winkey.js index e5949bed..1e289dc8 100644 --- a/assets/js/winkey.js +++ b/assets/js/winkey.js @@ -9,6 +9,7 @@ connectButton.addEventListener("click", clickConnect) sendButton.addEventListener("click", clickSend) helpButton.addEventListener("click", clickHelp) statusButton.addEventListener("click", clickStatus) +cwfunc1Button.addEventListener("click", morsekey_func1) //When the connectButton is pressed async function clickConnect() { @@ -114,6 +115,15 @@ function clickSend() { } +function morsekey_func1() { + writeToStream("CQ CQ 2M0SQL"); + + //and clear the input field, so it's clear it has been sent + sendText.value = ""; + +} + + //Read the incoming data async function readLoop() { while (true) { From 6f93ac6db01c94e37010065679a80a55dfba4d4d Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Mon, 15 May 2023 14:44:07 +0100 Subject: [PATCH 05/17] Update winkey.js --- assets/js/winkey.js | 1 + 1 file changed, 1 insertion(+) diff --git a/assets/js/winkey.js b/assets/js/winkey.js index 1e289dc8..f23d9cf5 100644 --- a/assets/js/winkey.js +++ b/assets/js/winkey.js @@ -116,6 +116,7 @@ function clickSend() { } function morsekey_func1() { + console.log("send CQ"); writeToStream("CQ CQ 2M0SQL"); //and clear the input field, so it's clear it has been sent From af6ba5f547819008df84e77ecb448366fc76cca9 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Mon, 15 May 2023 14:46:14 +0100 Subject: [PATCH 06/17] onclick --- application/views/qso/index.php | 2 +- assets/js/winkey.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/application/views/qso/index.php b/application/views/qso/index.php index c5b75df8..0844840b 100755 --- a/application/views/qso/index.php +++ b/application/views/qso/index.php @@ -522,7 +522,7 @@

- +
diff --git a/assets/js/winkey.js b/assets/js/winkey.js index f23d9cf5..dcdc6026 100644 --- a/assets/js/winkey.js +++ b/assets/js/winkey.js @@ -9,7 +9,6 @@ connectButton.addEventListener("click", clickConnect) sendButton.addEventListener("click", clickSend) helpButton.addEventListener("click", clickHelp) statusButton.addEventListener("click", clickStatus) -cwfunc1Button.addEventListener("click", morsekey_func1) //When the connectButton is pressed async function clickConnect() { From 4ec722236e676c49f2755872c05e8bd8938c1a64 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Mon, 15 May 2023 15:35:11 +0100 Subject: [PATCH 07/17] Cleaned up the UI added a settings popup modal --- application/controllers/Qso.php | 4 +++ .../views/qso/components/winkeysettings.php | 16 ++++++++++ application/views/qso/index.php | 30 +++++++++++++++---- assets/js/sections/qso.js | 14 +++++++++ 4 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 application/views/qso/components/winkeysettings.php diff --git a/application/controllers/Qso.php b/application/controllers/Qso.php index 3189df04..05916d60 100755 --- a/application/controllers/Qso.php +++ b/application/controllers/Qso.php @@ -151,6 +151,10 @@ class QSO extends CI_Controller { } } + function winkeysettings() { + $this->load->view('qso/components/winkeysettings'); + } + function edit_ajax() { $this->load->model('logbook_model'); diff --git a/application/views/qso/components/winkeysettings.php b/application/views/qso/components/winkeysettings.php new file mode 100644 index 00000000..ae80a9f1 --- /dev/null +++ b/application/views/qso/components/winkeysettings.php @@ -0,0 +1,16 @@ + + \ No newline at end of file diff --git a/application/views/qso/index.php b/application/views/qso/index.php index 0844840b..60969b10 100755 --- a/application/views/qso/index.php +++ b/application/views/qso/index.php @@ -517,13 +517,33 @@
-

Winkey

+
+

Winkey + + + + +

+
-
- - -
+
+ + + + + + +

+ + +
+
diff --git a/assets/js/sections/qso.js b/assets/js/sections/qso.js index df22c366..50d4d3ab 100644 --- a/assets/js/sections/qso.js +++ b/assets/js/sections/qso.js @@ -798,3 +798,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) +} \ No newline at end of file From 8dcd74c9784d2698f0e55b8b5fa3bc7767f3f50e Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Mon, 15 May 2023 16:52:59 +0100 Subject: [PATCH 08/17] stop making life hard --- assets/js/winkey.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/winkey.js b/assets/js/winkey.js index dcdc6026..b483fbe0 100644 --- a/assets/js/winkey.js +++ b/assets/js/winkey.js @@ -78,7 +78,7 @@ async function writeToStream(line) { var enc = new TextEncoder(); // always utf-8 const writer = outputStream.getWriter(); - writer.write(enc); + writer.write(line); writer.releaseLock(); } From 96a747e15c2c05b6ac2a09d3b05f3a65f7ba17f6 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Wed, 17 May 2023 21:19:18 +0100 Subject: [PATCH 09/17] Change to interface for CW settings --- application/controllers/Qso.php | 4 + .../views/qso/components/winkeysettings.php | 85 ++++++++++++++++++- application/views/qso/index.php | 1 - 3 files changed, 86 insertions(+), 4 deletions(-) diff --git a/application/controllers/Qso.php b/application/controllers/Qso.php index 05916d60..3e8a0839 100755 --- a/application/controllers/Qso.php +++ b/application/controllers/Qso.php @@ -155,6 +155,10 @@ class QSO extends CI_Controller { $this->load->view('qso/components/winkeysettings'); } + function cwmacrosave(){ + echo "lets save!"; + } + function edit_ajax() { $this->load->model('logbook_model'); diff --git a/application/views/qso/components/winkeysettings.php b/application/views/qso/components/winkeysettings.php index ae80a9f1..f0e7ccff 100644 --- a/application/views/qso/components/winkeysettings.php +++ b/application/views/qso/components/winkeysettings.php @@ -1,16 +1,95 @@ \ No newline at end of file + + diff --git a/application/views/qso/index.php b/application/views/qso/index.php index 60969b10..e61c89c6 100755 --- a/application/views/qso/index.php +++ b/application/views/qso/index.php @@ -538,7 +538,6 @@ -

From 65b780e2f37893f251262e3d964f1d8bd490788b Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Fri, 2 Jun 2023 15:43:53 +0100 Subject: [PATCH 10/17] [CW Macros] Database Schema Created --- application/config/migration.php | 2 +- .../migrations/122_create_cwmacros_table.php | 116 ++++++++++++++++++ assets/js/winkey.js | 14 +++ 3 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 application/migrations/122_create_cwmacros_table.php diff --git a/application/config/migration.php b/application/config/migration.php index 36e3840a..372fbaf2 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -21,7 +21,7 @@ $config['migration_enabled'] = TRUE; | be upgraded / downgraded to. | */ -$config['migration_version'] = 121; +$config['migration_version'] = 122; /* |-------------------------------------------------------------------------- diff --git a/application/migrations/122_create_cwmacros_table.php b/application/migrations/122_create_cwmacros_table.php new file mode 100644 index 00000000..42940d36 --- /dev/null +++ b/application/migrations/122_create_cwmacros_table.php @@ -0,0 +1,116 @@ +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'); + } +} \ No newline at end of file diff --git a/assets/js/winkey.js b/assets/js/winkey.js index b483fbe0..77caa2b7 100644 --- a/assets/js/winkey.js +++ b/assets/js/winkey.js @@ -138,4 +138,18 @@ async function readLoop() { //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") + + setTimeout(function() { + container.removeChild(backdrop) + container.removeChild(modal) + }, 200) } \ No newline at end of file From 43bacdc62a6a7953e73ba78f5491b1c48a299237 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Mon, 31 Jul 2023 15:52:32 +0100 Subject: [PATCH 11/17] Save and Update Macros from the Database --- application/controllers/Qso.php | 52 +++++++++- application/models/Winkey.php | 34 +++++++ .../views/qso/components/winkeysettings.php | 21 ++-- .../qso/components/winkeysettings_results.php | 96 +++++++++++++++++++ 4 files changed, 191 insertions(+), 12 deletions(-) create mode 100644 application/models/Winkey.php create mode 100644 application/views/qso/components/winkeysettings_results.php diff --git a/application/controllers/Qso.php b/application/controllers/Qso.php index 3e8a0839..b633c4be 100755 --- a/application/controllers/Qso.php +++ b/application/controllers/Qso.php @@ -152,11 +152,59 @@ class QSO extends CI_Controller { } function winkeysettings() { - $this->load->view('qso/components/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(){ - echo "lets save!"; + // 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 edit_ajax() { diff --git a/application/models/Winkey.php b/application/models/Winkey.php new file mode 100644 index 00000000..94c96009 --- /dev/null +++ b/application/models/Winkey.php @@ -0,0 +1,34 @@ +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 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); + } + } +} + +?> \ No newline at end of file diff --git a/application/views/qso/components/winkeysettings.php b/application/views/qso/components/winkeysettings.php index f0e7ccff..c65c402a 100644 --- a/application/views/qso/components/winkeysettings.php +++ b/application/views/qso/components/winkeysettings.php @@ -6,18 +6,19 @@ + diff --git a/application/views/qso/components/winkeysettings_results.php b/application/views/qso/components/winkeysettings_results.php new file mode 100644 index 00000000..cd6031c9 --- /dev/null +++ b/application/views/qso/components/winkeysettings_results.php @@ -0,0 +1,96 @@ + + From 9ddcb70588f4c3074659f3baade7147c947129d2 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Tue, 1 Aug 2023 11:40:32 +0100 Subject: [PATCH 12/17] Return macros as json --- application/controllers/Qso.php | 10 ++++++++++ application/models/Winkey.php | 17 ++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/application/controllers/Qso.php b/application/controllers/Qso.php index b633c4be..c0f49820 100755 --- a/application/controllers/Qso.php +++ b/application/controllers/Qso.php @@ -207,6 +207,16 @@ class QSO extends CI_Controller { 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'); diff --git a/application/models/Winkey.php b/application/models/Winkey.php index 94c96009..43938fd4 100644 --- a/application/models/Winkey.php +++ b/application/models/Winkey.php @@ -7,7 +7,7 @@ class Winkey extends CI_Model $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 { @@ -15,6 +15,21 @@ class Winkey extends CI_Model } } + 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']); From ba89628b8c9d41594d5e23810fa7871704a28f33 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Tue, 1 Aug 2023 14:07:11 +0100 Subject: [PATCH 13/17] Load the macros into the buttons --- application/views/qso/index.php | 10 ++--- assets/js/winkey.js | 75 +++++++++++++++++++++++++++++++-- 2 files changed, 76 insertions(+), 9 deletions(-) diff --git a/application/views/qso/index.php b/application/views/qso/index.php index e61c89c6..506627c0 100755 --- a/application/views/qso/index.php +++ b/application/views/qso/index.php @@ -533,11 +533,11 @@
- - - - - + + + + +

diff --git a/assets/js/winkey.js b/assets/js/winkey.js index 77caa2b7..085230ef 100644 --- a/assets/js/winkey.js +++ b/assets/js/winkey.js @@ -1,3 +1,7 @@ +let function1Name, function1Macro, function2Name, function2Macro, function3Name, function3Macro, function4Name, function4Macro, function5Name, function5Macro; + +getMacros(); + let sendText = document.getElementById("sendText"); let sendButton = document.getElementById("sendButton"); let receiveText = document.getElementById("receiveText"); @@ -115,14 +119,41 @@ function clickSend() { } function morsekey_func1() { - console.log("send CQ"); - writeToStream("CQ CQ 2M0SQL"); - + console.log("F1: " + function1Macro); + writeToStream(function1Macro); //and clear the input field, so it's clear it has been sent sendText.value = ""; - } +function morsekey_func2() { + console.log("F2: " + function2Macro); + writeToStream(function2Macro); + //and clear the input field, so it's clear it has been sent + sendText.value = ""; +} + +function morsekey_func3() { + console.log("F3: " + function3Macro); + writeToStream(function3Macro); + //and clear the input field, so it's clear it has been sent + sendText.value = ""; +} + +function morsekey_func4() { + console.log("F4: " + function4Macro); + writeToStream(function4Macro); + //and clear the input field, so it's clear it has been sent + sendText.value = ""; +} + +function morsekey_func5() { + console.log("F5: " + function5Macro); + writeToStream(function5Macro); + //and clear the input field, so it's clear it has been sent + sendText.value = ""; +} + + //Read the incoming data async function readLoop() { @@ -148,8 +179,44 @@ function closeModal() { modal.classList.remove("show") backdrop.classList.remove("show") + getMacros(); + setTimeout(function() { container.removeChild(backdrop) container.removeChild(modal) }, 200) +} + +// 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; + // Do something with the variables + + 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 + ')'; + }); } \ No newline at end of file From b13f2b032c2ad81cd165e0cfb993b3a2117c6a71 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Tue, 1 Aug 2023 14:49:43 +0100 Subject: [PATCH 14/17] Implement macro shortcuts --- application/views/interface_assets/footer.php | 2 + assets/js/winkey.js | 84 +++++++++++-------- 2 files changed, 51 insertions(+), 35 deletions(-) diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 6628a27b..6855a8e4 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -7,6 +7,8 @@ var base_url = ""; // Base URL var site_url = ""; // Site URL var icon_dot_url = "assets/images/dot.png"; + // get the user_callsign from session + var my_call = "session->userdata('user_callsign'); ?>".toUpperCase(); diff --git a/assets/js/winkey.js b/assets/js/winkey.js index 085230ef..7d3d6126 100644 --- a/assets/js/winkey.js +++ b/assets/js/winkey.js @@ -2,6 +2,7 @@ let function1Name, function1Macro, function2Name, function2Macro, function3Name, getMacros(); + let sendText = document.getElementById("sendText"); let sendButton = document.getElementById("sendButton"); let receiveText = document.getElementById("receiveText"); @@ -119,36 +120,36 @@ function clickSend() { } function morsekey_func1() { - console.log("F1: " + function1Macro); - writeToStream(function1Macro); + 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: " + function2Macro); - writeToStream(function2Macro); + 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: " + function3Macro); - writeToStream(function3Macro); + 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: " + function4Macro); - writeToStream(function4Macro); + 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: " + function5Macro); - writeToStream(function5Macro); + console.log("F5: " + UpdateMacros(function5Macro)); + writeToStream(UpdateMacros(function5Macro)); //and clear the input field, so it's clear it has been sent sendText.value = ""; } @@ -187,36 +188,49 @@ function closeModal() { }, 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; - // Do something with the variables + .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_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_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_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 + ')'; - }); + const morsekey_func5_Button = document.getElementById('morsekey_func5'); + morsekey_func5_Button.textContent = 'F5 (' + function5Name + ')'; + }); } \ No newline at end of file From 3e43e613c2cbb44710b0054c7c1a90bcd294254c Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Tue, 1 Aug 2023 16:05:30 +0100 Subject: [PATCH 15/17] Macros now work using the F keys --- assets/js/winkey.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/assets/js/winkey.js b/assets/js/winkey.js index 7d3d6126..a91e0489 100644 --- a/assets/js/winkey.js +++ b/assets/js/winkey.js @@ -2,6 +2,33 @@ let function1Name, function1Macro, function2Name, function2Macro, function3Name, 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"); From 59689f80cca22597b05bf46681b4b04887df7ac0 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Tue, 1 Aug 2023 16:18:56 +0100 Subject: [PATCH 16/17] Only show CW functions if using SSL and only when mode is CW --- application/views/qso/index.php | 2 +- assets/js/winkey.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/application/views/qso/index.php b/application/views/qso/index.php index 506627c0..585fe0c8 100755 --- a/application/views/qso/index.php +++ b/application/views/qso/index.php @@ -516,7 +516,7 @@
-
+

Winkey diff --git a/assets/js/winkey.js b/assets/js/winkey.js index a91e0489..daa04398 100644 --- a/assets/js/winkey.js +++ b/assets/js/winkey.js @@ -1,3 +1,34 @@ +// 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(); From c5cf2b27f5a25e5082ce3ae2116e87ff97add9dd Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Tue, 1 Aug 2023 16:22:03 +0100 Subject: [PATCH 17/17] Getting ready for merge --- application/config/migration.php | 2 +- ..._create_cwmacros_table.php => 132_create_cwmacros_table.php} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename application/migrations/{122_create_cwmacros_table.php => 132_create_cwmacros_table.php} (100%) diff --git a/application/config/migration.php b/application/config/migration.php index 372fbaf2..63cb55ec 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -21,7 +21,7 @@ $config['migration_enabled'] = TRUE; | be upgraded / downgraded to. | */ -$config['migration_version'] = 122; +$config['migration_version'] = 132; /* |-------------------------------------------------------------------------- diff --git a/application/migrations/122_create_cwmacros_table.php b/application/migrations/132_create_cwmacros_table.php similarity index 100% rename from application/migrations/122_create_cwmacros_table.php rename to application/migrations/132_create_cwmacros_table.php