Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add comms to config page and small code refactor #153

Merged
merged 3 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 15 additions & 38 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (

goapi "github.com/TheCacophonyProject/go-api"
goconfig "github.com/TheCacophonyProject/go-config"
"github.com/TheCacophonyProject/lepton3"
signalstrength "github.com/TheCacophonyProject/management-interface/signal-strength"
saltrequester "github.com/TheCacophonyProject/salt-updater"
"github.com/godbus/dbus"
Expand Down Expand Up @@ -399,10 +398,12 @@ func (api *ManagementAPI) SetConfig(w http.ResponseWriter, r *http.Request) {
newConfigRaw := r.FormValue("config")
newConfig := map[string]interface{}{}
if err := json.Unmarshal([]byte(newConfigRaw), &newConfig); err != nil {
log.Printf("Error with unmarshal: %s", err)
badRequest(&w, err)
return
}
if err := api.config.SetFromMap(section, newConfig, false); err != nil {
log.Printf("Error with SetFromMap: %s", err)
badRequest(&w, err)
return
}
Expand All @@ -416,50 +417,26 @@ func (api *ManagementAPI) GetConfig(w http.ResponseWriter, r *http.Request) {
return
}

configDefaults := map[string]interface{}{
goconfig.AudioRecordingKey: goconfig.DefaultAudioRecording(),
goconfig.AudioBaitKey: goconfig.DefaultAudioBait(),
goconfig.GPIOKey: goconfig.DefaultGPIO(),
goconfig.LeptonKey: goconfig.DefaultLepton(),
goconfig.ModemdKey: goconfig.DefaultModemd(),
goconfig.PortsKey: goconfig.DefaultPorts(),
goconfig.TestHostsKey: goconfig.DefaultTestHosts(),
goconfig.ThermalMotionKey: goconfig.DefaultThermalMotion(lepton3.Model35), // TODO don't assume that model 3.5 is being used
goconfig.ThermalRecorderKey: goconfig.DefaultThermalRecorder(),
goconfig.ThermalThrottlerKey: goconfig.DefaultThermalThrottler(),
goconfig.WindowsKey: goconfig.DefaultWindows(),
}

configValues := map[string]interface{}{
goconfig.AudioRecordingKey: &goconfig.AudioRecording{},
goconfig.AudioBaitKey: &goconfig.AudioBait{},
goconfig.GPIOKey: &goconfig.GPIO{},
goconfig.LeptonKey: &goconfig.Lepton{},
goconfig.ModemdKey: &goconfig.Modemd{},
goconfig.PortsKey: &goconfig.Ports{},
goconfig.TestHostsKey: &goconfig.TestHosts{},
goconfig.ThermalMotionKey: &goconfig.ThermalMotion{},
goconfig.ThermalRecorderKey: &goconfig.ThermalRecorder{},
goconfig.ThermalThrottlerKey: &goconfig.ThermalThrottler{},
goconfig.WindowsKey: &goconfig.Windows{},
}

for section, sectionStruct := range configValues {
if err := api.config.Unmarshal(section, sectionStruct); err != nil {
serverError(&w, err)
return
}
defaultValues := map[string]interface{}{}
for k, v := range goconfig.GetDefaults() {
defaultValues[toCamelCase(k)] = v
}

values, err := api.config.GetAllValues()
if err != nil {
serverError(&w, err)
return
}

configValuesCC := map[string]interface{}{}
for k, v := range configValues {
for k, v := range values {
configValuesCC[toCamelCase(k)] = v
}
configValues = configValuesCC
values = configValuesCC

valuesAndDefaults := map[string]interface{}{
"values": configValues,
"defaults": configDefaults,
"values": values,
"defaults": defaultValues,
}

jsonString, err := json.Marshal(valuesAndDefaults)
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.22.3
require (
github.com/TheCacophonyProject/audiobait/v3 v3.0.1
github.com/TheCacophonyProject/event-reporter v1.3.2-0.20200210010421-ca3fcb76a231
github.com/TheCacophonyProject/go-api v1.2.0
github.com/TheCacophonyProject/go-config v1.18.0
github.com/TheCacophonyProject/go-api v1.2.1
github.com/TheCacophonyProject/go-config v1.22.0
github.com/TheCacophonyProject/go-cptv v0.0.0-20211109233846-8c32a5d161f7
github.com/TheCacophonyProject/lepton3 v0.0.0-20211005194419-22311c15d6ee
github.com/TheCacophonyProject/rtc-utils v1.2.0
Expand All @@ -30,7 +30,7 @@ require (
)

require (
github.com/TheCacophonyProject/event-reporter/v3 v3.7.0 // indirect
github.com/TheCacophonyProject/event-reporter/v3 v3.8.0 // indirect
github.com/TheCacophonyProject/window v0.0.0-20200312071457-7fc8799fdce7 // indirect
github.com/alexflint/go-scalar v1.1.0 // indirect
github.com/boltdb/bolt v1.3.1 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ github.com/TheCacophonyProject/audiobait/v3 v3.0.1/go.mod h1:EDM0fyF6oHPUmtOfY4Q
github.com/TheCacophonyProject/event-reporter v1.3.2-0.20200210010421-ca3fcb76a231 h1:nLqfSx3zDBzghlP/S8X2j/WRtW0e3BZvSkMm1J/Fa8U=
github.com/TheCacophonyProject/event-reporter v1.3.2-0.20200210010421-ca3fcb76a231/go.mod h1:kei6S/4x+VHp5yiwYPqvcNnhuRpZ8iLsh95Sue6kPvc=
github.com/TheCacophonyProject/event-reporter/v3 v3.3.0/go.mod h1:dGIYfhABsJHKjcsxtftDwpdcfLOWTYKeIyCYxCOIMrc=
github.com/TheCacophonyProject/event-reporter/v3 v3.7.0 h1:B+a5PXqBh7Bkf2HDo+j94Ascqw6SCTlOhSN9TXZfjY8=
github.com/TheCacophonyProject/event-reporter/v3 v3.7.0/go.mod h1:WTppJtTBxduasM1Or5SAh4Mm0YrTDnprOChjnGYgyEI=
github.com/TheCacophonyProject/event-reporter/v3 v3.8.0 h1:FYNR+MX5ypyG7UWpogDnDqsTV+23WS1sIr9o6rhjf/8=
github.com/TheCacophonyProject/event-reporter/v3 v3.8.0/go.mod h1:WTppJtTBxduasM1Or5SAh4Mm0YrTDnprOChjnGYgyEI=
github.com/TheCacophonyProject/go-api v0.0.0-20190923033957-174cea2ac81c/go.mod h1:FfMpa4cFhNXQ9tuKG18HO6yLExezcJhzjUjBOFocrQw=
github.com/TheCacophonyProject/go-api v1.0.4/go.mod h1:F7UUNgsLhbw7hsiNBMRB9kQz9uXXosVmNToqImz7EA8=
github.com/TheCacophonyProject/go-api v1.2.0 h1:5cEUlv3Xe8T4SuLmIPK2ppkPt/Mi41OSvp/vCPPUxuY=
github.com/TheCacophonyProject/go-api v1.2.0/go.mod h1:F7UUNgsLhbw7hsiNBMRB9kQz9uXXosVmNToqImz7EA8=
github.com/TheCacophonyProject/go-api v1.2.1 h1:QS8mzStQHzb3oAqqwjoLqCvXsRM8fx7F9I7hpgKND5c=
github.com/TheCacophonyProject/go-api v1.2.1/go.mod h1:F7UUNgsLhbw7hsiNBMRB9kQz9uXXosVmNToqImz7EA8=
github.com/TheCacophonyProject/go-config v0.0.0-20190922224052-7c2a21bc6b88/go.mod h1:gPUJLVu408NRz9/P3BrsxzOzLc+KJLrv+jVdDw3RI0Y=
github.com/TheCacophonyProject/go-config v0.0.0-20190927054511-c93578ae648a/go.mod h1:QCgT+KCrz1CmLVpeeOMl5L8/X1QvWwpsLzR7afTmEJc=
github.com/TheCacophonyProject/go-config v1.4.0/go.mod h1:oARW/N3eJbcewCqB+Jc7TBwuODawwYgpo56UO6yBdKU=
github.com/TheCacophonyProject/go-config v1.6.4/go.mod h1:eDQfBjmTDh/l+2QLBgsotmJFd/1x/7w4SwwBUxMM86w=
github.com/TheCacophonyProject/go-config v1.9.0/go.mod h1:+y80PSRZudMYuVrYTGOvzc66NxVJWKS4TuU442vmvhY=
github.com/TheCacophonyProject/go-config v1.18.0 h1:R3zOjfHBxsI8t5J7PSuv6Wb5xwj2LPMC8vqD+d5Azd8=
github.com/TheCacophonyProject/go-config v1.18.0/go.mod h1:XZwQmNl2wQXhYR18RQtwZ6LwFwgAx73yzJfymYLz68s=
github.com/TheCacophonyProject/go-config v1.22.0 h1:ElKhWV4w0m4xX59h6ORrSDsAkBsAScJskrouCjKchqY=
github.com/TheCacophonyProject/go-config v1.22.0/go.mod h1:Nf1iBI/gqYf7UCcUZezO7bj9hzY2jRPdzDW+kOI9/Fo=
github.com/TheCacophonyProject/go-cptv v0.0.0-20200116020937-858bd8b71512/go.mod h1:8H6Aaft5549sIWxcsuCIL2o60/TQkoF93fVoSTpgZb8=
github.com/TheCacophonyProject/go-cptv v0.0.0-20200616224711-fc633122087a/go.mod h1:Vg73Ezn4kr8qDNP9LNgjki9qgi+5T/0Uc9oDyflaYUY=
github.com/TheCacophonyProject/go-cptv v0.0.0-20200818214604-bd5d4aa36043/go.mod h1:wG4/P/TsGtk33uBClYPjRlSbcdQrIASXutOUV8LMn2o=
Expand Down
2 changes: 1 addition & 1 deletion html/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ <h3>Device<br></h3>
</div>
<div class="row">
<p class="col-2 text-left">Previous Output:</p>
<p id="previous-output" class="col-9 monospace"></p>
<pre id="previous-output" class="col-9 monospace"></pre>
</div>
<div class="row">
<p class="col-2 text-left">Previous Success:</p>
Expand Down
80 changes: 80 additions & 0 deletions html/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,87 @@ <h3>Thermal Motion<br></h3>
<div class="container pt-1 pl-0">
<button id="save-button" type="button" onclick="saveThermalMotionConfig()" class="btn btn-primary">Save ThermalMotion Config</button>
</div>

<div class="container pt-5 pl-0">
<h3>Comms port<br></h3>
</div>

<div class="row">
<div class="col-xs-8">
<div class="table-responsive">
<table class="table">
<tbody>
<tr>
<td>Enable</td>
<td><input type="checkbox" id="input-comms-enable"></td>
</tr>
<tr></tr>
<td>Trap Default State</td>
<td><input type="checkbox" id="input-comms-trap-default"></td>
</tr>

<tr>
<td>Bluetooth Enablued</td>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*Bluetooth Enabled
though kind of funny to leave as EnaBLUEd

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, should probably fix it..

<td><input type="checkbox" id="input-comms-bluetooth"></td>
</tr>

<tr>
<td>Power Output</td>
<td>
<div id="comms-type">
<select class="form-select" id="input-comms-power-output">
<option selected>Select Power Output type</option>
<option>on</option>
<option>off</option>
<option>comms-only</option>
</select>
</div>
</td>
</tr>

<tr>
<td>Power On Duration</td>
<td><input type="text" id="input-comms-power-up-duration"></td>
</tr>

<tr>
<td>Comms Type</td>
<td>
<div id="comms-type">
<select class="form-select" id="input-comms-type-select">
<option selected>Select Comms type</option>
<option>simple</option>
<option>uart</option>
</select>
</div>
</td>
</tr>
<tr>
<td>Trap Species</td>
<td><input type="text" id="input-comms-trap-species"></td>
</tr>
<tr>
<td>Trap Duration</td>
<td><input type="text" id="input-comms-trap-duration"></td>
</tr>
<tr>
<td>Protect Species</td>
<td><input type="text" id="input-comms-protect-species"></td>
</tr>
<tr>
<td>Protect Species</td>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*Protect Duration

<td><input type="text" id="input-comms-protect-duration"></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>

<div class="container pt-1 pl-0">
<button id="save-button" type="button" onclick="saveCommsConfig()" class="btn btn-primary">Save Comms Config</button>
</div>

</div>

<script src="/static/js/jquery-3.3.1.slim.min.js"></script>
Expand Down
Loading