palm-client: MeshTerm-style screens: conversations, transcript, contacts, node
Home is now the conversation list (channels in slot order, then direct conversations most recent first) with markers, unread badges, failed marks, ages and previews; it connects on launch with the saved link. The conversation screen shows day dividers, sender chips, time column, wrapped text and SNR or delivery marks (pending, waiting for ack, acked, failed), with a compose field, a UTF-8 byte counter, Send (or Graffiti return), and tap-to-retry on failed messages. Contacts pins our node and shows type marks, heard ages and routes; Message opens a DM. The old main screen becomes Node with Advert and Done. One Options menu everywhere; while connected the event loop polls every half second and posts a form update when messages or contacts change.
This commit is contained in:
1 parent
ece6a01c7f
commit
c04bebeb81
21 files changed
+1355
-264
No files matched your search
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Node: this radio's details, the link (USB / serial), connect/disconnect,
|
||||
* settings and sending an advert.
|
||||
*/
|
||||
#include <PalmOS.h>
|
||||
#include "resources.h"
|
||||
#include "protocol.h"
|
||||
#include "transport.h"
|
||||
#include "session.h"
|
||||
#include "app.h"
|
||||
#include "node_form.h"
|
||||
|
||||
#define VM_LABEL_CHARS 22 /* the info labels in the .rcp are padded to this width */
|
||||
|
||||
/* Replaces a label's text, truncated to the width reserved for it in the .rcp. */
|
||||
static void SetLabel(FormType *form, UInt16 id, const Char *text)
|
||||
{
|
||||
Char buf[VM_LABEL_CHARS + 1];
|
||||
UInt16 index = FrmGetObjectIndex(form, id);
|
||||
Boolean visible = FrmVisible(form);
|
||||
|
||||
StrNCopy(buf, text, VM_LABEL_CHARS);
|
||||
buf[VM_LABEL_CHARS] = 0;
|
||||
if (visible)
|
||||
FrmHideObject(form, index);
|
||||
FrmCopyLabel(form, id, buf);
|
||||
if (visible)
|
||||
FrmShowObject(form, index);
|
||||
}
|
||||
|
||||
/* Formats e.g. 869618 kHz as "869.618 MHz" and 62500 Hz as "62.5" (kHz), without floating point. */
|
||||
static void FormatFreq(Char *out, UInt32 kHz)
|
||||
{
|
||||
StrPrintF(out, "%lu.%03lu MHz", kHz / 1000, kHz % 1000);
|
||||
}
|
||||
|
||||
static void FormatBandwidth(Char *out, UInt32 hz)
|
||||
{
|
||||
if (hz % 1000)
|
||||
StrPrintF(out, "%lu.%lu", hz / 1000, (hz % 1000) / 100);
|
||||
else
|
||||
StrPrintF(out, "%lu", hz / 1000);
|
||||
}
|
||||
|
||||
static void ShowRadioInfo(FormType *form)
|
||||
{
|
||||
const VmDeviceInfo *dev = SessionDevice();
|
||||
const VmSelfInfo *self = SessionSelf();
|
||||
Char buf[40], bw[12];
|
||||
|
||||
if (!SessionIsConnected()) {
|
||||
SetLabel(form, MainNameLabel, "Not connected");
|
||||
SetLabel(form, MainFreqLabel, "-");
|
||||
SetLabel(form, MainModeLabel, "-");
|
||||
SetLabel(form, MainPowerLabel, "-");
|
||||
SetLabel(form, MainFirmwareLabel, "-");
|
||||
CtlSetLabel(FrmGetObjectPtr(form, FrmGetObjectIndex(form, MainConnectButton)), "Connect");
|
||||
return;
|
||||
}
|
||||
SetLabel(form, MainNameLabel, self->name);
|
||||
FormatFreq(buf, self->freqKHz);
|
||||
SetLabel(form, MainFreqLabel, buf);
|
||||
FormatBandwidth(bw, self->bwHz);
|
||||
StrPrintF(buf, "BW %s SF%u CR%u", bw, self->sf, self->cr);
|
||||
SetLabel(form, MainModeLabel, buf);
|
||||
StrPrintF(buf, "%d dBm (max %u)", (Int16)self->txPowerDbm, self->maxTxPowerDbm);
|
||||
SetLabel(form, MainPowerLabel, buf);
|
||||
StrPrintF(buf, "%s (%u)", dev->version, dev->fwVerCode);
|
||||
SetLabel(form, MainFirmwareLabel, buf);
|
||||
CtlSetLabel(FrmGetObjectPtr(form, FrmGetObjectIndex(form, MainConnectButton)), "Disconnect");
|
||||
}
|
||||
|
||||
static FormType *gStatusForm;
|
||||
|
||||
static void ShowStatus(const Char *text)
|
||||
{
|
||||
SetLabel(gStatusForm, MainNameLabel, text);
|
||||
}
|
||||
|
||||
static void ConnectOrDisconnect(FormType *form)
|
||||
{
|
||||
Char msg[40];
|
||||
Err err;
|
||||
|
||||
if (SessionIsConnected()) {
|
||||
SessionDisconnect();
|
||||
ShowRadioInfo(form);
|
||||
return;
|
||||
}
|
||||
gStatusForm = form;
|
||||
err = AppConnect(ShowStatus, true);
|
||||
ShowRadioInfo(form);
|
||||
if (err != errNone) {
|
||||
AppErrorText(err, msg);
|
||||
SetLabel(form, MainNameLabel, msg);
|
||||
}
|
||||
}
|
||||
|
||||
static void SendAdvert(void)
|
||||
{
|
||||
UInt16 choice;
|
||||
Char msg[40];
|
||||
Err err;
|
||||
|
||||
if (!SessionIsConnected()) {
|
||||
FrmCustomAlert(SettingsErrorAlert, "Connect to the radio first.", "", "");
|
||||
return;
|
||||
}
|
||||
choice = FrmAlert(AdvertAlert); /* 0 zero-hop, 1 flood, 2 cancel */
|
||||
if (choice > 1)
|
||||
return;
|
||||
err = SessionSendAdvert(choice == 1);
|
||||
if (err != errNone) {
|
||||
AppErrorText(err, msg);
|
||||
FrmCustomAlert(SettingsErrorAlert, msg, "", "");
|
||||
}
|
||||
}
|
||||
|
||||
Boolean NodeFormHandleEvent(EventType *event)
|
||||
{
|
||||
FormType *form = FrmGetActiveForm();
|
||||
|
||||
switch (event->eType) {
|
||||
case frmOpenEvent: {
|
||||
UInt16 link = (TransportGetPort() == VM_PORT_USB) ? MainUsbPush : MainSerialPush;
|
||||
|
||||
FrmSetControlGroupSelection(form, MainLinkGroup, link);
|
||||
ShowRadioInfo(form);
|
||||
FrmDrawForm(form);
|
||||
return true;
|
||||
}
|
||||
case frmUpdateEvent:
|
||||
ShowRadioInfo(form);
|
||||
return true;
|
||||
|
||||
case ctlSelectEvent:
|
||||
switch (event->data.ctlSelect.controlID) {
|
||||
case MainSerialPush:
|
||||
case MainUsbPush:
|
||||
/* Changing the link drops any open connection; it applies on the next Connect. */
|
||||
if (SessionIsConnected()) {
|
||||
SessionDisconnect();
|
||||
ShowRadioInfo(form);
|
||||
}
|
||||
TransportSetPort(event->data.ctlSelect.controlID == MainUsbPush ? VM_PORT_USB : VM_PORT_SERIAL);
|
||||
AppSavePrefs();
|
||||
return true;
|
||||
case MainConnectButton:
|
||||
ConnectOrDisconnect(form);
|
||||
return true;
|
||||
case MainSettingsButton:
|
||||
if (SessionIsConnected())
|
||||
FrmGotoForm(SettingsForm);
|
||||
else
|
||||
FrmCustomAlert(SettingsErrorAlert, "Connect to the radio first.", "", "");
|
||||
return true;
|
||||
case MainAdvertButton:
|
||||
SendAdvert();
|
||||
return true;
|
||||
case MainDoneButton:
|
||||
FrmGotoForm(HomeForm);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Reference in new issue
Block a user