forked from Blendman974/faceclaw
Add sound demo to Faceclaw; use CFW mode 6 (headerless 4bpp) for images
This commit is contained in:
1 parent
116e8891e7
commit
acda9cdd7e
15 files changed
+262
-22
No files matched your search
@@ -155,6 +155,7 @@ class DashboardController {
|
||||
setTranscribeRenderActive: (active) => this.setTranscribeRenderActive(active),
|
||||
startDedicatedVoiceInput: (mode) => this.startDedicatedVoiceInput(mode),
|
||||
stopDedicatedVoiceInput: () => this.stopDedicatedVoiceInput(),
|
||||
playBuzzerNote: (note, oct, beat) => this.playBuzzerNote(note, oct, beat),
|
||||
});
|
||||
this.offAndroidNotification = onAndroidNotificationPosted((notificationKey) => {
|
||||
void this.handleAndroidNotificationPosted(notificationKey).catch((error) => {
|
||||
@@ -674,6 +675,13 @@ class DashboardController {
|
||||
this.startVoiceControlIfEnabled();
|
||||
}
|
||||
|
||||
private async playBuzzerNote(note: number, oct: number, beat: number): Promise<void> {
|
||||
if (this.phase !== "connected" || !this.communicator) {
|
||||
return;
|
||||
}
|
||||
await this.communicator.playBuzzerNote(note, oct, beat);
|
||||
}
|
||||
|
||||
private setStopwatchRenderActive(active: boolean): void {
|
||||
if (!active || this.phase !== "connected" || !this.communicator) {
|
||||
if (this.stopwatchRenderTimer) {
|
||||
|
||||
@@ -266,6 +266,16 @@ export class FaceclawCommunicatorBridge {
|
||||
return this.enqueueJavaCall(() => Boolean(this.communicator.sendShutdown(exitMode)));
|
||||
}
|
||||
|
||||
async playBuzzerNote(note: number, oct: number, beat: number): Promise<void> {
|
||||
await this.enqueueJavaCall(() => {
|
||||
this.communicator.playBuzzerNote(
|
||||
Math.round(note),
|
||||
Math.round(oct),
|
||||
Math.round(beat),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async close(): Promise<void> {
|
||||
await this.enqueueJavaCall(() => this.communicator.close());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
import { getDefaultSmallFont } from "../../graphics/bdffont";
|
||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
|
||||
import { Layer, type DashboardInputEvent, type LayerContext } from "../layers";
|
||||
|
||||
const NOTE_NAMES = ["C", "D", "E", "F", "G", "A", "B"] as const;
|
||||
const DEFAULT_BEAT = 4; // ~250ms at 62ms units
|
||||
|
||||
export class BuzzerDemoLayer implements Layer {
|
||||
private note = 1;
|
||||
private oct = 2;
|
||||
|
||||
paint(_ctx: LayerContext, _paintBelow: () => GrayImage): GrayImage {
|
||||
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
|
||||
const font = getDefaultSmallFont();
|
||||
|
||||
image.drawText(font, 24, 20, "Buzzer demo", 200);
|
||||
image.drawText(font, 24, 44, `Note: ${NOTE_NAMES[this.note - 1]} Octave: ${this.oct}`, 180);
|
||||
image.drawText(font, 24, 68, "Scroll: change note", 150);
|
||||
image.drawText(font, 24, 84, "Click: play note", 150);
|
||||
image.drawText(font, 24, 252, "Double-click: back", 130);
|
||||
|
||||
const keyWidth = 64;
|
||||
const keyY = 130;
|
||||
const keyX = Math.floor((G2_LENS_WIDTH - keyWidth * NOTE_NAMES.length) / 2);
|
||||
for (let i = 0; i < NOTE_NAMES.length; i++) {
|
||||
const selected = i + 1 === this.note;
|
||||
const x = keyX + i * keyWidth;
|
||||
image.drawRect(x + 2, keyY, keyWidth - 4, 48, selected ? 220 : 80);
|
||||
const label = NOTE_NAMES[i]!;
|
||||
image.drawText(
|
||||
font,
|
||||
x + Math.max(4, Math.floor((keyWidth - font.measureText(label)) / 2)),
|
||||
keyY + 18,
|
||||
label,
|
||||
selected ? 0 : 200,
|
||||
);
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
async handleInput(event: DashboardInputEvent, ctx: LayerContext): Promise<void> {
|
||||
switch (event.type) {
|
||||
case "scroll-up":
|
||||
this.advanceNote(1);
|
||||
return;
|
||||
case "scroll-down":
|
||||
this.advanceNote(-1);
|
||||
return;
|
||||
case "click":
|
||||
await ctx.actions.playBuzzerNote(this.note, this.oct, DEFAULT_BEAT);
|
||||
return;
|
||||
case "double-click":
|
||||
ctx.stack.pop();
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private advanceNote(delta: number): void {
|
||||
let next = this.note + delta;
|
||||
if (next > 7) {
|
||||
this.note = 1;
|
||||
this.oct = Math.min(3, this.oct + 1);
|
||||
return;
|
||||
}
|
||||
if (next < 1) {
|
||||
this.note = 7;
|
||||
this.oct = Math.max(0, this.oct - 1);
|
||||
return;
|
||||
}
|
||||
this.note = next;
|
||||
}
|
||||
}
|
||||
@@ -14,9 +14,11 @@ export type NightscoutSettings = {
|
||||
siteUrl: string;
|
||||
apiToken: string;
|
||||
};
|
||||
export type BatteryDisplayMode = "icon" | "percentage";
|
||||
export type SystemCardSettings = {
|
||||
showFaceclawLogo: boolean;
|
||||
showBatteryIndicators: boolean;
|
||||
batteryDisplayMode: BatteryDisplayMode;
|
||||
showAndroidNotifications: boolean;
|
||||
showSignalStrength: boolean;
|
||||
};
|
||||
@@ -197,6 +199,15 @@ export const showBatteryIndicatorsSetting = new ConfigSettingBoolean({
|
||||
defaultValue: true,
|
||||
});
|
||||
|
||||
export const batteryDisplayModeSetting = new ConfigSettingEnum<BatteryDisplayMode>({
|
||||
id: "batteryDisplayMode",
|
||||
label: "Battery display",
|
||||
storageKey: "dashboard.systemCard.batteryDisplayMode",
|
||||
defaultValue: "icon",
|
||||
values: ["icon", "percentage"],
|
||||
formatValue: batteryDisplayModeLabel,
|
||||
});
|
||||
|
||||
export const showAndroidNotificationsSetting = new ConfigSettingBoolean({
|
||||
id: "showAndroidNotifications",
|
||||
label: "Show Android Notifications",
|
||||
@@ -267,6 +278,10 @@ export function screenTimeoutLabel(value: ScreenTimeoutSetting): string {
|
||||
return value === "never" ? "Never" : value;
|
||||
}
|
||||
|
||||
export function batteryDisplayModeLabel(value: BatteryDisplayMode): string {
|
||||
return value === "icon" ? "Icon" : "Percentage";
|
||||
}
|
||||
|
||||
export function loadNightscoutSettings(): NightscoutSettings {
|
||||
return {
|
||||
siteUrl: nightscoutSiteUrlSetting.get(),
|
||||
|
||||
@@ -48,6 +48,7 @@ const dashboardActions: LayerActions = {
|
||||
setTranscribeRenderActive: () => {},
|
||||
startDedicatedVoiceInput: () => {},
|
||||
stopDedicatedVoiceInput: () => {},
|
||||
playBuzzerNote: () => {},
|
||||
};
|
||||
const dashboardFont = getDefaultSmallFont();
|
||||
export const TOP_LEFT_MENU_LAYOUT = { x: 8, y: 8, width: 272, height: 128 };
|
||||
|
||||
@@ -10,6 +10,7 @@ import { TelepromptLayer } from "../apps/teleprompt";
|
||||
import { StopwatchLayer } from "../apps/stopwatch";
|
||||
import { TranscribeLayer } from "../apps/transcribe";
|
||||
import { ScreenTestLayer } from "../apps/screen-test";
|
||||
import { BuzzerDemoLayer } from "../apps/buzzer-demo";
|
||||
import { AboutPage } from "./about-page";
|
||||
import { GrayImage } from "~/graphics/image";
|
||||
|
||||
@@ -105,6 +106,12 @@ function createAppsMenuLayer(): MenuLayer {
|
||||
ctx.stack.push(new ScreenTestLayer());
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Buzzer demo",
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(new BuzzerDemoLayer());
|
||||
},
|
||||
},
|
||||
],
|
||||
TOP_LEFT_MENU_LAYOUT,
|
||||
);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { dashboardState, TOP_LEFT_MENU_LAYOUT } from "../dashboard";
|
||||
import { dashboardSlotIds, enumSettingMenuItem, showSignalStrengthSetting, showAndroidNotificationsSetting, showBatteryIndicatorsSetting, showFaceclawLogoSetting, systemCardNameSetting, textSettingMenuItem, toggleSettingMenuItem, voiceControlEnabledSetting, dashboardSlotSettings, nightscoutSiteUrlSetting, nightscoutApiTokenSetting, screenTimeoutSetting } from "../dashboard-settings";
|
||||
import { batteryDisplayModeSetting, dashboardSlotIds, enumSettingMenuItem, showSignalStrengthSetting, showAndroidNotificationsSetting, showBatteryIndicatorsSetting, showFaceclawLogoSetting, systemCardNameSetting, textSettingMenuItem, toggleSettingMenuItem, voiceControlEnabledSetting, dashboardSlotSettings, nightscoutSiteUrlSetting, nightscoutApiTokenSetting, screenTimeoutSetting } from "../dashboard-settings";
|
||||
import { MenuLayer } from "../menu";
|
||||
|
||||
export function createSettingsMenuLayer(): MenuLayer {
|
||||
@@ -84,6 +84,7 @@ function createSystemCardSettingsMenuLayer(): MenuLayer {
|
||||
textSettingMenuItem(systemCardNameSetting),
|
||||
toggleSettingMenuItem(showFaceclawLogoSetting),
|
||||
toggleSettingMenuItem(showBatteryIndicatorsSetting),
|
||||
enumSettingMenuItem(batteryDisplayModeSetting),
|
||||
toggleSettingMenuItem(showAndroidNotificationsSetting),
|
||||
toggleSettingMenuItem(showSignalStrengthSetting),
|
||||
],
|
||||
|
||||
@@ -7,7 +7,7 @@ import { type DashboardPluginCardBounds } from "../dashboard-plugins";
|
||||
import { dashboardState } from "../dashboard";
|
||||
import { getDefaultMediumFont, getDefaultSmallFont } from "~/graphics/bdffont";
|
||||
import { getDashboardLogo } from "~/graphics/logo";
|
||||
import { showAndroidNotificationsSetting, showBatteryIndicatorsSetting, showFaceclawLogoSetting, showSignalStrengthSetting, systemCardNameSetting } from "../dashboard-settings";
|
||||
import { batteryDisplayModeSetting, showAndroidNotificationsSetting, showBatteryIndicatorsSetting, showFaceclawLogoSetting, showSignalStrengthSetting, systemCardNameSetting } from "../dashboard-settings";
|
||||
|
||||
const NOTIFICATION_ICON_SIZE = 24;
|
||||
const SYSTEM_CARD_ITEM_HEIGHT = 38;
|
||||
@@ -70,6 +70,10 @@ function systemCardFlowItemWidth(item: SystemCardFlowItem): number {
|
||||
if (item.type === "notification") {
|
||||
return NOTIFICATION_ICON_SIZE;
|
||||
}
|
||||
if (batteryDisplayModeSetting.get() === "percentage") {
|
||||
const percentText = formatBatteryPercent(item.percentCharge);
|
||||
return Math.max(smallFont.measureText(percentText), smallFont.measureText(item.label));
|
||||
}
|
||||
return Math.max(BATTERY_ICON_WIDTH, smallFont.measureText(item.label));
|
||||
}
|
||||
|
||||
@@ -98,14 +102,44 @@ function addBatteryItem(
|
||||
});
|
||||
}
|
||||
|
||||
function formatBatteryPercent(percentCharge: number): string {
|
||||
const clamped = Math.max(0, Math.min(100, Math.round(percentCharge)));
|
||||
return `${clamped}%`;
|
||||
}
|
||||
|
||||
function drawBatteryFlowItem(image: GrayImage, x: number, y: number, item: Extract<SystemCardFlowItem, { type: "battery" }>): void {
|
||||
const itemWidth = systemCardFlowItemWidth(item);
|
||||
const labelX = x + Math.max(0, ((itemWidth - smallFont.measureText(item.label)) / 2) | 0);
|
||||
image.drawText(smallFont, labelX, y + BATTERY_ITEM_Y_OFFSET, item.label, 150);
|
||||
if (batteryDisplayModeSetting.get() === "percentage") {
|
||||
drawBatteryPercentFlowItem(image, x, y, item, itemWidth);
|
||||
return;
|
||||
}
|
||||
const battery = drawBattery(item.percentCharge, item.isCharging);
|
||||
image.bitBlt(battery, x + ((itemWidth - battery.width) / 2) | 0, y + 16 + BATTERY_ITEM_Y_OFFSET);
|
||||
}
|
||||
|
||||
function drawBatteryPercentFlowItem(
|
||||
image: GrayImage,
|
||||
x: number,
|
||||
y: number,
|
||||
item: Extract<SystemCardFlowItem, { type: "battery" }>,
|
||||
itemWidth: number,
|
||||
): void {
|
||||
const percentText = formatBatteryPercent(item.percentCharge);
|
||||
const textWidth = smallFont.measureText(percentText);
|
||||
const textX = x + Math.max(0, ((itemWidth - textWidth) / 2) | 0);
|
||||
const textY = y + 16 + BATTERY_ITEM_Y_OFFSET;
|
||||
if (item.isCharging) {
|
||||
const padX = 2;
|
||||
const padY = 1;
|
||||
image.fillRect(textX - padX, textY - padY, textWidth + padX * 2, smallFont.lineHeight + padY * 2, 255);
|
||||
image.drawText(smallFont, textX, textY, percentText, 0);
|
||||
return;
|
||||
}
|
||||
image.drawText(smallFont, textX, textY, percentText, 200);
|
||||
}
|
||||
|
||||
function formatDashboardDate(now: Date): string {
|
||||
return `${WEEKDAYS[now.getDay()]} ${MONTHS[now.getMonth()]} ${now.getDate()} ${pad2(now.getHours())}:${pad2(now.getMinutes())}`;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ export type LayerActions = {
|
||||
setTranscribeRenderActive: (active: boolean) => Promise<void> | void;
|
||||
startDedicatedVoiceInput: (mode: "wakeword" | "full") => Promise<void> | void;
|
||||
stopDedicatedVoiceInput: () => Promise<void> | void;
|
||||
playBuzzerNote: (note: number, oct: number, beat: number) => Promise<void> | void;
|
||||
};
|
||||
|
||||
export type PaintBelow = () => GrayImage;
|
||||
|
||||
Reference in new issue
Block a user