Skip to content

Commit

Permalink
Param page with new format
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzalemon committed Sep 1, 2023
1 parent 41c5a46 commit eb55b2e
Show file tree
Hide file tree
Showing 4 changed files with 46,607 additions and 8,729 deletions.
6 changes: 4 additions & 2 deletions client/src/pages/Params/Param/Active.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ const Active = ({ listRef, style, height, data, index, setActiveIndex, setModifi
</Row>
</div>
<Column style={{ display: "flex", height: "96%" }}>
<Content padded children={data.description} />
<Content>
<b>{data.DisplayName}</b>{data.DisplayName ? ". " : ""}{data.Description}
</Content>
</Column>
<aside
style={{
Expand All @@ -48,7 +50,7 @@ const Active = ({ listRef, style, height, data, index, setActiveIndex, setModifi
...data,
value,
}
setParameters(params)
setParameters(params.slice())
setModifiedIndexes(prev => {
if (!prev.includes(index)) return [...prev, index]
else return prev
Expand Down
10 changes: 6 additions & 4 deletions client/src/pages/Params/Param/Normal.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,20 @@ const Normal = ({ listRef, style, height, data, index, setActiveIndex, setModifi
{modified ? (
<Value
style={{ color: modified ? blue : "inherit" }}
hook={[data.old.value, null]}
hook={[data.old, null]}
/>
) : null}
</Row>
</Column>
<Column height="2rem">
<Description description={data.description.replace(/\s/g, "\u00A0")} />
<Description DisplayName={data.DisplayName} description={data.Description} />
</Column>
{modified ? (
<Submit
type="decline"
callback={() => {
setModifiedIndexes(prev => prev.filter(i => i !== index))
parameters[index] = parametersSave[index]
setParameters(parameters)
}}
/>
) : (
Expand All @@ -57,7 +56,10 @@ const Normal = ({ listRef, style, height, data, index, setActiveIndex, setModifi

const Description = styled(Content).attrs(props => ({
padded: true,
children: props.description,
children:
<>
<b>{props.DisplayName}</b>{props.DisplayName ? ". " : ""}{props.description}
</>,
}))`
white-space: nowrap;
position: relative;
Expand Down
79 changes: 59 additions & 20 deletions client/src/pages/Params/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,23 @@ TODO: Read params from mavlink
TODO: Write params to mavlink
*/

const INITIAL_PARAMS = Object.entries(require("parameters.json")).map(
([name, { description, link }]) => ({
name,
description,
link,
value: "0",
})
)
var INITIAL_PARAMS = []
var enables = {}
let json = require("parameters.json")
Object.entries(json).forEach((entry) => {
if (entry[0] == "")
return

let paramToIndex = {}
for (let param in entry[1]) {
if (param.includes("_ENABLE")) {
enables[entry[0]] = param
}
let a = { ...entry[1][param], name: param, value: 0 }
INITIAL_PARAMS.push(a)
}
})

var paramToIndex = {}
INITIAL_PARAMS.forEach((val, i) => {
paramToIndex[val.name] = i
})
Expand All @@ -51,22 +58,32 @@ const Params = () => {
const [parameters, setParameters] = useState(INITIAL_PARAMS)
const [parametersSave, setParametersSave] = useState(INITIAL_PARAMS.slice())

const isEnabled = (param) => {
if (param.includes("_ENABLE")) {
return true
}
for (let e in enables) {
if (param.indexOf(e) == 0) {
return parameters[paramToIndex[enables[e]]].value == 1.0
}
}
return true
}

const [filter, setFilter] = useState("")
const parametersDisplay = useMemo(() => {
if (filter === "") {
return [...Array(INITIAL_PARAMS.length).keys()]
}
setFilter(filter.toLowerCase())

let dispMap = []
for (let index in parameters) {
let param = parameters[index]
if (param.name.includes(filter) || param.description.includes(filter)) {
if ((filter === "" && param.name.includes("_ENABLE")) || (isEnabled(param.name) && (param.name.toLowerCase().includes(filter) || param.description?.toLowerCase().includes(filter)))) {
dispMap.push(index)
}
}

return dispMap
}, [filter])
}, [filter, parameters])

const inputBox = useRef(null)
const listRef = useRef(null)
Expand All @@ -79,8 +96,30 @@ const Params = () => {
setModifiedIndexes([])
}

const fetch = (url) => {
httpget(url, response => {
const get = () => {
httpget("/uav/params/getall", response => {
let data = response.data.result
let missingParams = []
for (let param in data) {
if (paramToIndex[param] != undefined) {
parameters[paramToIndex[param]].value = data[param]
} else {
missingParams.push({ name: param, value: data[param], Description: "N/A" })
}
}
missingParams.forEach((val, i) => {
parameters.push(val)
paramToIndex[val.name] = i
})

setParameters(parameters)
setParametersSave(parameters.slice())
})
revertParameters()
}

const load = () => {
httppost("/uav/params/load", null, response => {
let data = response.data.result
for (let param in data) {
parameters[paramToIndex[param]].value = data[param]
Expand All @@ -92,7 +131,7 @@ const Params = () => {
}

useEffect(() => {
fetch("/uav/params/getall")
get()
}, [])

return (
Expand All @@ -113,7 +152,7 @@ const Params = () => {
<Button
title="Get params from server file"
onClick={() => {
fetch("/uav/params/getall")
get()
}}
>
Get
Expand All @@ -135,7 +174,7 @@ const Params = () => {
<Button
title="Load params from plane"
onClick={() => {
fetch("/uav/params/load")
load()
}}
>
Load
Expand Down Expand Up @@ -177,7 +216,7 @@ const Params = () => {
<Param
key={index}
index={mIndex}
data={{ ...parameters[mIndex], old: parametersSave[mIndex] }}
data={{ ...parameters[mIndex], old: parametersSave[mIndex].value }}
active={false}
setActiveIndex={setActiveIndex}
setModifiedIndexes={setModifiedIndexes}
Expand Down
Loading

0 comments on commit eb55b2e

Please sign in to comment.