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 59faa9c
Show file tree
Hide file tree
Showing 4 changed files with 46,609 additions and 8,727 deletions.
4 changes: 3 additions & 1 deletion 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 Down
9 changes: 6 additions & 3 deletions client/src/pages/Params/Param/Normal.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ 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
Expand All @@ -57,7 +57,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
82 changes: 62 additions & 20 deletions client/src/pages/Params/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,24 @@ 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")
console.log(Object.entries(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,16 +59,28 @@ const Params = () => {
const [parameters, setParameters] = useState(INITIAL_PARAMS)
const [parametersSave, setParametersSave] = useState(INITIAL_PARAMS.slice())

const [filter, setFilter] = useState("")
const parametersDisplay = useMemo(() => {
if (filter === "") {
return [...Array(INITIAL_PARAMS.length).keys()]
const isEnabled = (param) => {
if (param == undefined) {
console.log(param)
return
}
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(() => {
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.includes(filter) || param.description?.includes(filter)))) {
dispMap.push(index)
}
}
Expand All @@ -79,8 +99,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 +134,7 @@ const Params = () => {
}

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

return (
Expand All @@ -113,7 +155,7 @@ const Params = () => {
<Button
title="Get params from server file"
onClick={() => {
fetch("/uav/params/getall")
get()
}}
>
Get
Expand All @@ -135,7 +177,7 @@ const Params = () => {
<Button
title="Load params from plane"
onClick={() => {
fetch("/uav/params/load")
load()
}}
>
Load
Expand Down Expand Up @@ -177,7 +219,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 59faa9c

Please sign in to comment.