-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip #44: implement some basic cat control
Implements a new "screen tab" called CAT with the following: 1. Buttons to play messages that have been pre-recorded on the KX2/3 and stored in Bank1 or Bank2. 2. Three fields to enter text messages of up to 24 characters, which can be sent using CW. 3. Buttons to quickly set the transmit power to minimum (0) and maximum (10). - The CW keying could be improved by saving the messages. Presently they are not stored across page views. - Radio handling following the CW keying could be more intelligent. There is a TODO comment in the handler_cat.cpp file documenting the intention. - Max power on the KX3 is 15w as I recall, not 10, but 10 is hardcoded for now.
- Loading branch information
1 parent
141927b
commit 077d9dc
Showing
10 changed files
with
232 additions
and
4 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
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 |
---|---|---|
@@ -1 +1 @@ | ||
#define BUILD_DATE_TIME "240628:1451" | ||
#define BUILD_DATE_TIME "240629:1515" |
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
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
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,106 @@ | ||
#include <memory> | ||
#include "globals.h" | ||
#include "kx_radio.h" | ||
#include "webserver.h" | ||
|
||
#include <esp_log.h> | ||
static const char * TAG8 = "sc:hdl_cat "; | ||
|
||
/** | ||
* Handles an HTTP PUT request to play a pre-recorded message | ||
* | ||
* @param req Pointer to the HTTP request structure. The "bank" query parameter | ||
* is expected to hold either "1" or "2". | ||
*/ | ||
esp_err_t handler_msg_put (httpd_req_t * req) { | ||
showActivity(); | ||
|
||
ESP_LOGV (TAG8, "trace: %s()", __func__); | ||
|
||
STANDARD_DECODE_SOLE_PARAMETER (req, "bank", param_value); | ||
ESP_LOGI (TAG8, "playing message bank '%s'", param_value); | ||
|
||
long bank = atoi (param_value); // Convert the parameter to an integer | ||
const char * command = bank == 1 ? "SWT11;SWT19;" : "SWT11;SWT27;"; | ||
|
||
{ | ||
const std::lock_guard<Lockable> lock (kxRadio); | ||
kxRadio.put_to_kx_command_string (command, 1); | ||
} | ||
|
||
REPLY_WITH_SUCCESS(); | ||
} | ||
|
||
esp_err_t handler_power_get (httpd_req_t * req) { | ||
showActivity(); | ||
|
||
ESP_LOGV (TAG8, "trace: %s()", __func__); | ||
|
||
long power; | ||
{ | ||
const std::lock_guard<Lockable> lock (kxRadio); | ||
power = kxRadio.get_from_kx ("PC", SC_KX_COMMUNICATION_RETRIES, 3); | ||
} | ||
|
||
char power_string[8]; | ||
snprintf (power_string, sizeof (power_string), "%ld", power); | ||
ESP_LOGI (TAG8, "returning power: %s", power_string); | ||
httpd_resp_send (req, power_string, HTTPD_RESP_USE_STRLEN); | ||
|
||
return ESP_OK; | ||
} | ||
|
||
esp_err_t handler_power_put (httpd_req_t * req) { | ||
showActivity(); | ||
|
||
ESP_LOGV (TAG8, "trace: %s()", __func__); | ||
|
||
STANDARD_DECODE_SOLE_PARAMETER (req, "power", param_value); | ||
ESP_LOGI (TAG8, "setting power to '%s'", param_value); | ||
|
||
{ | ||
const std::lock_guard<Lockable> lock (kxRadio); | ||
if (!kxRadio.put_to_kx ("PC", 3, atoi (param_value), SC_KX_COMMUNICATION_RETRIES)) | ||
REPLY_WITH_FAILURE (req, 404, "unable to set power"); | ||
} | ||
|
||
REPLY_WITH_SUCCESS(); | ||
} | ||
|
||
esp_err_t handler_keyer_put (httpd_req_t * req) { | ||
showActivity(); | ||
|
||
ESP_LOGV (TAG8, "trace: %s()", __func__); | ||
|
||
STANDARD_DECODE_SOLE_PARAMETER (req, "message", param_value); | ||
|
||
url_decode_in_place (param_value); | ||
ESP_LOGI (TAG8, "keying message '%s'", param_value); | ||
|
||
char command[256]; | ||
snprintf (command, sizeof (command), "KYW%s;", param_value); | ||
{ | ||
const std::lock_guard<Lockable> lock (kxRadio); | ||
radio_mode_t mode; | ||
|
||
mode = (radio_mode_t)kxRadio.get_from_kx ("MD", SC_KX_COMMUNICATION_RETRIES, 1); | ||
if (mode != MODE_CW) | ||
kxRadio.put_to_kx ("MD", 1, MODE_CW, SC_KX_COMMUNICATION_RETRIES); | ||
kxRadio.put_to_kx_command_string (command, 1); | ||
/** | ||
* TODO: wait for keying to complete before changing mode back This can | ||
* be a combination of a smart delay computed by taking WPM, message | ||
* size, and standard dot length into account As well, it can finish by | ||
* querying the radio for characters remaining to transmit, and | ||
* repeating that polling using shorter cycle informed by the queue | ||
* length. See "TBX" command. As it stands, the mode switch will be | ||
* queued, and won't disrupt transmission, but since the command returns | ||
* immediately and says we're still in CW mode, it looks like a failure | ||
* in the logs. | ||
*/ | ||
if (mode != MODE_CW) | ||
kxRadio.put_to_kx ("MD", 1, mode, SC_KX_COMMUNICATION_RETRIES); | ||
} | ||
|
||
REPLY_WITH_SUCCESS(); | ||
} |
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,52 @@ | ||
<script src="cat.js"></script> | ||
<div class="cat-container"> | ||
<div class="msg-section"> | ||
<h2>Play Stored Msg</h2> | ||
<button class="bigthumb" onclick="playMsg(1)">Bank 1</button> | ||
<button class="bigthumb" onclick="playMsg(2)">Bank 2</button> | ||
</div> | ||
<hr /> | ||
<div class="keyer-section"> | ||
<h2>Send Text as CW</h2> | ||
<div class="input-group"> | ||
<input | ||
type="text" | ||
id="message1" | ||
pattern=".{0}|.{1,24}" | ||
placeholder="Type up to 24 chars" | ||
/> | ||
<button onclick="sendKeys(document.getElementById('message1').value)"> | ||
Send | ||
</button> | ||
</div> | ||
<div class="input-group"> | ||
<input | ||
type="text" | ||
id="message2" | ||
pattern=".{0}|.{1,24}" | ||
placeholder="Type up to 24 chars" | ||
/> | ||
<button onclick="sendKeys(document.getElementById('message2').value)"> | ||
Send | ||
</button> | ||
</div> | ||
<div class="input-group"> | ||
<input | ||
type="text" | ||
id="message3" | ||
pattern=".{0}|.{1,24}" | ||
placeholder="Type up to 24 chars" | ||
/> | ||
<button onclick="sendKeys(document.getElementById('message3').value)"> | ||
Send | ||
</button> | ||
</div> | ||
</div> | ||
<hr /> | ||
<div class="power-section"> | ||
<h2>Adjust Power</h2> | ||
<button class="bigthumb" onclick="setPowerMinMax(false)">Min</button> | ||
<button class="bigthumb" onclick="setPowerMinMax(true)">Max</button> | ||
</div> | ||
<hr /> | ||
</div> |
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,27 @@ | ||
function playMsg(slot) { | ||
// Create the PUT request using Fetch API | ||
const url = "/api/v1/msg?bank=" + slot; | ||
fetch(url, { method: "PUT" }).catch((error) => | ||
console.error("Fetch error:", error), | ||
); | ||
} | ||
|
||
function setPowerMinMax(maximum) { | ||
const url = "/api/v1/power?power=" + (maximum ? "10" : "0"); | ||
fetch(url, { method: "PUT" }).catch((error) => | ||
console.error("Fetch error:", error), | ||
); | ||
} | ||
|
||
function sendKeys(message) { | ||
if (message.length < 1 || message.length > 24) | ||
alert("Text length must be [1..24] characters."); | ||
else { | ||
const url = "/api/v1/keyer?message=" + message; | ||
fetch(url, { method: "PUT" }).catch((error) => | ||
console.error("Fetch error:", error), | ||
); | ||
} | ||
} | ||
|
||
function settingsOnAppearing() {} |
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
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
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