Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | 65x 6x 6x 6x 6x 9x 9x 9x 6x 6x 3x 3x 9x 9x 4x 4x 2x 4x 4x 1x 3x 2x 1x 1x 4x 3x 3x 3x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x | import { Component, inject, Input, OnChanges } from '@angular/core';
import { InputNumberModule } from 'primeng/inputnumber';
import { InputSwitchModule } from 'primeng/inputswitch';
import { Signal } from '../../models/signals';
import { TwinpadApiService } from '../../services/twinpad-api.service';
import { FormsModule } from '@angular/forms';
import { NgIf } from '@angular/common';
import { FloatLabelModule } from 'primeng/floatlabel';
import { ToastModule } from 'primeng/toast';
import { MessageService } from 'primeng/api';
import { Select } from 'primeng/select';
import { InputGroupModule } from 'primeng/inputgroup';
import { InputGroupAddonModule } from 'primeng/inputgroupaddon';
import { DatePicker } from 'primeng/datepicker';
@Component({
selector: 'app-signal-command',
imports: [InputSwitchModule, InputNumberModule, FormsModule, NgIf, FloatLabelModule, ToastModule, Select, InputGroupModule, InputGroupAddonModule, DatePicker],
providers: [],
templateUrl: './signal-command.component.html',
styleUrl: './signal-command.component.scss'
})
export class SignalCommandComponent implements OnChanges{
private messageService = inject(MessageService);
@Input() signal: Signal;
@Input() forcedValue: string | number | null;
boolValue: boolean=false;
floatValue: number = 0;
dateValue: Date;
enumOptions: string[];
stringValue: string;
placeholder: string;
button_message: string;
precisionNumber: string;
constructor(private twinpadApiService: TwinpadApiService
){}
ngOnChanges(){
this.precisionNumber = "";
Iif (this.signal.precision_digits){
this.precisionNumber = this.signal.precision_digits.toString();
}
if(this.signal.type === "command"){
this.button_message = "Send command";
this.placeholder = "Value";
}
else{
this.button_message = "Force sensor";
this.placeholder = "Forced value";
}
this.enumOptions = this.signal.stringEnumOptions();
this.stringValue = this.enumOptions[0];
}
sendCommand(){
let value: string | number | boolean;
let signalDataType = this.signal.data_type;
if (this.signal.isEnum()){
signalDataType = this.signal.enumType();
}
value = this.floatValue;
if (signalDataType === "bool"){
value = this.boolValue;
}
else if (signalDataType === "str"){
value = this.stringValue;
}
else Eif (signalDataType === "epoch"){
value = this.dateValue.getTime() / 1000;
}
if (this.signal.type === "command"){
console.log(this.signal);
this.twinpadApiService.sendSignalCommand(this.signal, value, this.forcedValue).subscribe(_ => {
this.messageService.add({severity: 'success', summary: 'Command success', detail: this.signal.signal_id+' sent value '+value });
},
error => {
console.log(error);
this.messageService.add({severity: 'error', summary: 'Command error', detail: error.message });
});
}
else{
this.twinpadApiService.sendSignalForcedValue(this.signal, value).subscribe(_ => {
this.messageService.add({severity: 'success', summary: 'Value forced', detail: this.signal.signal_id+' sent forced value '+value });
},
error => {
console.log(error);
this.messageService.add({severity: 'error', summary: 'Value force error', detail: error.message });
});
}
}
forceCommand(){
const value = this.getSignalType();
this.twinpadApiService.sendSignalForcedValue(this.signal, value).subscribe(_ => {
this.messageService.add({severity: 'success', summary: 'Value forced', detail: this.signal.signal_id+' sent forced command '+value });
},
error => {
console.log(error);
this.messageService.add({severity: 'error', summary: 'Command force error', detail: error.message });
});
}
getSignalType(){
let signalDataType = this.signal.data_type;
Eif (this.signal.isEnum()){
signalDataType = this.signal.enumType();
}
Iif (signalDataType === "bool"){
return this.boolValue;
}
else Eif (signalDataType === "str"){
return this.stringValue;
}
else if (signalDataType === "epoch"){
return this.dateValue.getTime() / 1000;
}
return this.floatValue;
}
}
|