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

Vector Battery Status #382

Merged
merged 44 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
1cb79d3
api-sdk get_battery proxy
AshMartian Sep 1, 2024
7eb10b6
Handle errors fetching intents
AshMartian Sep 1, 2024
7795837
Fix styling and catch ble network errors
AshMartian Sep 1, 2024
1cc6366
more ble error handling
AshMartian Sep 1, 2024
c2e884c
fix missing )
AshMartian Sep 1, 2024
6e4b301
Prepare for bot connection display
AshMartian Sep 1, 2024
a2e4477
initial commit of battery display on homepage
AshMartian Sep 1, 2024
93aadc7
correct post
AshMartian Sep 1, 2024
b704662
don't clear botStats
AshMartian Sep 1, 2024
5ed16d4
Update styling, fix bot settings page
AshMartian Sep 1, 2024
26f639d
x defined
AshMartian Sep 1, 2024
0dd3136
style cleanup
AshMartian Sep 1, 2024
fed6169
sdkapp settings
AshMartian Sep 1, 2024
3d24fa3
Make battery functions independent of homepage, calculate percentage …
AshMartian Sep 1, 2024
c222127
Display battery percentage in tooltip
AshMartian Sep 1, 2024
8a87113
Add battery info to settings page
AshMartian Sep 1, 2024
063d93b
more efficient battery polling
AshMartian Sep 1, 2024
54b50d0
fix battery bugs, ensure retrying happens if unable to get battery st…
AshMartian Sep 1, 2024
ecfac8c
battery server timeout
AshMartian Sep 1, 2024
2cec033
3.5v as 0%
AshMartian Sep 1, 2024
694f77b
Use ~ for battery display, and use log10 to estimate battery percentage
AshMartian Sep 1, 2024
781625d
intent graph logging
AshMartian Sep 1, 2024
401af5e
Update battery colors to reflect percentage
AshMartian Sep 1, 2024
d746a65
Don't cap percentage if charging
AshMartian Sep 1, 2024
fa5412b
Add charge time remaining seconds
AshMartian Sep 1, 2024
323157d
Charge status style update
AshMartian Sep 1, 2024
6d7e167
Charging status visual update
AshMartian Sep 1, 2024
5f602f2
Ensure battery bar fits within padding
AshMartian Sep 1, 2024
7041a02
Correct battery styling
AshMartian Sep 1, 2024
edfbf0e
More face gifs for future use
AshMartian Sep 1, 2024
b0a8691
round suggested charge time
AshMartian Sep 1, 2024
109e25e
Add home face
AshMartian Sep 1, 2024
94eb16c
png home face
AshMartian Sep 1, 2024
085f27f
Update face background size
AshMartian Sep 1, 2024
b4b23e4
Face size update
AshMartian Sep 1, 2024
ffd159b
Align battery and face better
AshMartian Sep 1, 2024
5016757
face refinements
AshMartian Sep 1, 2024
8b942f8
move tooltip down
AshMartian Sep 1, 2024
b5300bf
set to a regular face is fully charged
AshMartian Sep 1, 2024
92d370e
abort battery status after 15s
AshMartian Sep 1, 2024
69fb37a
4.1 max voltage
AshMartian Sep 1, 2024
b80d14a
red battery when needing to charge
AshMartian Sep 2, 2024
b10e6a4
hide botStats if there are no authed robots, return a formal HTTP err…
kercre123 Sep 2, 2024
5c22023
if get_battery's response doesn't return a voltage, assume 70 percent
kercre123 Sep 2, 2024
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
4 changes: 2 additions & 2 deletions chipper/pkg/servers/chipper/intent_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func (s *Server) StreamingIntentGraph(stream pb.ChipperGrpc_StreamingIntentGraph

req, err := stream.Recv()
if err != nil {
logger.Println("Intent graph error")
logger.Println("Intent graph stream error")
logger.Println(err)

return err
Expand All @@ -32,7 +32,7 @@ func (s *Server) StreamingIntentGraph(stream pb.ChipperGrpc_StreamingIntentGraph
// Mode:
},
); err != nil {
logger.Println("Intent graph error")
logger.Println("Intent graph processing error")
logger.Println(err)
return err
}
Expand Down
2 changes: 1 addition & 1 deletion chipper/pkg/wirepod/config-ws/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func apiHandler(w http.ResponseWriter, r *http.Request) {
handleGetVersionInfo(w)
case "generate_certs":
handleGenerateCerts(w)
case "is_api_v2":
case "is_api_v3":
fmt.Fprintf(w, "it is!")
default:
http.Error(w, "not found", http.StatusNotFound)
Expand Down
7 changes: 6 additions & 1 deletion chipper/pkg/wirepod/sdkapp/robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ func getRobot(serial string) (Robot, int, error) {
// if connection is inactive for more than 5 minutes, remove robot
// run this as a goroutine
func connTimer(ind int) {
// Check if the index is in the list
if len(robots) <= ind {
return
}

robots[ind].ConnTimer = 0
for {
time.Sleep(time.Second)
Expand All @@ -150,7 +155,7 @@ func connTimer(ind int) {
logger.Println("Closing SDK connection for " + robots[ind].ESN + ", source: connTimer")
removeRobot(robots[ind].ESN, "connTimer")
return
}
}
robots[ind].ConnTimer = robots[ind].ConnTimer + 1
}
}
Expand Down
23 changes: 23 additions & 0 deletions chipper/pkg/wirepod/sdkapp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sdkapp

import (
"bytes"
"context"
"encoding/json"
"fmt"
"image"
Expand Down Expand Up @@ -95,6 +96,10 @@ func SdkapiHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "done")
return
case r.URL.Path == "/api-sdk/get_sdk_info":
if len(vars.BotInfo.Robots) == 0 {
http.Error(w, "no bots are authenticated", http.StatusInternalServerError)
return
}
jsonBytes, err := json.Marshal(vars.BotInfo)
if err != nil {
fmt.Fprintf(w, "error marshaling json")
Expand Down Expand Up @@ -135,6 +140,24 @@ func SdkapiHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(json))
return
}
case r.URL.Path == "/api-sdk/get_battery":
// Ensure the endpoint times out after 15 seconds
ctx := r.Context() // Get the request context
ctx, cancel := context.WithTimeout(ctx, 15*time.Second)
defer cancel()

resp, err := robot.Conn.BatteryState(ctx, &vectorpb.BatteryStateRequest{})
if err != nil {
fmt.Fprint(w, "error: "+err.Error())
return
}
jsonBytes, err := json.Marshal(resp)
if err != nil {
fmt.Fprint(w, "error: "+err.Error())
return
}
fmt.Fprint(w, string(jsonBytes))
return
case r.URL.Path == "/api-sdk/time_format_12":
setSettingSDKintbool(robotObj, "clock_24_hour", "false")
fmt.Fprintf(w, "done")
Expand Down
Binary file added chipper/webroot/assets/cloudface.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chipper/webroot/assets/expandface.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chipper/webroot/assets/face.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chipper/webroot/assets/faceblank.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chipper/webroot/assets/faceblank.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chipper/webroot/assets/facefireworks.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chipper/webroot/assets/facegaze.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chipper/webroot/assets/homeface.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chipper/webroot/assets/webface.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chipper/webroot/assets/wififace.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
133 changes: 133 additions & 0 deletions chipper/webroot/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
--button-color: rgba(75,75,75,1); /* dark gray #4B4B4B */
--button-color-alt: rgba(164,164,164,1); /* light gray #A4A4A4 */
--fg-color: #00ff80; /* light green 33ED6D */
--medium-battery: #ced100; /* bright yellow */
--low-battery: #ff0000; /* bright red */
--fg-color-alt: rgba(51,237,109,.05); /* light green 33ED6D */
--text-color: rgba(255,255,255,1); /* white #FFFFFF */
--text-color-alt: rgba(34,34,34,1); /* black #000000 */
Expand Down Expand Up @@ -299,6 +301,10 @@ input[type='radio']:disabled:after {
border: 2px solid var(--fg-color); /* accent color */
}

#botAuth {
color: var(--text-color);
}

#content {
width: 950px !important;
/* word-break:break-all !important; */
Expand All @@ -313,6 +319,133 @@ input[type='radio']:disabled:after {
align-items: start;
}

#botStats {
width: 100%;
height: 50px;
display: flex;
justify-content: center;
align-items: center;
gap: 30px;
}

/* a simple gif loading from /assets/cloudface.gif and is 60x60px */
.botLoader {
background-image: url('/assets/cloudface.gif');
background-size: 60px 60px;
background-position: center;
background-clip: border-box;
background-repeat: no-repeat;
width: 60px;
height: 60px;
margin: 0 auto;
}

.batteryContainer {
display: flex;
justify-content: center;
align-items: center;
margin: 0 auto;
height: 60px;
padding-bottom: 15px;
gap: 15px;
cursor: pointer;
}

.batteryContainer:hover .tooltip {
display: block;
}

.tooltip {
position: absolute;
display: none;
background-color: var(--bg-color);
color: var(--text-color);
border-radius: 5px;
padding: 5px;
z-index: 1000;
margin-top: 145px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
}

.batteryOutline {
outline: 2px solid var(--text-color);
outline-offset: 2px;
border-radius: 5px;
width: 100px;
height: 40px;
position: relative;
}
.batteryOutline::before {
content: '';
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background-color: var(--button-color);
border-radius: 5px;
}
.batteryOutline::after {
content: '';
position: absolute;
top: 12px;
left: 102px;
width: 6px;
height: 18px;
background-color: var(--text-color);
}

.vectorFace {
height: 60px;
width: 60px;
background-position: center;
background-size: contain;
background-repeat: no-repeat;
}

.batteryLevel {
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background-color: var(--button-color-alt);
border-radius: 5px;
}

.battery0 {
background-color: var(--low-battery);
}

.battery1 {
background-color: var(--medium-battery);
}

.battery3, .battery2 {
background-color: var(--fg-color);
}

.charging {
position: absolute;
top: 0px;
left: 30px;
width: 40px;
height: 40px;
/* content is an svg of a lightning bolt */
content: url('data:image/svg+xml;utf8,<svg width="60" height="60" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 60"><polygon points="20,0 5,33 24,33 15,60 35,27 16,27" fill="white"/></svg>');
/* svg drop shadow */
filter: drop-shadow(0 0 4px rgba(0, 0, 0, 0.4));
}

.chargeTimeRemaining {
position: absolute;
bottom: 0px;
left: 3px;
font-size: 0.6em;
color: white;
text-shadow: 0 0 4px rgba(0, 0, 0, 1);
}

.main-nav-parent {
display: flex;
justify-content: center;
Expand Down
9 changes: 7 additions & 2 deletions chipper/webroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<div id="outer">
<div id="content" class="">
<h1>Wire-Pod</h1>
<!-- Bot stats, connected and battery -->
<div id="botStats"></div>
<hr />

<div class="main-nav-parent">
Expand Down Expand Up @@ -155,8 +157,8 @@ <h2>Log</h2>
</div>
</div>
<textarea id="botTranscriptedTextArea" rows="7" cols="50">
loading log...
</textarea>
loading log...
</textarea>
<hr class="log-hr" />
</div>

Expand Down Expand Up @@ -207,12 +209,15 @@ <h2>UI Customizer</h2>
<script src="./js/ble.js"></script>
<script src="./js/ssh.js"></script>
<script src="./js/ui.js"></script>
<script src="./sdkapp/js/common.js"></script>
<script src="./js/battery.js"></script>
<!-- <script src="./sdkapp/js/main.js"></script> -->
<script>
checkInited();
updateIntentSelection("editSelect");
updateIntentSelection("deleteSelect");
createIntentSelect("intentAddSelect");
processBotStats();
</script>

</html>
Loading
Loading