Skip to content

Commit

Permalink
add reset default
Browse files Browse the repository at this point in the history
  • Loading branch information
amatilda committed Mar 28, 2024
1 parent eb39491 commit 7d4cf2c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/controller_sapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,20 @@ class ControllerSapiClass {
return (ControllerSapiClassStatus.OK);
}

public async setDefault(): Promise<ControllerSapiClassStatus> {
if (this._test_cmd(SapiClassFuncId.FUNC_ID_ZW_SET_DEFAULT) == false)
return (ControllerSapiClassStatus.UNSUPPORT_CMD);
const seq:number = this._set_seq();
const res:SapiClassRet = await this.sapi.sendCommandUnSz(SapiClassFuncId.FUNC_ID_ZW_SET_DEFAULT, [seq]);
if (res.status != SapiClassStatus.OK)
return ((res.status as any));
if (res.data.length < 0x1)//0x1 seq
return (ControllerSapiClassStatus.WRONG_LENGTH_SEQ);
if (res.data[0x0] != seq)
return (ControllerSapiClassStatus.WRONG_SEQ);
return (ControllerSapiClassStatus.OK);
}

public getBoardInfo(): ControllerSapiClassBoardInfo {
return (this.board_info);
}
Expand Down
21 changes: 20 additions & 1 deletion src/controller_ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ControllerUiClass {
private readonly MESSAGE_SET_LICENSE:string = "Set license the controller";
private readonly MESSAGE_READ_BOARD_INFO:string = "Read board info the controller";
private readonly MESSAGE_SET_REGION:string = "Set region the controller";
private readonly MESSAGE_SET_DEFAULT:string = "Set default the controller";
private readonly MESSAGE_PLEASE_WAIT:string = "Please wait until the previous operation is completed.";
private readonly MESSAGE_VERSION_LOG = "SerialAPIWebTools version 0.0.1";

Expand All @@ -42,6 +43,10 @@ class ControllerUiClass {
private readonly TABLE_NAME_VENDOR_ID_TITLE:string = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
private readonly TABLE_NAME_REGION:string = "Region:";
private readonly TABLE_NAME_REGION_TITLE:string = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
private readonly TABLE_NAME_RESET_DEFAULT:string = "Reset default:";
private readonly TABLE_NAME_RESET_DEFAULT_TITLE:string = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
private readonly TABLE_NAME_RESET_DEFAULT_BUTTON:string = "Reset";
private readonly TABLE_NAME_RESET_DEFAULT_BUTTON_TITLE:string = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
private readonly TABLE_NAME_REGION_SELECT_TITLE:string = "Select region";
private readonly TABLE_NAME_REGION_BUTTON:string = "Apple";
private readonly TABLE_NAME_REGION_BUTTON_TITLE:string = "Apple select region";
Expand Down Expand Up @@ -218,6 +223,18 @@ class ControllerUiClass {
this._log_error_faled_code(this.MESSAGE_SET_REGION, status);
}

private async _reset_default(): Promise<void> {
if (this._is_busy() == true)
return ;
this._log_info_start(this.MESSAGE_SET_DEFAULT);
const status:ControllerSapiClassStatus = await this.razberry.setDefault();
if (status == ControllerSapiClassStatus.OK) {
this._log_info_done(this.MESSAGE_SET_DEFAULT);
return ;
}
this._log_error_faled_code(this.MESSAGE_SET_DEFAULT, status);
}

private _html_event(el:HTMLElement, data:string): void {
const list:NodeListOf<HTMLElement> = el.querySelectorAll('[data-'+ data + ']');
list.forEach((item:HTMLElement) => {
Expand Down Expand Up @@ -355,7 +372,7 @@ class ControllerUiClass {
}

private _get_controller_default(): boolean {

this._create_table_element_controler_info(this.TABLE_NAME_RESET_DEFAULT, "", '<button data-click="_reset_default()" title="' + this.TABLE_NAME_RESET_DEFAULT_BUTTON_TITLE + '" type="button">' + this.TABLE_NAME_RESET_DEFAULT_BUTTON + '</button>', this.TABLE_NAME_RESET_DEFAULT_TITLE);
return (true);
}

Expand All @@ -367,6 +384,8 @@ class ControllerUiClass {
display = true;
if (await this._get_region() == true)
display = true;
if (await this._get_controller_default() == true)
display = true;
if (display == false)
return ;
this._start_display(this.SECTION_ID_DATA_CONTROLLER_INFO, "");
Expand Down

0 comments on commit 7d4cf2c

Please sign in to comment.