diff --git a/palm-client/Makefile b/palm-client/Makefile index 86ddeb0..4cb0555 100644 --- a/palm-client/Makefile +++ b/palm-client/Makefile @@ -60,7 +60,7 @@ build/$(APP)-sections.o: build/$(APP)-sections.s build/$(APP): $(OBJS) build/$(APP)-sections.o build/$(APP)-sections.ld $(CC) $(CFLAGS) -o $@ $(OBJS) build/$(APP)-sections.o build/$(APP)-sections.ld -build/res.stamp: resources/$(APP).rcp src/resources.h resources/smallfont.nfnt resources/largefont.nfnt resources/emoji.bin | build +build/res.stamp: resources/$(APP).rcp src/resources.h resources/smallfont.nfnt resources/largefont.nfnt resources/emoji.bin resources/icon/*.bmp | build rm -rf build/res && mkdir -p build/res $(PILRC) -q -I src $< build/res touch $@ diff --git a/palm-client/resources/icon/large1.bmp b/palm-client/resources/icon/large1.bmp new file mode 100644 index 0000000..6d00430 Binary files /dev/null and b/palm-client/resources/icon/large1.bmp differ diff --git a/palm-client/resources/icon/large4.bmp b/palm-client/resources/icon/large4.bmp new file mode 100644 index 0000000..394af78 Binary files /dev/null and b/palm-client/resources/icon/large4.bmp differ diff --git a/palm-client/resources/icon/large8.bmp b/palm-client/resources/icon/large8.bmp new file mode 100644 index 0000000..1940e1c Binary files /dev/null and b/palm-client/resources/icon/large8.bmp differ diff --git a/palm-client/resources/icon/small1.bmp b/palm-client/resources/icon/small1.bmp new file mode 100644 index 0000000..b592db9 Binary files /dev/null and b/palm-client/resources/icon/small1.bmp differ diff --git a/palm-client/resources/icon/small4.bmp b/palm-client/resources/icon/small4.bmp new file mode 100644 index 0000000..7448bc0 Binary files /dev/null and b/palm-client/resources/icon/small4.bmp differ diff --git a/palm-client/resources/icon/small8.bmp b/palm-client/resources/icon/small8.bmp new file mode 100644 index 0000000..eef5ab5 Binary files /dev/null and b/palm-client/resources/icon/small8.bmp differ diff --git a/palm-client/resources/visormesh.rcp b/palm-client/resources/visormesh.rcp index 4775af7..bfe2d36 100644 --- a/palm-client/resources/visormesh.rcp +++ b/palm-client/resources/visormesh.rcp @@ -2,6 +2,8 @@ VERSION ID 1 "0.1" APPLICATIONICONNAME ID 1000 "VisorMesh" +ICONFAMILY "resources/icon/large1.bmp" "" "resources/icon/large4.bmp" "resources/icon/large8.bmp" TRANSPARENT 255 255 255 +SMALLICONFAMILY "resources/icon/small1.bmp" "" "resources/icon/small4.bmp" "resources/icon/small8.bmp" TRANSPARENT 255 255 255 /* * Small UI font, registered as app font 0x80 at launch. tools/gen_font.py writes the @@ -285,7 +287,7 @@ BEGIN CHECKBOX "Public channel" ID 2206 AT (5 PREVBOTTOM AUTO 11) CHECKBOX "New contacts" ID 2207 AT (5 PREVBOTTOM AUTO 11) LABEL "Turning a sound on plays it." AUTOID AT (5 PREVBOTTOM+1) - LABEL "Volume: Prefs, General, Alarm" AUTOID AT (5 PREVBOTTOM) + LABEL "Volume: Prefs, General, Alarm " ID SoundsStatusLabel AT (5 PREVBOTTOM) LABEL "Check when closed:" AUTOID AT (5 132) FONT 1 POPUPTRIGGER "Off" ID SoundsCheckTrigger AT (95 131 AUTO AUTO) LEFTANCHOR LIST "Off" "Every 5 min" "Every 15 min" "Every 30 min" "Every hour" ID SoundsCheckList AT (90 90 66 AUTO) NONUSABLE VISIBLEITEMS 5 diff --git a/palm-client/src/bgcheck.c b/palm-client/src/bgcheck.c index c420365..cfd7f39 100644 --- a/palm-client/src/bgcheck.c +++ b/palm-client/src/bgcheck.c @@ -18,6 +18,23 @@ typedef struct { UInt16 minutes; } BgPrefs; +/* What the last check did, for Preferences (unsaved prefs: not backed up). */ +#define VM_BG_STATUS_ID 6 +#define VM_BG_STATUS_VERSION 1 +#define VM_BG_LAUNCHING 1 /* the check started and didn't finish */ +#define VM_BG_LAUNCH_ERR 2 /* SysAppLaunch failed: err */ +#define VM_BG_HOTSYNC 3 /* skipped: HotSync was running */ +#define VM_BG_NO_RADIO 4 /* couldn't connect: err */ +#define VM_BG_DONE 5 /* checked: kinds found */ + +typedef struct { + UInt16 version; + UInt16 stage; + UInt32 when; /* TimGetSeconds */ + UInt16 err; + UInt16 kinds; +} BgStatus; + /* Everything up to BgCheckRun runs in launches without globals: no globals, no extra segments. */ UInt16 BgInterval(void) @@ -58,6 +75,18 @@ static void SetAlarm(UInt32 when) AlmSetAlarm(card, id, 0, when, true); } +static void WriteStatus(UInt16 stage, Err err, UInt16 kinds) +{ + BgStatus st; + + st.version = VM_BG_STATUS_VERSION; + st.stage = stage; + st.when = TimGetSeconds(); + st.err = err; + st.kinds = kinds; + PrefSetAppPreferences(VM_CREATOR, VM_BG_STATUS_ID, VM_BG_STATUS_VERSION, &st, sizeof(st), false); +} + void BgSchedule(void) { UInt16 minutes = BgInterval(); @@ -65,11 +94,6 @@ void BgSchedule(void) SetAlarm(minutes ? TimGetSeconds() + (UInt32)minutes * 60 : 0); } -void BgCancel(void) -{ - SetAlarm(0); -} - void BgAlarmTriggered(SysAlarmTriggeredParamType *p) { UInt16 card, curCard; @@ -77,20 +101,27 @@ void BgAlarmTriggered(SysAlarmTriggeredParamType *p) UInt32 creator = 0, shown = 0, result; UInt16 kinds = 0; + Err err; + p->purgeAlarm = true; + BgSchedule(); /* first, so a failed check doesn't end the chain */ if (!FindSelf(&card, &id)) return; if (SysCurAppDatabase(&curCard, &curId) == errNone) { if (curId == id) - return; /* the app is open; it sets the alarm again when it exits */ + return; /* the app is open and checks for itself */ DmDatabaseInfo(curCard, curId, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &creator); } - BgSchedule(); /* first, so a failed check doesn't end the chain */ - if (creator == sysFileCSync) - return; /* HotSync has the USB port */ - if (SysAppLaunch(card, id, sysAppLaunchFlagNewGlobals, VM_LAUNCH_BGCHECK, &kinds, &result) != errNone || - !kinds) + if (creator == sysFileCSync) { + WriteStatus(VM_BG_HOTSYNC, errNone, 0); /* HotSync has the USB port */ + return; + } + WriteStatus(VM_BG_LAUNCHING, errNone, 0); /* BgCheckRun overwrites it */ + err = SysAppLaunch(card, id, sysAppLaunchFlagNewGlobals, VM_LAUNCH_BGCHECK, &kinds, &result); + if (err != errNone) + WriteStatus(VM_BG_LAUNCH_ERR, err, 0); + if (err != errNone || !kinds) return; FtrGet(VM_CREATOR, VM_FTR_BG_KINDS, &shown); FtrSet(VM_CREATOR, VM_FTR_BG_KINDS, shown | kinds); @@ -140,16 +171,66 @@ UInt16 BgCheckRun(void) { UInt16 kinds, n; + Err err; + AppLoadPrefs(); - if (SessionConnectLight() == errNone) { + err = SessionConnectLight(); + if (err == errNone) { for (n = 0; n < VM_BG_SYNC_ROUNDS && SessionMessageWaiting(); n++) SessionSyncMessages(); SessionDisconnect(); } kinds = SessionTakeSounds() & SoundsEnabledKinds(); SoundsNotify(kinds, NULL); + WriteStatus(err == errNone ? VM_BG_DONE : VM_BG_NO_RADIO, err, kinds); ContactsClose(); ChannelsClose(); MessagesClose(); return kinds; } + +/* "18:05" (24-hour: the label has no room for am/pm). */ +static void AppendTime(Char *out, UInt32 secs) +{ + DateTimeType dt; + + TimSecondsToDateTime(secs, &dt); + TimeToAscii((UInt8)dt.hour, (UInt8)dt.minute, tfColon24h, out + StrLen(out)); +} + +void BgStatusText(Char *out) +{ + BgStatus st; + UInt16 size = sizeof(st), card, n, kind; + LocalID id; + UInt32 ref, next = 0; + + out[0] = 0; + if (PrefGetAppPreferences(VM_CREATOR, VM_BG_STATUS_ID, &st, &size, false) != noPreferenceFound && + size == sizeof(st) && st.version == VM_BG_STATUS_VERSION) { + StrCopy(out, "Last "); + AppendTime(out, st.when); + switch (st.stage) { + case VM_BG_LAUNCHING: StrCat(out, " stopped"); break; + case VM_BG_HOTSYNC: StrCat(out, " HotSync"); break; + case VM_BG_NO_RADIO: StrCat(out, " no radio"); break; + case VM_BG_LAUNCH_ERR: + StrCat(out, " err "); + StrIToA(out + StrLen(out), st.err); + break; + case VM_BG_DONE: + for (n = 0, kind = 0; kind < VM_SND_COUNT; kind++) + if (st.kinds & (1 << kind)) + n++; + StrCat(out, n ? " new" : " ok"); + break; + } + } else { + StrCopy(out, "Not checked yet"); + } + if (FindSelf(&card, &id)) + next = AlmGetAlarm(card, id, &ref); + StrCat(out, next ? ", next " : ", no alarm"); + if (next) + AppendTime(out, next); +} diff --git a/palm-client/src/bgcheck.h b/palm-client/src/bgcheck.h index a7b752d..5629ccf 100644 --- a/palm-client/src/bgcheck.h +++ b/palm-client/src/bgcheck.h @@ -7,8 +7,8 @@ * and plays the notification sound. If anything new arrived, the alarm stays * for display, and BgDisplayAlarm shows an alert with an Open button. * - * While the app is open it checks for itself: the alarm is cleared at launch - * and set again at exit. + * While the app is open it checks for itself: the alarm keeps coming and is + * skipped, and exiting sets it N minutes on. */ #ifndef VM_BGCHECK_H #define VM_BGCHECK_H @@ -24,12 +24,14 @@ void BgSetInterval(UInt16 minutes); /* Sets the next alarm from the interval (clears it when off). */ void BgSchedule(void); -void BgCancel(void); /* Launch codes; no globals needed. */ void BgAlarmTriggered(SysAlarmTriggeredParamType *p); void BgDisplayAlarm(void); +/* "Last 18:05 ok, next 18:10" for Preferences: out holds 40. */ +void BgStatusText(Char *out) VM_SECT4; + /* The VM_LAUNCH_BGCHECK work, with globals: returns the enabled sound kinds (1 << VM_SND_*) found. */ UInt16 BgCheckRun(void) VM_SECT4; diff --git a/palm-client/src/main.c b/palm-client/src/main.c index 7b8bf94..51a9c01 100644 --- a/palm-client/src/main.c +++ b/palm-client/src/main.c @@ -190,7 +190,6 @@ UInt32 PilotMain(UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags) return errNone; } if (cmd == sysAppLaunchCmdNormalLaunch) { - BgCancel(); AppLoadPrefs(); UiFontInit(SoundsLargeText()); HeardLoad(); diff --git a/palm-client/src/resources.h b/palm-client/src/resources.h index 2eaa3a4..fc9acc4 100644 --- a/palm-client/src/resources.h +++ b/palm-client/src/resources.h @@ -133,6 +133,7 @@ #define SoundsCheckTrigger 2214 #define SoundsCheckList 2215 /* items: kCheckMinutes (sounds.c) */ #define BgNewAlert 2216 +#define SoundsStatusLabel 2217 /* last background check, or the volume hint */ #define ScopesForm 2300 #define ScopesDefaultLabel 2301 diff --git a/palm-client/src/sounds.c b/palm-client/src/sounds.c index f9d1dfb..980045f 100644 --- a/palm-client/src/sounds.c +++ b/palm-client/src/sounds.c @@ -7,6 +7,7 @@ #include "ui/draw.h" static void SavePrefs(void) VM_SECT3; +static void ShowCheckStatus(FormType *form) VM_SECT3; #define VM_SOUNDS_PREFS_ID 1 #define VM_SOUNDS_PREFS_VERSION 1 @@ -117,6 +118,18 @@ void SoundsNotify(UInt16 kinds, const VmConv *onScreen) } } +/* The status line shows the volume hint while checking is off. */ +static void ShowCheckStatus(FormType *form) +{ + Char text[40]; + + if (BgInterval()) + BgStatusText(text); + else + StrCopy(text, "Volume: Prefs, General, Alarm"); + FrmCopyLabel(form, SoundsStatusLabel, text); +} + void SoundsFormOpen(UInt16 returnForm) { if (returnForm != SoundsForm) @@ -144,13 +157,17 @@ Boolean SoundsFormHandleEvent(EventType *event) LstSetSelection(list, i); CtlSetLabel(FrmGetObjectPtr(form, FrmGetObjectIndex(form, SoundsCheckTrigger)), LstGetSelectionText(list, i)); + ShowCheckStatus(form); FrmDrawForm(form); return true; case popSelectEvent: - /* the alarm is set when the app exits; the trigger's label is set by the form */ + /* the trigger's label is set by the form */ if (event->data.popSelect.controlID == SoundsCheckTrigger && - event->data.popSelect.selection < VM_CHECK_CHOICES) + event->data.popSelect.selection < VM_CHECK_CHOICES) { BgSetInterval(kCheckMinutes[event->data.popSelect.selection]); + BgSchedule(); + ShowCheckStatus(form); + } break; case ctlSelectEvent: id = event->data.ctlSelect.controlID; diff --git a/palm-client/tools/make_icon.sh b/palm-client/tools/make_icon.sh new file mode 100755 index 0000000..fd6ff85 --- /dev/null +++ b/palm-client/tools/make_icon.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# Renders the app icon BMPs in resources/icon/ from the SVG (needs rsvg-convert +# and ImageMagick: brew install librsvg imagemagick). The BMPs are committed, so +# the build itself doesn't need these tools. +# +# tools/make_icon.sh [icon.svg] +# +# Large icon 32x22 and small (list view) 15x9, each at 1 bit (ordered dither), +# 4 bits (16 grays: the Visor Neo) and 8 bits (colour; pilrc maps it to the +# Palm palette). White is transparent. +set -e +cd "$(dirname "$0")/.." +SVG="${1:-../meshcore-visor-hair.svg}" +OUT=resources/icon +TMP=$(mktemp -d) +trap 'rm -rf "$TMP"' EXIT +mkdir -p "$OUT" + +rsvg-convert -w 512 -h 512 "$SVG" -o "$TMP/full.png" +magick "$TMP/full.png" -trim +repage "$TMP/trim.png" + +for spec in large:32x22 small:15x9; do + name=${spec%%:*} + size=${spec#*:} + magick "$TMP/trim.png" -resize "$size" -background white -gravity center -extent "$size" \ + -alpha remove "$TMP/$name.png" + magick "$TMP/$name.png" -colorspace Gray -ordered-dither o2x2 -threshold 50% -type Bilevel -compress None "BMP3:$OUT/${name}1.bmp" + magick "$TMP/$name.png" -colorspace Gray -dither None -colors 16 -type Palette -compress None "BMP3:$OUT/${name}4.bmp" + magick "$TMP/$name.png" -dither None -colors 64 -type Palette -compress None "BMP3:$OUT/${name}8.bmp" +done +ls -l "$OUT"