Skip to content

Commit

Permalink
Temporal work around for a dead-lock issue:
Browse files Browse the repository at this point in the history
  • Loading branch information
palthedog committed Jul 14, 2024
1 parent 060b4b5 commit 675123b
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 66 deletions.
14 changes: 13 additions & 1 deletion firmware/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ default_envs = debug

[env]
lib_deps = bblanchon/ArduinoJson@^7.0.4
adafruit/Adafruit TinyUSB Library@^3.3.1
;adafruit/Adafruit TinyUSB Library@^3.3.1
Adafruit TinyUSB Library=https://github.com/palthedog/Adafruit_TinyUSB_Arduino

platform = https://github.com/maxgerhardt/platform-raspberrypi.git
framework = arduino
Expand Down Expand Up @@ -57,3 +58,14 @@ build_type = debug
build_flags =
${env.build_flags}
-DDEBUG

;; For Raspberry Pi Pico
[env:pico_debug]
build_type = debug
board = pico
; 2MB FLASH memory
board_upload.maximum_size = 2097152
board_build.filesystem_size = 1m
build_flags =
${env.build_flags}
-DDEBUG
1 change: 1 addition & 0 deletions firmware/src/serial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ void SerialHandler::HandleSerial(Udong& context) {

// String serial_buffer;
void SerialHandler::HandleCmd(Udong& context, const String& cmd) {
Serial.printf("Received command: %s\n", cmd.c_str());
if (cmd == "") {
// Do nothing
} else if (cmd == "dump") {
Expand Down
18 changes: 17 additions & 1 deletion firmware/src/udong.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <memory>

#include "boards/breadboard.h"
#include "boards/udong_prototype1.h"
#include "config/config_util.h"
#include "gamepad/button/button.h"
Expand Down Expand Up @@ -144,7 +145,15 @@ class Udong {
config.mutable_baked()->set_board_name(board_name.c_str());

// Configure circuit
circuit = std::make_unique<UdongPrototype1>();
if (config.baked().board_name() == "Udong Board rev.1") {
circuit = std::make_unique<UdongPrototype1>();
} else if (config.baked().board_name() == "Udong Board rev.2") {
// circuit = std::make_unique<UdongPrototype2>();
} else if (config.baked().board_name() == "Breadboard") {
circuit = std::make_unique<Breadboard>();
} else {
// TODO
}
ConfigureSwitches();

// No need of calibration if reloading
Expand All @@ -160,8 +169,15 @@ class Udong {
for (const ButtonAssignment& b : config.button_assignments()) {
std::shared_ptr<Switch> switch_ptr;
if (b.switch_id().type() == SwitchType::ANALOG_SWITCH) {
if (analog_switches_.size() <= b.switch_id().id()) {
// We don't have that many analog switches
continue;
}
switch_ptr = analog_switches_[b.switch_id().id()];
} else if (b.switch_id().type() == SwitchType::DIGITAL_SWITCH) {
if (digital_switches_.size() <= b.switch_id().id()) {
continue;
}
switch_ptr = digital_switches_[b.switch_id().id()];
} else {
Serial.println("Unknown switch type");
Expand Down
1 change: 0 additions & 1 deletion web_conf/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ <h1>{{title}}</h1>
<div [hidden]=" !(connected | async)">
<app-configurator>
</app-configurator>

<!--app-text-commander></app-text-commander-->
</div>

Expand Down
21 changes: 11 additions & 10 deletions web_conf/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { inject, Component } from '@angular/core';
import { inject, Component, Output } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterOutlet } from '@angular/router';

Expand All @@ -10,7 +10,8 @@ import { AnalogSwitchConfigComponent } from "./analog-switch-config/analog-switc
import { ConfiguratorComponent } from "./configurator/configurator.component";
import { SerialConnectorComponent } from './serial-connector/serial-connector.component';
import { TextCommanderComponent } from './text-commander/text-commander.component';
import { Logger } from './logger';
import { logger } from './logger';
import { Observable } from 'rxjs';

@Component({
selector: 'app-root',
Expand All @@ -22,20 +23,20 @@ import { Logger } from './logger';
]
})
export class AppComponent {
log = inject(Logger);
serial_service = inject(SerialServiceInterface);

title: string = '';

serial_service = inject(SerialServiceInterface);
connected = this.serial_service.ConnectionChanges();
connected?: Observable<boolean>;

constructor() {
this.serial_service.ConnectionChanges().subscribe(connected => {
this.title = connected ? 'Udong is Connected' : 'Udong is Not Connected';
});
logger.debug('AppComponent initialized', this.serial_service);
this.connected = this.serial_service.ConnectionChanges();
}

ngOnInit() {
logger.debug('AppComponent initialized', this.serial_service);
this.serial_service.ConnectionChanges().subscribe(connected => {
this.title = connected ? 'Udong is Connected' : 'Udong is Not Connected';
});
}

}
2 changes: 0 additions & 2 deletions web_conf/src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { provideAnimationsAsync } from '@angular/platform-browser/animations/asy
import { routes } from './app.routes';

import { environment } from '../environments/environment';
import { provideLogger } from './logger';
import { SerialServiceInterface } from './serial/serial.service';

export const appConfig: ApplicationConfig = {
Expand All @@ -17,7 +16,6 @@ export const appConfig: ApplicationConfig = {
provideClientHydration(),
provideAnimationsAsync(),
provideAnimations(), provideAnimationsAsync(), provideAnimationsAsync(),
provideLogger(),
{ provide: SerialServiceInterface, useClass: environment.serialService },
]
};
8 changes: 3 additions & 5 deletions web_conf/src/app/board-buttons/board-buttons.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { CommonModule } from '@angular/common';
import { Component, Input, Output, inject } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { AppConsts } from '../consts';
import { Logger } from '../logger';
import { SwitchId, SwitchType, UdongConfig } from '../../proto/config';
import { SwitchIdToButtonId, SwitchIdToGroupId } from '../config_util';
import { BoardInfo, BoardInfoProvider, SwitchInfo } from '../board_info/board_info';
import { logger } from '../logger';

@Component({
selector: 'app-board-buttons',
Expand All @@ -15,8 +15,6 @@ import { BoardInfo, BoardInfoProvider, SwitchInfo } from '../board_info/board_in
styleUrl: './board-buttons.component.scss'
})
export class BoardButtonsComponent {
log = inject(Logger);

board_info_provider = inject(BoardInfoProvider);

@Input()
Expand Down Expand Up @@ -47,7 +45,7 @@ export class BoardButtonsComponent {
let group_id = SwitchIdToGroupId(this.config, switch_id);
return this.app_consts.configGroupColor(group_id!);
}
this.log.error('Unknown switch_id.type: ', switch_id);
logger.error('Unknown switch_id.type: ', switch_id);

return '#fff';
}
Expand All @@ -58,7 +56,7 @@ export class BoardButtonsComponent {
}

onClickButton(switch_id: SwitchId) {
this.log.debug('button clicked', switch_id);
logger.debug('button clicked', switch_id);
this.activeSwitchIdChanged.next(switch_id);
}
}
3 changes: 3 additions & 0 deletions web_conf/src/app/configurator/configurator.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
>
</app-board-buttons>

<app-button-preview>
</app-button-preview>

<mat-divider style="margin-bottom: 8px"></mat-divider>

<div
Expand Down
22 changes: 11 additions & 11 deletions web_conf/src/app/configurator/configurator.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ import { AnalogSwitchConfig, AnalogSwitchGroup, ButtonAssignment, ButtonId, Swit
import { AppConsts } from '../consts';
import { GroupSelectorComponent } from '../group-selector/group-selector.component';
import { SerialServiceInterface } from '../serial/serial.service';
import { Logger } from '../logger';
import { logger, Logger } from '../logger';
import { SwitchIdToGroupId, compareButtonIds } from '../config_util';
import { ButtonPreviewComponent } from "../button-preview/button-preview.component";

@Component({
selector: 'app-configurator',
standalone: true,
imports: [MatDividerModule, MatSelectModule, BoardButtonsComponent, MatRippleModule, MatFormFieldModule, MatCardModule, CommonModule, AnalogSwitchConfigComponent, MatButtonModule, GroupSelectorComponent, FormsModule],
imports: [MatDividerModule, MatSelectModule, BoardButtonsComponent, MatRippleModule, MatFormFieldModule, MatCardModule, CommonModule, AnalogSwitchConfigComponent, MatButtonModule, GroupSelectorComponent, FormsModule, ButtonPreviewComponent],
templateUrl: './configurator.component.html',
styleUrl: './configurator.component.scss'
})
export class ConfiguratorComponent {
log = inject(Logger);
serial_service = inject(SerialServiceInterface);
consts = inject(AppConsts);

Expand All @@ -46,17 +46,17 @@ export class ConfiguratorComponent {

constructor() {
this.serial_service.ConnectionChanges().subscribe((connected) => {
this.log.info('connected', connected);
logger.info('connected', connected);
if (connected) {
this.serial_service.Send('get-config');
}
});

this.serial_service.MessageReceiveFor('get-config').subscribe((v) => {
this.log.info('get-config size: ', v.length);
logger.info('get-config size: ', v.length);
this.config = UdongConfig.deserializeBinary(v[1]);
this.log.info('Config received');
this.log.info(this.config.toObject());
logger.info('Config received');
logger.info(this.config.toObject());
if (this.config) {
this.group_ids = this.config.analog_switch_groups.map((group) => {
return group.analog_switch_group_id;
Expand All @@ -68,7 +68,7 @@ export class ConfiguratorComponent {
}

setActiveSwitchId(switch_id: SwitchId) {
this.log.info('active switch changed', switch_id);
logger.info('active switch changed', switch_id);
this.active_switch_id = switch_id;
this.setActiveGroupId(SwitchIdToGroupId(this.config!, this.active_switch_id));
if (this.ripple) {
Expand All @@ -77,12 +77,12 @@ export class ConfiguratorComponent {
}

onGroupSelected() {
this.log.info('onGroupSelected');
logger.info('onGroupSelected');
this.setActiveGroupId(SwitchIdToGroupId(this.config!, this.active_switch_id));
}

setActiveGroupId(group_id: number | null) {
this.log.info('active group changed', group_id);
logger.info('active group changed', group_id);
this.active_group_id = group_id;
}

Expand Down Expand Up @@ -116,7 +116,7 @@ export class ConfiguratorComponent {
if (this.config == undefined) {
return;
}
this.log.info('save:', this.config);
logger.info('save:', this.config);
this.serial_service.SendBinary('save-config', this.config.serializeBinary());
}
}
6 changes: 2 additions & 4 deletions web_conf/src/app/logger.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Provider } from '@angular/core';
import log, { getLogger } from 'loglevel';
import { environment } from '../environments/environment';

export class Logger {
[x: string]: any;
impl_: log.Logger;

constructor(impl: log.Logger) {
Expand Down Expand Up @@ -46,6 +46,4 @@ function loggerFactory() {
return new Logger(logger);
}

export function provideLogger(): Provider {
return { provide: Logger, useFactory: loggerFactory };
};
export let logger: Logger = loggerFactory();
18 changes: 8 additions & 10 deletions web_conf/src/app/serial/mock_serial.service.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { Injectable, inject } from '@angular/core';
import { Injectable } from '@angular/core';

import { BehaviorSubject, Observable, Subject, defer, filter } from 'rxjs';
import { SerialServiceInterface } from './serial.service';
import { Logger } from '../logger';

import { AnalogSwitchConfig, AnalogSwitchGroup, ButtonAssignment, ButtonId, ButtonType, PushButtonSelector, RapidTriggerConfig, StaticTriggerConfig, SwitchId, SwitchType, TriggerType, UdongConfig } from '../../proto/config';
import { logger } from '../logger';

@Injectable()
export class MockSerialService extends SerialServiceInterface {
log = inject(Logger);

private message_subject = new Subject<[string, Uint8Array]>();
private connection_subject = new BehaviorSubject<boolean>(false);

Expand All @@ -26,9 +24,9 @@ export class MockSerialService extends SerialServiceInterface {
}

override async Send(cmd: string, message?: string) {
this.log.info('Sending via MockSerialService');
this.log.info('cmd: ', cmd);
this.log.info('payload: ', message);
logger.info('Sending via MockSerialService');
logger.info('cmd: ', cmd);
logger.info('payload: ', message);
if (cmd == 'get-config') {
this.HandleGetConfig();
} else {
Expand All @@ -39,9 +37,9 @@ export class MockSerialService extends SerialServiceInterface {
}

override async SendBinary(cmd: string, payload: Uint8Array) {
this.log.info('Sending Binary via MockSerialService');
this.log.info('cmd: ', cmd);
this.log.info('payload-size: ', payload.length);
logger.info('Sending Binary via MockSerialService');
logger.info('cmd: ', cmd);
logger.info('payload-size: ', payload.length);
}

private MockResponse(type: string, bin_payload: Uint8Array) {
Expand Down
Loading

0 comments on commit 675123b

Please sign in to comment.