Skip to content

Commit

Permalink
#887 - Make acaia connection switchable v1/v2
Browse files Browse the repository at this point in the history
  • Loading branch information
graphefruit committed Jan 17, 2025
1 parent 53bab4e commit 95ed946
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ios/App/App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.food-and-drink";
IPHONEOS_DEPLOYMENT_TARGET = 15.6;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 8.0.3;
MARKETING_VERSION = 8.0.4;
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\"";
PRODUCT_BUNDLE_IDENTIFIER = com.beanconqueror.app;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -380,7 +380,7 @@
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.food-and-drink";
IPHONEOS_DEPLOYMENT_TARGET = 15.6;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 8.0.3;
MARKETING_VERSION = 8.0.4;
PRODUCT_BUNDLE_IDENTIFIER = com.beanconqueror.app;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "";
Expand Down
15 changes: 15 additions & 0 deletions src/app/settings/settings.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,21 @@ <h2>{{"SMART_SCALE_COMMAND_DELAY" | translate}}</h2>
</ion-range>
</ion-item>


<ion-item lines="none">
<ion-label>
<h2>{{"SMART_SCALE_ACAIA_CONNECTION_MODE_TITLE" | translate}}</h2>
<p>{{"SMART_SCALE_ACAIA_CONNECTION_MODE_DESCRIPTION" | translate}}</p>
</ion-label>
</ion-item>
<ion-item *ngIf="platform.is('ios')">
<ion-select (ngModelChange)="saveSettings()" [(ngModel)]="settings.bluetooth_scale_acaia_connection_mode"
cancelText="{{'CANCEL'| translate }}" cancelText="{{'CANCEL'| translate }}"
okText="{{'CHOOSE'| translate }}" okText="{{'CHOOSE'| translate }}">
<ion-select-option value="V2">{{"SMART_SCALE_ACAIA_CONNECTION_MODE_V2" | translate}}</ion-select-option>
<ion-select-option value="V1">{{"SMART_SCALE_ACAIA_CONNECTION_MODE_V1" | translate}}</ion-select-option>
</ion-select>
</ion-item>
<ion-item lines="none">
<ion-label>
<h2>{{"SMART_SCALE_ACAIA_HEARTBEAT_TIMER" | translate}}</h2>
Expand Down
6 changes: 5 additions & 1 deletion src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1473,5 +1473,9 @@
"PAGE_SETTINGS_LANGUAGE_PORTUGUESE": "Portuguese",
"SMART_SCALE_ESPRESSO_WEIGHT_DOUBLING_JUST_ONE_CUP_TITLE": "Weight doubling - 1 of 2 cups on scale",
"SMART_SCALE_ESPRESSO_WEIGHT_DOUBLING_JUST_ONE_CUP_DESCRIPTION": "If just one cups fits on your scale, you can enable this setting. This makes it possible that you can choose in the brew, to activate a checkbox, when you have two cups, but just one is on the scale. The weight will get when the settings is activated doubled, to behave like there would be two cups on the scale.",
"BEAN_SORT_WEIGHT_REMAINING": "Remaining weight"
"BEAN_SORT_WEIGHT_REMAINING": "Remaining weight",
"SMART_SCALE_ACAIA_CONNECTION_MODE_TITLE": "Acaia connection mode",
"SMART_SCALE_ACAIA_CONNECTION_MODE_DESCRIPTION": "If your scale keeps connecting and disconnecting, try to set the mode to V1 and change the heartbeat and the command timer, with this you'll take the old connection routine",
"SMART_SCALE_ACAIA_CONNECTION_MODE_V2": "V2 - New connection mode",
"SMART_SCALE_ACAIA_CONNECTION_MODE_V1": "V1 - Old connection mode"
}
31 changes: 26 additions & 5 deletions src/classes/devices/acaia/acaia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class DecoderWorker {
}

let HEARTBEAT_INTERVAL = 1000;
let CONNECTION_MODE: string = 'V2';

export class AcaiaScale {
private readonly device_id: string;
Expand Down Expand Up @@ -145,6 +146,7 @@ export class AcaiaScale {
const uiSettingsStorage = UISettingsStorage.getInstance();
const settingsInst = uiSettingsStorage.getSettings();
HEARTBEAT_INTERVAL = settingsInst.acaia_heartbeat_command_delay;
CONNECTION_MODE = settingsInst.bluetooth_scale_acaia_connection_mode;
} catch (ex) {}
// TODO(mike1808): make it to work with new Lunar and Pyxis by auto-detecting service and char uuid
this.logger.info(
Expand Down Expand Up @@ -188,6 +190,10 @@ export class AcaiaScale {

public async connect(callback: any) {
this.logger.log('Connect scale');
try {
this.logger.log('Connect scale with mode' + CONNECTION_MODE);
} catch (ex) {}

if (this.connected) {
this.logger.log('Already connected, bail.');
return;
Expand Down Expand Up @@ -241,7 +247,10 @@ export class AcaiaScale {
*/
await sleep(150);

if (Capacitor.getPlatform() === 'android') {
if (
Capacitor.getPlatform() === 'android' ||
(CONNECTION_MODE === 'V1' && Capacitor.getPlatform() === 'ios')
) {
await this.write(new Uint8Array([0, 1]).buffer);
await this.notificationsReady();
} else {
Expand Down Expand Up @@ -382,7 +391,10 @@ export class AcaiaScale {
private startHeartbeatMonitor() {
this.heartbeat_monitor_interval = setInterval(async () => {
if (Date.now() > this.last_heartbeat + HEARTBEAT_INTERVAL) {
if (Capacitor.getPlatform() === 'android') {
if (
Capacitor.getPlatform() === 'android' ||
(CONNECTION_MODE === 'V1' && Capacitor.getPlatform() === 'ios')
) {
await this.initScales();
} else {
this.initScales();
Expand Down Expand Up @@ -450,7 +462,10 @@ export class AcaiaScale {
}

private async initScales() {
if (Capacitor.getPlatform() === 'android') {
if (
Capacitor.getPlatform() === 'android' ||
(CONNECTION_MODE === 'V1' && Capacitor.getPlatform() === 'ios')
) {
await this.ident();
} else {
this.ident();
Expand All @@ -460,7 +475,10 @@ export class AcaiaScale {
}

private async notificationsReady() {
if (Capacitor.getPlatform() === 'android') {
if (
Capacitor.getPlatform() === 'android' ||
(CONNECTION_MODE === 'V1' && Capacitor.getPlatform() === 'ios')
) {
await this.initScales();
} else {
this.initScales();
Expand Down Expand Up @@ -501,7 +519,10 @@ export class AcaiaScale {
}

private async ident() {
if (Capacitor.getPlatform() === 'android') {
if (
Capacitor.getPlatform() === 'android' ||
(CONNECTION_MODE === 'V1' && Capacitor.getPlatform() === 'ios')
) {
return new Promise((resolve) => {
this.write(encodeId(this.isPyxisStyle), true);
setTimeout(() => {
Expand Down
2 changes: 2 additions & 0 deletions src/classes/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export class Settings implements ISettings {
public bluetooth_scale_ignore_weight_button_active: boolean;
public bluetooth_scale_first_drip_threshold: number;
public bluetooth_scale_espresso_just_one_cup: boolean;
public bluetooth_scale_acaia_connection_mode: string;

public maximize_hide_value_cards_on_maximize_screen: boolean;

Expand Down Expand Up @@ -514,6 +515,7 @@ export class Settings implements ISettings {
this.bluetooth_scale_ignore_weight_button_active = false;
this.bluetooth_scale_first_drip_threshold = 0.1;
this.bluetooth_scale_espresso_just_one_cup = false;
this.bluetooth_scale_acaia_connection_mode = 'V2';

this.maximize_hide_value_cards_on_maximize_screen = false;

Expand Down
1 change: 1 addition & 0 deletions src/interfaces/settings/iSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export interface ISettings {
bluetooth_scale_ignore_weight_button_active: boolean;
bluetooth_scale_first_drip_threshold: number;
bluetooth_scale_espresso_just_one_cup: boolean;
bluetooth_scale_acaia_connection_mode: string;

maximize_hide_value_cards_on_maximize_screen: boolean;

Expand Down

0 comments on commit 95ed946

Please sign in to comment.