Update tool for generic input too
This commit is contained in:
parent
b442fc7bb8
commit
e6a8a16db4
2 changed files with 52 additions and 32 deletions
|
|
@ -159,24 +159,38 @@ def convert_components_to_json():
|
|||
|
||||
# Handle UART-specific properties
|
||||
if category == "uart":
|
||||
device_type = component_data.get("deviceType")
|
||||
if device_type == "generic_input":
|
||||
# Required properties
|
||||
component_info["device_type"] = component_data.get("deviceType")
|
||||
component_info["deviceId"] = component_data.get("deviceId")
|
||||
# Specific device_type properties
|
||||
if component_info["device_type"] == "generic_input":
|
||||
# Parse generic input properties
|
||||
component_info["period"] = component_data["generic_input"].get("period", 30000) # Default to 30s if not specified
|
||||
# Extract data types
|
||||
if "generic_input" in component_data and "sensor_types" in component_data["generic_input"]:
|
||||
for meas_type in component_data["generic_input"]["sensor_types"]:
|
||||
if isinstance(meas_type, dict) and "sensorType" in meas_type:
|
||||
component_info["dataTypes"].append({
|
||||
"displayName": meas_type["displayName"] if "displayName" in meas_type else meas_type["sensorType"],
|
||||
"sensorType": map_datatypes_to_offline_types(meas_type["sensorType"]) if "sensorType" in meas_type else None
|
||||
})
|
||||
else:
|
||||
component_info["dataTypes"].append(map_datatypes_to_offline_types(meas_type))
|
||||
|
||||
elif component_info["device_type"] == "generic_output":
|
||||
# TODO
|
||||
pass
|
||||
elif device_type == "generic_output":
|
||||
elif component_info["device_type"] == "gps":
|
||||
# TODO
|
||||
pass
|
||||
elif device_type == "gps":
|
||||
# TODO
|
||||
pass
|
||||
elif device_type == "pm25aqi":
|
||||
# Get pm25aqi specific data
|
||||
pm25aqi_data = component_data
|
||||
elif component_info["device_type"] == "pm25aqi":
|
||||
# Parse PM2.5 AQI properties
|
||||
if "pm25aqi" in component_data:
|
||||
component_info["period"] = component_data["pm25aqi"].get("period", 30000) # Default to 30s if not specified
|
||||
if component_data["pm25aqi"].get("is_pm1006", False):
|
||||
component_info["is_pm1006"] = True
|
||||
# Extract data types
|
||||
pm25aqi_data = component_data
|
||||
if "pm25aqi" in pm25aqi_data and "sensor_types" in pm25aqi_data["pm25aqi"]:
|
||||
for meas_type in pm25aqi_data["pm25aqi"]["sensor_types"]:
|
||||
if isinstance(meas_type, dict) and "sensorType" in meas_type:
|
||||
|
|
|
|||
|
|
@ -1650,19 +1650,19 @@ function saveModalData() {
|
|||
// Mark pin as used
|
||||
appState.usedPins.add(parseInt(pin));
|
||||
} else if (componentType === 'uart') {
|
||||
const txPin = document.getElementById('modal-uart-tx').value;
|
||||
const rxPin = document.getElementById('modal-uart-rx').value;
|
||||
if (!rxPin) {
|
||||
const pinTx = document.getElementById('modal-uart-tx').value;
|
||||
const pinRx = document.getElementById('modal-uart-rx').value;
|
||||
if (!pinRx) {
|
||||
validationError = true;
|
||||
alert('Please select a RX pin for the component.');
|
||||
return false;
|
||||
}
|
||||
if (!!txPin) {
|
||||
componentConfig.txPin = `D${txPin}`;
|
||||
appState.usedPins.add(parseInt(txPin));
|
||||
if (!!pinTx) {
|
||||
componentConfig.pinTx = `D${pinTx}`;
|
||||
appState.usedPins.add(parseInt(pinTx));
|
||||
}
|
||||
componentConfig.rxPin = `D${rxPin}`;
|
||||
appState.usedPins.add(parseInt(rxPin));
|
||||
componentConfig.pinRx = `D${pinRx}`;
|
||||
appState.usedPins.add(parseInt(pinRx));
|
||||
|
||||
// Add data types
|
||||
const dataTypeCheckboxes = document.querySelectorAll('input[name="data-type"]:checked');
|
||||
|
|
@ -1676,9 +1676,15 @@ function saveModalData() {
|
|||
});
|
||||
}
|
||||
|
||||
// UART-Specific //
|
||||
// Add is_pm1006 field if it exists in the component template
|
||||
if (componentTemplate.is_pm1006) {
|
||||
componentConfig.is_pm1006 = componentTemplate.is_pm1006;
|
||||
if (componentTemplate.device_type) {
|
||||
componentConfig.device_type = componentTemplate.device_type;
|
||||
}
|
||||
|
||||
// Add deviceId field if it exists in the component template
|
||||
if (componentTemplate.deviceId) {
|
||||
componentConfig.deviceId = componentTemplate.deviceId;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1763,7 +1769,7 @@ function updateSelectedComponentsList() {
|
|||
detailsText += `<br>Pin: ${component.pinName}`;
|
||||
detailsText += `<br>Pixels: ${component.numPixels}`;
|
||||
} else if (component.componentAPI === 'uart') {
|
||||
detailsText += `<br>TX Pin: ${component.txPin}, RX Pin: ${component.rxPin}`;
|
||||
detailsText += `<br>TX Pin: ${component.pinTx}, RX Pin: ${component.pinRx}`;
|
||||
|
||||
// Show sensor types
|
||||
if (component.sensorTypes && component.sensorTypes.length > 0) {
|
||||
|
|
@ -1815,14 +1821,14 @@ function removeComponent(instanceId) {
|
|||
appState.usedPins.delete(pinNumber);
|
||||
}
|
||||
|
||||
if (component.txPin) {
|
||||
const txPinNumber = parseInt(component.txPin.replace('D', ''));
|
||||
appState.usedPins.delete(txPinNumber);
|
||||
if (component.pinTx) {
|
||||
const pinTxNumber = parseInt(component.pinTx.replace('D', ''));
|
||||
appState.usedPins.delete(pinTxNumber);
|
||||
}
|
||||
|
||||
if (component.rxPin) {
|
||||
const rxPinNumber = parseInt(component.rxPin.replace('D', ''));
|
||||
appState.usedPins.delete(rxPinNumber);
|
||||
if (component.pinRx) {
|
||||
const pinRxNumber = parseInt(component.pinRx.replace('D', ''));
|
||||
appState.usedPins.delete(pinRxNumber);
|
||||
}
|
||||
|
||||
// Check if this is a multiplexer and remove it from the multiplexers list
|
||||
|
|
@ -2295,14 +2301,14 @@ function importConfigObject(config) {
|
|||
appState.usedPins.add(pinNumber);
|
||||
}
|
||||
|
||||
if (component.txPin) {
|
||||
const txPinNumber = parseInt(component.txPin.replace('D', ''));
|
||||
appState.usedPins.add(txPinNumber);
|
||||
if (component.pinTx) {
|
||||
const pinTxNumber = parseInt(component.pinTx.replace('D', ''));
|
||||
appState.usedPins.add(pinTxNumber);
|
||||
}
|
||||
|
||||
if (component.rxPin) {
|
||||
const rxPinNumber = parseInt(component.rxPin.replace('D', ''));
|
||||
appState.usedPins.add(rxPinNumber);
|
||||
if (component.pinRx) {
|
||||
const pinRxNumber = parseInt(component.pinRx.replace('D', ''));
|
||||
appState.usedPins.add(pinRxNumber);
|
||||
}
|
||||
|
||||
// Handle I2C bus pins
|
||||
|
|
|
|||
Loading…
Reference in a new issue