diff --git a/docs/progress.md b/docs/progress.md index 0001f85..a2f29b5 100644 --- a/docs/progress.md +++ b/docs/progress.md @@ -80,3 +80,4 @@ - 2026-11-02: Verified on the Neo against a PhillyMesh repeater: login, admin console (Read settings, typed CLI commands, Status 0x87 and Telemetry 0x8B decoded), contact detail with signal history, Add Contact, Reset Path. Segments: 9.1 / 27.7 / 12.4 KB. Upstream issues written up in docs/upstream-issues.md (none filed yet). - 2026-11-02: SB-LoRa transport written ahead of the boards: bus-SPI bit-bang over CS0/CS1 (`sb_spi.c`), SC16IS740 setup for 115200 8N1, burst FIFO access, sleep, and a "Slot" link on the Node screen (`transport_sb.c`). `tests/test_sblora.c` checks it against a simulated carrier (latches, inverter, SC16IS740). Unknowns for bring-up: whether connector A0 is CPU A1 (the probe tries both mappings via the scratch register), the hard-coded csSlot0 base 0x28000000 (no Handspring SDK for HsCardAttrGet), and RX overruns while the app isn't polling (no IRQ handler yet). Segments: 9.6 / 27.7 / 13.1 KB. - 2026-11-02: Slot with an empty slot reset the Visor (bus error at csSlot0), and since Slot was saved and Home auto-connects, every launch reset it. Slot is no longer restored at launch, and Connect now checks `HsCardAttrGet(hsCardAttrHwInstalled)` and takes the chip-select base and size from the OS before any bus access. Verified on the Neo: empty slot gives "No module in the slot." with no reset. Node-screen errors shortened to its 22-character labels. +- 2026-11-02: Notification sounds (Options > Sounds): separate tunes for direct messages, mentions, room posts, private / hashtag / Public channels and new contacts (PUSH_NEW_ADVERT), each on or off, at the alarm volume. One sound per poll, by priority; none for the conversation on screen. Verified on the Neo. Segment 3 is 13.8 KB. diff --git a/palm-client/Makefile b/palm-client/Makefile index c8926e3..5bda5a9 100644 --- a/palm-client/Makefile +++ b/palm-client/Makefile @@ -10,7 +10,7 @@ APP = visormesh NAME = VisorMesh CREATOR = VMsh -SRCS = src/main.c src/app.c src/home_form.c src/convo_form.c src/node_form.c src/channel_form.c src/convos.c src/protocol.c src/sha256.c src/transport_srm.c src/transport_sb.c src/sb_spi.c src/session.c src/settings.c src/presets.c src/contacts.c src/contacts_form.c src/contact_form.c src/heard.c src/remote_fmt.c src/remote.c src/remote_form.c src/messages.c src/channels.c src/preview_form.c src/ui/draw.c src/ui/text.c src/ui/rowlist.c src/ui/fontmetrics.c src/ports.c +SRCS = src/main.c src/app.c src/home_form.c src/convo_form.c src/node_form.c src/channel_form.c src/convos.c src/protocol.c src/sha256.c src/transport_srm.c src/transport_sb.c src/sb_spi.c src/session.c src/settings.c src/presets.c src/contacts.c src/contacts_form.c src/contact_form.c src/heard.c src/remote_fmt.c src/remote.c src/remote_form.c src/messages.c src/channels.c src/preview_form.c src/ui/draw.c src/ui/text.c src/ui/rowlist.c src/ui/fontmetrics.c src/ports.c src/sounds.c OBJS = $(SRCS:src/%.c=build/%.o) CC = m68k-palmos-gcc diff --git a/palm-client/resources/visormesh.rcp b/palm-client/resources/visormesh.rcp index 432a008..dc02441 100644 --- a/palm-client/resources/visormesh.rcp +++ b/palm-client/resources/visormesh.rcp @@ -20,6 +20,8 @@ BEGIN MENUITEM "Add Channel..." ID MainMenuAddChannel "A" MENUITEM "Leave Channel" ID MainMenuLeaveChannel "L" MENUITEM "-" AUTOID + MENUITEM "Sounds..." ID MainMenuSounds "B" + MENUITEM "-" AUTOID MENUITEM "Serial Ports..." ID MainMenuPorts "P" MENUITEM "Font Preview" ID MainMenuFontPreview "F" END @@ -260,6 +262,24 @@ BEGIN BUTTON "Done" ID PortsDoneButton AT (CENTER 145 AUTO AUTO) END +/* Sounds: checkbox IDs are SoundsFirstCheck + VM_SND_* (sounds.h) */ +FORM ID SoundsForm AT (0 0 160 160) +NOFRAME +USABLE +BEGIN + TITLE "Sounds" + CHECKBOX "Direct messages" ID 2201 AT (5 18 AUTO 12) + CHECKBOX "Mentions of me" ID 2202 AT (5 PREVBOTTOM+1 AUTO 12) + CHECKBOX "Room posts" ID 2203 AT (5 PREVBOTTOM+1 AUTO 12) + CHECKBOX "Private channels" ID 2204 AT (5 PREVBOTTOM+1 AUTO 12) + CHECKBOX "Hashtag channels" ID 2205 AT (5 PREVBOTTOM+1 AUTO 12) + CHECKBOX "Public channel" ID 2206 AT (5 PREVBOTTOM+1 AUTO 12) + CHECKBOX "New contacts" ID 2207 AT (5 PREVBOTTOM+1 AUTO 12) + LABEL "Turning a sound on plays it." AUTOID AT (5 PREVBOTTOM+6) + LABEL "Volume: Prefs, General, Alarm" AUTOID AT (5 PREVBOTTOM+1) + BUTTON "Done" ID SoundsDoneButton AT (CENTER 145 AUTO AUTO) +END + ALERT ID RomIncompatibleAlert ERROR BEGIN diff --git a/palm-client/src/app.c b/palm-client/src/app.c index 54f09d2..739c672 100644 --- a/palm-client/src/app.c +++ b/palm-client/src/app.c @@ -3,6 +3,7 @@ #include "transport.h" #include "session.h" #include "app.h" +#include "sounds.h" VmConv gAppConv; Boolean gAppAutoConnectTried = false; @@ -25,6 +26,7 @@ void AppLoadPrefs(void) UInt16 size = sizeof(prefs); Int32 west; + SoundsLoad(); if (PrefGetAppPreferences(VM_CREATOR, VM_PREFS_ID, &prefs, &size, true) != noPreferenceFound && size == sizeof(prefs) && prefs.version == VM_PREFS_VERSION) { /* diff --git a/palm-client/src/channels.c b/palm-client/src/channels.c index ce96b98..d2341cf 100644 --- a/palm-client/src/channels.c +++ b/palm-client/src/channels.c @@ -157,3 +157,12 @@ Err ChannelsRemove(UInt8 slot, UInt8 maxChannels) MemSet(zero, sizeof(zero), 0); return ChannelsSet(slot, kEmpty, zero, maxChannels); } + +UInt8 ChannelKind(const VmChannel *c) +{ + if (c->name[0] == '#') + return VM_CHAN_HASHTAG; + if (c->idx == 0 || StrCaselessCompare(c->name, "Public") == 0) + return VM_CHAN_PUBLIC; + return VM_CHAN_PRIVATE; +} diff --git a/palm-client/src/channels.h b/palm-client/src/channels.h index b8dfd8c..933f6d3 100644 --- a/palm-client/src/channels.h +++ b/palm-client/src/channels.h @@ -15,6 +15,12 @@ UInt16 ChannelsCount(void) VM_SECT2; Boolean ChannelsGet(UInt16 i, VmChannel *out) VM_SECT2; Boolean ChannelsFindSlot(UInt8 slot, VmChannel *out) VM_SECT2; +/* A slot's kind, from its name: Public (slot 0), a #hashtag, or private. */ +#define VM_CHAN_PUBLIC 0 +#define VM_CHAN_HASHTAG 1 +#define VM_CHAN_PRIVATE 2 +UInt8 ChannelKind(const VmChannel *c) VM_SECT2; + /* The first slot not in use (from the cache), or -1 if all maxChannels are used. */ Int16 ChannelsFreeSlot(UInt8 maxChannels) VM_SECT2; /* Stores a channel in a slot on the radio (name in the Visor's charset), then refreshes the cache. */ diff --git a/palm-client/src/convos.c b/palm-client/src/convos.c index a9e94ea..3c7ce4b 100644 --- a/palm-client/src/convos.c +++ b/palm-client/src/convos.c @@ -37,11 +37,11 @@ void ContactNameForPrefix(const UInt8 *prefix, Char *out, UInt16 size) /* Channel names: "#foo" shows as marker '#' + "foo"; slot 0 / Public as '@'; others are private. */ static Char ChannelMarker(const VmChannel *c) { - if (c->name[0] == '#') - return '#'; - if (c->idx == 0 || StrCaselessCompare(c->name, "Public") == 0) - return '@'; - return GLYPH_LOCK; + switch (ChannelKind(c)) { + case VM_CHAN_HASHTAG: return '#'; + case VM_CHAN_PUBLIC: return '@'; + default: return GLYPH_LOCK; + } } static void ChannelDisplayName(const VmChannel *c, Char *out, UInt16 size) diff --git a/palm-client/src/main.c b/palm-client/src/main.c index f8839e6..3a0aead 100644 --- a/palm-client/src/main.c +++ b/palm-client/src/main.c @@ -12,6 +12,7 @@ #include "heard.h" #include "remote.h" #include "remote_form.h" +#include "sounds.h" #include "node_form.h" #include "settings.h" #include "ports.h" @@ -45,6 +46,7 @@ static Boolean HandleMenu(UInt16 itemID) case MainMenuNode: FrmGotoForm(MainForm); return true; case MainMenuPorts: FrmGotoForm(PortsForm); return true; case MainMenuFontPreview: FrmGotoForm(FontPreviewForm); return true; + case MainMenuSounds: SoundsFormOpen(FrmGetActiveFormID()); return true; case MainMenuAddChannel: FrmGotoForm(ChannelForm); return true; case MainMenuLeaveChannel: ChannelLeaveCurrent(); return true; } @@ -75,6 +77,7 @@ static Boolean AppHandleEvent(EventType *event) case ContactForm: FrmSetEventHandler(form, ContactFormHandleEvent); break; case ContactAddForm: FrmSetEventHandler(form, ContactAddFormHandleEvent); break; case RemoteForm: FrmSetEventHandler(form, RemoteFormHandleEvent); break; + case SoundsForm: FrmSetEventHandler(form, SoundsFormHandleEvent); break; } return true; } @@ -121,9 +124,9 @@ static void Poll(void) if (RemoteTick()) changed |= VM_CHANGED_REMOTE; - /* a short beep for a new DM or mention, unless that conversation is on screen */ - if ((changed & VM_CHANGED_ALERT) && !(formId == ConvoForm && ConvEqual(SessionAlertConv(), &gAppConv))) - SndPlaySystemSound(sndConfirmation); + /* a notification sound, unless it's for the conversation on screen */ + if (changed & VM_CHANGED_ALERT) + SoundsNotify(SessionTakeSounds(), formId == ConvoForm ? &gAppConv : NULL); if (changed) FrmUpdateForm(formId, VM_UPDATE_DATA); if (formId == ConvoForm) diff --git a/palm-client/src/resources.h b/palm-client/src/resources.h index 2d889d3..efdd27c 100644 --- a/palm-client/src/resources.h +++ b/palm-client/src/resources.h @@ -22,6 +22,7 @@ #define MainMenuNode 1005 #define MainMenuAddChannel 1006 #define MainMenuLeaveChannel 1007 +#define MainMenuSounds 1008 #define MainLinkGroup 1 #define SettingsForm 1200 @@ -118,6 +119,10 @@ #define RomIncompatibleAlert 2000 +#define SoundsForm 2200 +#define SoundsFirstCheck 2201 /* + VM_SND_* (sounds.h), in that order */ +#define SoundsDoneButton 2210 + #define SmallFontRes 1000 #define FontPreviewForm 1400 #define FontPreviewDoneButton 1401 diff --git a/palm-client/src/session.c b/palm-client/src/session.c index ca8d0ec..0ce296a 100644 --- a/palm-client/src/session.c +++ b/palm-client/src/session.c @@ -8,6 +8,7 @@ #include "session.h" #include "heard.h" #include "remote.h" +#include "sounds.h" #define VM_APP_NAME "VisorMesh" #define VM_REPLY_TIMEOUT (2 * SysTicksPerSecond()) @@ -40,6 +41,8 @@ static UInt16 gRxPos, gRxLen; */ static Int32 gUtcOffsetSecs = 0; /* local minus UTC */ +static void NoteSound(UInt8 kind, const VmMessage *m); + void SessionSetUtcOffset(Int16 minutes) { gUtcOffsetSecs = (Int32)minutes * 60; @@ -83,6 +86,9 @@ static void HandlePush(void) if (VmParseRxLog(gDecoder.payload, gDecoder.len, &rx)) HeardRecord(&rx, SessionNow()); } else if (code == VM_PUSH_ADVERT || code == VM_PUSH_NEW_ADVERT || code == VM_PUSH_PATH_UPDATED) { + /* NEW_ADVERT is the radio's first sight of a node (MyMesh::onDiscoveredContact is_new) */ + if (code == VM_PUSH_NEW_ADVERT) + NoteSound(VM_SND_CONTACT, NULL); gChanged |= VM_CHANGED_CONTACTS; } } @@ -332,19 +338,24 @@ Err SessionGetChannel(UInt8 slot, VmChannel *out) return err; } -/* The newest message that should alert (a DM, or a mention of us in a channel). */ -static VmConv gAlertConv; +/* Sound kinds noted since SessionTakeSounds, and the conversation of the newest of each. */ +static UInt16 gSounds; +static VmConv gSoundConv[VM_SND_COUNT]; -static void NoteAlert(const VmMessage *m) +/* m is the message, or NULL for an event without a conversation (a new contact). */ +static void NoteSound(UInt8 kind, const VmMessage *m) { - MemSet(&gAlertConv, sizeof(gAlertConv), 0); - if (m->isChannel) { - gAlertConv.type = VM_CONV_CHANNEL; - gAlertConv.channel = m->channelIdx; - } else { - gAlertConv.type = VM_CONV_DIRECT; - MemMove(gAlertConv.key, m->senderPrefix, 6); + VmConv *c = &gSoundConv[kind]; + + MemSet(c, sizeof(*c), 0); + if (m && m->isChannel) { + c->type = VM_CONV_CHANNEL; + c->channel = m->channelIdx; + } else if (m) { + c->type = VM_CONV_DIRECT; + MemMove(c->key, m->senderPrefix, 6); } + gSounds |= 1 << kind; gChanged |= VM_CHANGED_ALERT; } @@ -369,9 +380,39 @@ static Boolean MentionsUs(const VmMessage *m) return false; } -const VmConv *SessionAlertConv(void) +/* Room posts arrive signed, from the room's key; a room contact covers unsigned ones. */ +static UInt8 MessageSound(const VmMessage *m) { - return &gAlertConv; + VmChannel ch; + VmContact ct; + + if (MentionsUs(m)) + return VM_SND_MENTION; + if (m->isChannel) { + if (!ChannelsFindSlot(m->channelIdx, &ch)) + return VM_SND_PRIVATE; + switch (ChannelKind(&ch)) { + case VM_CHAN_PUBLIC: return VM_SND_PUBLIC; + case VM_CHAN_HASHTAG: return VM_SND_HASHTAG; + default: return VM_SND_PRIVATE; + } + } + if (m->hasSigner || (ContactsFindByPrefix(m->senderPrefix, &ct) && ct.type == VM_ADV_TYPE_ROOM)) + return VM_SND_ROOM; + return VM_SND_DIRECT; +} + +UInt16 SessionTakeSounds(void) +{ + UInt16 kinds = gSounds; + + gSounds = 0; + return kinds; +} + +const VmConv *SessionSoundConv(UInt8 kind) +{ + return &gSoundConv[kind]; } Err SessionSyncMessages(void) @@ -403,8 +444,7 @@ Err SessionSyncMessages(void) } if (MessagesAddIncoming(&m, SessionNow()) == errNone) { gChanged |= VM_CHANGED_MESSAGES; - if (!m.isChannel || MentionsUs(&m)) - NoteAlert(&m); + NoteSound(MessageSound(&m), &m); } } gMsgWaiting = true; /* more left: carry on at the next poll */ diff --git a/palm-client/src/session.h b/palm-client/src/session.h index bbb240e..3d87146 100644 --- a/palm-client/src/session.h +++ b/palm-client/src/session.h @@ -19,7 +19,7 @@ /* What SessionPoll found changed, so the screen on show can redraw. */ #define VM_CHANGED_MESSAGES 0x0001 #define VM_CHANGED_CONTACTS 0x0002 -#define VM_CHANGED_ALERT 0x0004 /* a new DM or mention of us arrived: see SessionAlertConv */ +#define VM_CHANGED_ALERT 0x0004 /* something to sound for: see SessionTakeSounds */ #define VM_CHANGED_REMOTE 0x0008 /* the admin console has new lines */ @@ -72,8 +72,10 @@ UInt32 SessionRadioTime(void); * messages and times out unacked DMs. Returns VM_CHANGED_* flags. */ UInt16 SessionPoll(void); -/* The conversation of the newest message that should alert (a DM or a mention of us). */ -const VmConv *SessionAlertConv(void); +/* The sound kinds (1 << VM_SND_*, sounds.h) noted since the last call; clears them. */ +UInt16 SessionTakeSounds(void); +/* The conversation of the newest message of that kind. */ +const VmConv *SessionSoundConv(UInt8 kind); /* Pulls queued messages into the message store (SYNC_NEXT_MESSAGE until none are left). */ Err SessionSyncMessages(void); Err SessionGetChannel(UInt8 slot, VmChannel *out); diff --git a/palm-client/src/sounds.c b/palm-client/src/sounds.c new file mode 100644 index 0000000..d8c1bc5 --- /dev/null +++ b/palm-client/src/sounds.c @@ -0,0 +1,129 @@ +#include +#include "resources.h" +#include "app.h" +#include "session.h" +#include "sounds.h" + +static void SavePrefs(void) VM_SECT3; + +#define VM_SOUNDS_PREFS_ID 1 +#define VM_SOUNDS_PREFS_VERSION 1 + +/* Off by default: the busy channels. */ +#define VM_SND_DEFAULT ((UInt16)~((1 << VM_SND_HASHTAG) | (1 << VM_SND_PUBLIC))) + +typedef struct { + UInt16 version; + UInt16 enabled; /* 1 << VM_SND_* */ +} SoundsPrefs; + +static UInt16 gEnabled = VM_SND_DEFAULT; +static UInt16 gReturnForm = HomeForm; + +/* Up to three notes per kind as (Hz, ms) pairs; 0 ends a tune early. */ +static const UInt16 kTunes[VM_SND_COUNT][6] = { + { 1760, 70, 2349, 90, 0, 0 }, /* direct: rising pair */ + { 2093, 50, 2093, 50, 2637, 90 }, /* mention: double tap, then up */ + { 1319, 70, 1760, 90, 0, 0 }, /* room: lower rising pair */ + { 1568, 60, 1976, 60, 0, 0 }, /* private channel */ + { 1397, 60, 0, 0, 0, 0 }, /* hashtag: one blip */ + { 1175, 40, 0, 0, 0, 0 }, /* public: shorter, lower blip */ + { 2637, 60, 1976, 60, 1568, 80 }, /* new contact: falling three */ +}; + +void SoundsLoad(void) +{ + SoundsPrefs prefs; + UInt16 size = sizeof(prefs); + + if (PrefGetAppPreferences(VM_CREATOR, VM_SOUNDS_PREFS_ID, &prefs, &size, true) != noPreferenceFound && + size == sizeof(prefs) && prefs.version == VM_SOUNDS_PREFS_VERSION) + gEnabled = prefs.enabled; +} + +static void SavePrefs(void) +{ + SoundsPrefs prefs; + + prefs.version = VM_SOUNDS_PREFS_VERSION; + prefs.enabled = gEnabled; + PrefSetAppPreferences(VM_CREATOR, VM_SOUNDS_PREFS_ID, VM_SOUNDS_PREFS_VERSION, &prefs, sizeof(prefs), true); +} + +void SoundsPlay(UInt8 kind) +{ + SndCommandType cmd; + UInt16 amp = (UInt16)PrefGetPreference(prefAlarmSoundVolume); + UInt16 i; + + if (kind >= VM_SND_COUNT || amp == 0) + return; + for (i = 0; i < 6 && kTunes[kind][i]; i += 2) { + if (i) + SysTaskDelay(1); /* a short gap so repeated notes stay separate */ + cmd.cmd = sndCmdFreqDurationAmp; + cmd.param1 = kTunes[kind][i]; + cmd.param2 = kTunes[kind][i + 1]; + cmd.param3 = amp; + SndDoCmd(NULL, &cmd, false); + } +} + +void SoundsNotify(UInt16 kinds, const VmConv *onScreen) +{ + UInt8 kind; + + for (kind = 0; kind < VM_SND_COUNT; kind++) { + if (!(kinds & (1 << kind)) || !(gEnabled & (1 << kind))) + continue; + /* a new contact has no conversation to be looking at */ + if (kind != VM_SND_CONTACT && onScreen && ConvEqual(SessionSoundConv(kind), onScreen)) + continue; + SoundsPlay(kind); + return; + } +} + +void SoundsFormOpen(UInt16 returnForm) +{ + if (returnForm != SoundsForm) + gReturnForm = returnForm; + FrmGotoForm(SoundsForm); +} + +Boolean SoundsFormHandleEvent(EventType *event) +{ + FormType *form = FrmGetActiveForm(); + UInt16 id; + UInt8 kind; + + switch (event->eType) { + case frmOpenEvent: + for (kind = 0; kind < VM_SND_COUNT; kind++) + FrmSetControlValue(form, FrmGetObjectIndex(form, SoundsFirstCheck + kind), + (gEnabled & (1 << kind)) != 0); + FrmDrawForm(form); + return true; + case ctlSelectEvent: + id = event->data.ctlSelect.controlID; + if (id == SoundsDoneButton) { + FrmGotoForm(gReturnForm); + return true; + } + if (id >= SoundsFirstCheck && id < SoundsFirstCheck + VM_SND_COUNT) { + kind = (UInt8)(id - SoundsFirstCheck); + if (event->data.ctlSelect.on) { + gEnabled |= 1 << kind; + SoundsPlay(kind); /* turning one on is how you hear it */ + } else { + gEnabled &= ~(1 << kind); + } + SavePrefs(); + return true; + } + break; + default: + break; + } + return false; +} diff --git a/palm-client/src/sounds.h b/palm-client/src/sounds.h new file mode 100644 index 0000000..b085436 --- /dev/null +++ b/palm-client/src/sounds.h @@ -0,0 +1,36 @@ +/* + * Notification sounds: a short tune for each kind of event, each of which can + * be turned off on the Sounds screen. Played at the system's alarm volume + * (Prefs > General > Alarm Sound), so muting taps doesn't mute messages. + */ +#ifndef VM_SOUNDS_H +#define VM_SOUNDS_H + +#include +#include "sections.h" +#include "messages.h" + +/* In priority order: one sound per poll, for the first kind that applies. */ +#define VM_SND_DIRECT 0 /* a direct message */ +#define VM_SND_MENTION 1 /* @[our name] anywhere */ +#define VM_SND_ROOM 2 /* a room server post */ +#define VM_SND_PRIVATE 3 /* a private (secret-key) channel */ +#define VM_SND_HASHTAG 4 /* a #hashtag channel */ +#define VM_SND_PUBLIC 5 /* the Public channel */ +#define VM_SND_CONTACT 6 /* a node we haven't seen advertised itself */ +#define VM_SND_COUNT 7 + +void SoundsLoad(void) VM_SECT3; +void SoundsPlay(UInt8 kind) VM_SECT3; + +/* + * Plays the first enabled kind in 'kinds' (a bitmask of 1 << VM_SND_*), skipping + * messages in the conversation on screen (onScreen; NULL if none is). + */ +void SoundsNotify(UInt16 kinds, const VmConv *onScreen) VM_SECT3; + +/* The Sounds screen; Done goes back to returnForm. */ +void SoundsFormOpen(UInt16 returnForm) VM_SECT3; +Boolean SoundsFormHandleEvent(EventType *event) VM_SECT3; + +#endif