Skip to content

Commit

Permalink
feat: ability to toggle bits with event #1058
Browse files Browse the repository at this point in the history
  • Loading branch information
unocelli committed Nov 20, 2024
1 parent a3b1f22 commit e2dcc9c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
11 changes: 8 additions & 3 deletions client/src/app/fuxa-view/fuxa-view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { Subject, Subscription, take } from 'rxjs';
import { ChangeDetectorRef } from '@angular/core';

import { Event, GaugeEvent, GaugeEventActionType, GaugeSettings, GaugeProperty, GaugeEventType, GaugeRangeProperty, GaugeStatus, Hmi, View, ViewType, Variable, ZoomModeType, InputOptionType, DocAlignType, DictionaryGaugeSettings, GaugeEventRelativeFromType, ViewEventType, InputActionEscType } from '../_models/hmi';
import { Event, GaugeEvent, GaugeEventActionType, GaugeSettings, GaugeProperty, GaugeEventType, GaugeRangeProperty, GaugeStatus, Hmi, View, ViewType, Variable, ZoomModeType, InputOptionType, DocAlignType, DictionaryGaugeSettings, GaugeEventRelativeFromType, ViewEventType, InputActionEscType, IPropertyVariable } from '../_models/hmi';
import { GaugesManager } from '../gauges/gauges.component';
import { Utils } from '../_helpers/utils';
import { ScriptParam, SCRIPT_PARAMS_MAP, ScriptParamType } from '../_models/script';
Expand Down Expand Up @@ -512,8 +512,9 @@ export class FuxaViewComponent implements OnInit, AfterViewInit, OnDestroy {
}

onToggleValue(ga: GaugeSettings, event: GaugeEvent) {
if (event.actoptions && event.actoptions['variable'] && event.actoptions['variable']['variableId']) {
this.gaugesManager.toggleSignalValue(event.actoptions['variable']['variableId']);
const actionOptions = event.actoptions as ActionOptionsVariable;
if (actionOptions?.variable?.variableId) {
this.gaugesManager.toggleSignalValue(actionOptions.variable.variableId, actionOptions.variable.bitmask);
} else if (ga.property && ga.property.variableId) {
this.gaugesManager.toggleSignalValue(ga.property.variableId);
}
Expand Down Expand Up @@ -1051,6 +1052,10 @@ interface VariableMappingDictionary {
[key: string]: VariableMappingType;
}

interface ActionOptionsVariable {
variable: IPropertyVariable;
}

export class CardModel {
public id: string;
public name: string;
Expand Down
6 changes: 5 additions & 1 deletion client/src/app/gauges/gauge-base/gauge-base.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class GaugeBaseComponent {
}
gaugeStatus.actionRef.type = act.type;
if (toEnable) {
if (gaugeStatus.actionRef.timer &&
if (gaugeStatus.actionRef.timer &&
(GaugeBaseComponent.getBlinkActionId(act) == gaugeStatus.actionRef.spool.actId)) {
return;
}
Expand Down Expand Up @@ -209,6 +209,10 @@ export class GaugeBaseComponent {
return value;
}

static toggleBitmask(value: number, bitmask: number): number {
return value ^ bitmask;
}

static getBlinkActionId(act: GaugeAction) {
return `${act.variableId}-${act.range.max}-${act.range.min}`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,19 @@
</div>
</div>
<div style="display: block; padding-top: 5px;padding-left: 25px;"
*ngIf="withToggleValue(item.action) || withSetValue(item.action) || withSetInput(item.action)">
*ngIf="withSetValue(item.action) || withSetInput(item.action)">
<flex-variable style="display: block" [data]="data" [(value)]="item.actoptions.variable" [withStaticValue]="false"></flex-variable>
</div>
<div style="display: block; padding-top: 5px;padding-left: 25px;"
*ngIf="withToggleValue(item.action)">
<flex-variable style="display: block"
[data]="data"
[(value)]="item.actoptions.variable"
[withBitmask]="true"
[bitmask]="item.actoptions.variable?.bitmask"
[withStaticValue]="false">
</flex-variable>
</div>
<div style="display: inline-block" *ngIf="withAddress(item.action)">
<div class="my-form-field" style="padding-left: 20px;">
<span>{{'gauges.property-event-address' | translate}}</span>
Expand Down
7 changes: 5 additions & 2 deletions client/src/app/gauges/gauges.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,13 +562,16 @@ export class GaugesManager {
}
}

toggleSignalValue(sigid: string) {
toggleSignalValue(sigid: string, bitmask?: number) {
if (this.hmiService.variables.hasOwnProperty(sigid)) {
let currentValue = this.hmiService.variables[sigid].value;
if (currentValue === null || currentValue === undefined){
return;
} else {
if (currentValue === 0 || currentValue === '0') {
if (!Utils.isNullOrUndefined(bitmask)) {
const value = GaugeBaseComponent.toggleBitmask(currentValue, bitmask);
this.putSignalValue(sigid, value.toString());
} else if (currentValue === 0 || currentValue === '0') {
this.putSignalValue(sigid, '1');
} else if (currentValue === 1 || currentValue === '1') {
this.putSignalValue(sigid, '0');
Expand Down

0 comments on commit e2dcc9c

Please sign in to comment.