diff --git a/application/controllers/Qso.php b/application/controllers/Qso.php
index a5277d0e6..e0e7ca8b8 100644
--- a/application/controllers/Qso.php
+++ b/application/controllers/Qso.php
@@ -220,10 +220,8 @@ class QSO extends CI_Controller {
->get_options('cwmacros', ['option_name' => "macro{$i}"])
->row();
- // Decode JSON stored in option_value
$decoded = json_decode($row->option_value ?? '');
- // Make sure it's an object (in case it's null)
$name = isset($decoded->name) ? $decoded->name : '';
$macro = isset($decoded->macro) ? $decoded->macro : '';
@@ -233,9 +231,28 @@ class QSO extends CI_Controller {
];
}
+ // Check if all are empty
+ $allEmpty = true;
+ foreach ($cwmacros as $macro) {
+ if (!empty($macro['name']) || !empty($macro['macro'])) {
+ $allEmpty = false;
+ break;
+ }
+ }
+
+ // Apply defaults to first 5 if all are empty
+ if ($allEmpty) {
+ $cwmacros['macro1'] = ['name' => 'CQ', 'macro' => 'CQ CQ CQ DE [MYCALL] [MYCALL] K'];
+ $cwmacros['macro2'] = ['name' => 'REPT', 'macro' => '[CALL] DE [MYCALL] [RSTS] [RSTS] K'];
+ $cwmacros['macro3'] = ['name' => 'TU', 'macro' => '[CALL] TU 73 DE [MYCALL] K'];
+ $cwmacros['macro4'] = ['name' => 'QRZ', 'macro' => 'QRZ DE [MYCALL] K'];
+ $cwmacros['macro5'] = ['name' => 'TEST', 'macro' => 'TEST DE [MYCALL] K'];
+ }
+
$this->load->view('qso/components/winkeysettings', $cwmacros);
}
+
function cwmacrosave(){
$this->load->model('user_options_model');
for ($i = 1; $i <= 10; $i++) {
@@ -260,7 +277,7 @@ class QSO extends CI_Controller {
->row();
// Decode JSON stored in option_value
- $decoded = json_decode($row->option_value);
+ $decoded = json_decode($row->option_value ?? '');
// Make sure it's an object (in case it's null)
$name = isset($decoded->name) ? $decoded->name : '';
@@ -630,7 +647,9 @@ class QSO extends CI_Controller {
$this->load->model('stations');
$this->load->library('qra');
$stationProfile = $this->input->post('stationProfile', TRUE);
- $data = array('station_power' => $this->stations->get_station_power($stationProfile));
+ $result = $this->stations->get_station_power($stationProfile);
+ $data['station_power'] = $result['station_power'];
+ $data['station_callsign'] = $result['station_callsign'];
[$data['lat'], $data['lng']] = $this->qra->qra2latlong($this->stations->gridsquare_from_station($stationProfile));
header('Content-Type: application/json');
diff --git a/application/models/Stations.php b/application/models/Stations.php
index 5e22bb106..bc7bf9f19 100644
--- a/application/models/Stations.php
+++ b/application/models/Stations.php
@@ -578,15 +578,16 @@ class Stations extends CI_Model {
}
public function get_station_power($id) {
- $this->db->select('station_power');
+ $this->db->select('station_power, station_callsign');
$this->db->where('user_id', $this->session->userdata('user_id'));
$this->db->where('station_id', $id);
$query = $this->db->get('station_profile');
if($query->num_rows() >= 1) {
- foreach ($query->result() as $row)
- {
- return $row->station_power;
- }
+ $row = $query->row(); // only one result expected
+ return [
+ 'station_power' => $row->station_power,
+ 'station_callsign' => $row->station_callsign
+ ];
} else {
return null;
}
diff --git a/application/views/qso/index.php b/application/views/qso/index.php
index 0fb78d697..53b9562b0 100644
--- a/application/views/qso/index.php
+++ b/application/views/qso/index.php
@@ -341,7 +341,7 @@ switch ($date_format) {
$power = '';
foreach ($stations->result() as $stationrow) {
?>
-
+
@@ -832,3 +832,6 @@ switch ($date_format) {
+
diff --git a/assets/js/winkey.js b/assets/js/winkey.js
index 7867e4421..82068be87 100644
--- a/assets/js/winkey.js
+++ b/assets/js/winkey.js
@@ -288,8 +288,7 @@ async function disconnect() {
//When the send button is pressed
function clickSend() {
- text2send = sendText.value.replaceAll('Ø', '0');
- writeToStream(text2send).then(function() {
+ writeToStream(sendText.value.replaceAll('Ø', '0')).then(function() {
// writeToStream("\r");
//and clear the input field, so it's clear it has been sent
$('#sendText').val('');
@@ -369,10 +368,12 @@ function UpdateMacros(macrotext) {
// Get the values from the form set to uppercase
let CALL = document.getElementById("callsign").value.toUpperCase();
+ CALL = CALL.replaceAll('Ø', '0');
let RSTS = document.getElementById("rst_sent").value;
let newString;
- newString = macrotext.replace(/\[MYCALL\]/g, my_call);
+ my_call = my_call.replaceAll('Ø', '0');
+ newString = macrotext.replace(/\[MYCALL\]/g, station_callsign);
newString = newString.replace(/\[CALL\]/g, CALL);
newString = newString.replace(/\[RSTS\]/g, RSTS);
return newString;
@@ -383,26 +384,43 @@ 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;
- function6Name = data.function6_name;
- function6Macro = data.function6_macro;
- function7Name = data.function7_name;
- function7Macro = data.function7_macro;
- function8Name = data.function8_name;
- function8Macro = data.function8_macro;
- function9Name = data.function9_name;
- function9Macro = data.function9_macro;
- function10Name = data.function10_name;
- function10Macro = data.function10_macro;
+ // Check if all fields are empty
+ const allEmpty = Object.values(data).every(value => value === "");
+
+ if (allEmpty) {
+ // Set default values
+ function1Name = 'CQ';
+ function1Macro = 'CQ CQ CQ DE [MYCALL] [MYCALL] K';
+ function2Name = 'REPT';
+ function2Macro = '[CALL] DE [MYCALL] [RSTS] [RSTS] K';
+ function3Name = 'TU';
+ function3Macro = '[CALL] TU 73 DE [MYCALL] K';
+ function4Name = 'QRZ';
+ function4Macro = 'QRZ DE [MYCALL] K';
+ function5Name = 'TEST';
+ function5Macro = 'TEST DE [MYCALL] K';
+ } else {
+ 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;
+ function6Name = data.function6_name;
+ function6Macro = data.function6_macro;
+ function7Name = data.function7_name;
+ function7Macro = data.function7_macro;
+ function8Name = data.function8_name;
+ function8Macro = data.function8_macro;
+ function9Name = data.function9_name;
+ function9Macro = data.function9_macro;
+ function10Name = data.function10_name;
+ function10Macro = data.function10_macro;
+ }
const morsekey_func1_Button = document.getElementById('morsekey_func1');
morsekey_func1_Button.textContent = 'F1 (' + function1Name + ')';