= {
name: this.selectedDevice.name,
position: this.selectedDevice.position,
orientation: this.selectedDevice.orientation,
};
elements.forEach(element => {
const inputElement = element as HTMLInputElement;
if (inputElement.id === 'editName') {
obj.name = inputElement.value;
} else if (inputElement.id.startsWith('editPos')) {
if (!Number.isNaN(Number(inputElement.value))) {
obj.position[inputElement.id.slice(7).toLowerCase()] =
DeviceInformation.checkPositionBound(
Number(inputElement.value) / 100);
}
} else if (inputElement.id.startsWith('editOri')) {
if (!Number.isNaN(Number(inputElement.value))) {
obj.orientation[inputElement.id.slice(7).toLowerCase()] =
DeviceInformation.checkOrientationBound(
Number(inputElement.value));
}
}
});
this.selectedDevice.name = obj.name;
this.selectedDevice.position = obj.position;
this.selectedDevice.orientation = obj.orientation;
this.handleEditForm();
simulationState.patchDevice({
device: obj,
});
}
private handleGetBleBeacon(ble_beacon: Chip_BleBeacon) {
const handleGetSettings = () => {
if (!ble_beacon.settings) {
return html``;
}
return html`
Settings
${
ble_beacon.settings.advertiseMode ?
html`
Advertise Mode:
${ble_beacon.settings.advertiseMode?.replace('-', ' ')}
` :
html`
Advertise Interval:
${ble_beacon.settings.milliseconds?.toString().concat(' ms')}
`}
${
ble_beacon.settings.txPowerLevel ?
html`
Transmit Power Level:
${ble_beacon.settings.txPowerLevel?.replace('-', ' ')}
` :
html`
Transmit Power:
${ble_beacon.settings.dbm?.toString().concat(' dBm')}
`}
Scannable:
${ble_beacon.settings.scannable}
Timeout:
${ble_beacon.settings.timeout?.toString().concat(' ms')}
`;
};
const handleGetAdvData = () => {
if (!ble_beacon.advData) {
return html``;
}
return html`
Advertise Data
Include Device Name:
${ble_beacon.advData.includeDeviceName}
Include Transmit Power:
${ble_beacon.advData.includeTxPowerLevel}
${
ble_beacon.advData.manufacturerData.length ?
html`
Manufacturer Data Length:
${ble_beacon.advData.manufacturerData.length}
` :
html``}
${
ble_beacon.advData.services.length ?
html`
Number of Supported Services:
${ble_beacon.advData.services.length}
` :
html``}
`;
};
return html`${handleGetSettings()} ${handleGetAdvData()}`;
}
private getRadioCheckbox = (radio: Chip_Radio, id: string) => {
return html` `;
};
private getBluetoothRadioCheckboxes(bt: Chip_Bluetooth) {
let lowEnergyCheckbox = undefined;
let classicCheckbox = undefined;
if ('lowEnergy' in bt && bt.lowEnergy) {
lowEnergyCheckbox = this.getRadioCheckbox(bt.lowEnergy, 'lowEnergy');
}
if ('classic' in bt && bt.classic) {
classicCheckbox = this.getRadioCheckbox(bt.classic, 'classic');
}
return [lowEnergyCheckbox, classicCheckbox];
}
private handleGetChip(chip: Chip, idx: number) {
if (chip.bleBeacon) {
let checkboxes: {[name: string]: undefined|TemplateResult} = {};
if (chip.bleBeacon.bt) {
[checkboxes['Bluetooth LE'], checkboxes['Bluetooth Classic']] =
this.getBluetoothRadioCheckboxes(chip.bleBeacon.bt);
}
return html`
Chip ${idx + 1}: ${chip.kind.replace('_', ' ')}
${
Object.entries(checkboxes).length ?
html`
Radios
` :
html``}
${
Object.entries(checkboxes)
.map(([name, template]) => html`
${name}
${template}
`)}
${this.handleGetBleBeacon(chip.bleBeacon)}`;
} else {
return ``;
}
}
private handleGetChips() {
if (!(this.selectedDevice && this.selectedDevice.chips)) {
return html``;
}
const isBuiltin = (chip: Chip) =>
chip.kind === ChipKind.BLUETOOTH_BEACON && chip.bleBeacon;
// If any chip is a builtin, display individual chip information
if (this.selectedDevice.chips.some(chip => isBuiltin(chip))) {
return html`${
this.selectedDevice.chips.map(
(chip, idx) => this.handleGetChip(chip, idx))}`;
}
// Otherwise, just display the radios
let checkboxes: {[name: string]: undefined|TemplateResult} = {};
for (const chip of this.selectedDevice.chips) {
if (chip) {
if (chip.bt) {
[checkboxes['Bluetooth LE'], checkboxes['Bluetooth Classic']] =
this.getBluetoothRadioCheckboxes(chip.bt);
}
if (chip.wifi) {
checkboxes['WIFI'] = this.getRadioCheckbox(chip.wifi, 'wifi');
}
if (chip.uwb) {
checkboxes['UWB'] = this.getRadioCheckbox(chip.uwb, 'uwb');
}
}
}
if (Object.keys(checkboxes).length) {
return html`
Radios
${
Object.entries(checkboxes)
.map(([name, template]) => html`
${name}
${template}
`)}
`;
} else {
return html``;
}
}
render() {
return html`${
this.selectedDevice ?
html`
Device Info
Name
${this.selectedDevice.name}
Orientation
Yaw
Pitch
Roll
${
this.editMode ? html`
` :
html``}
${this.handleGetChips()}
` :
html`Device Info
`}`;
}
}