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

Change Pressure Sensor Reading Color Based on Boundary! #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 10 additions & 5 deletions client/src/components/Data.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React from "react";
import { StatsState } from "../store/reducers/stats";
import { useSelector } from "react-redux";
import getColor from "../lib/getColor";
import sensorColor from "../lib/getColor";
import stylizeName from "../lib/camelize";
import { CaelusState } from "../store/reducers";

import Block from "./Block";
import BlockHeader from "./BlockHeader";
import PandidBoxed from "../images/pandidboxed.png";
import NitrousPID from "../images/nitrouspid.png";

const VALVE_MAP = {
1: "OPEN",
Expand Down Expand Up @@ -62,9 +64,12 @@ const Data = () => {
? []
: [["", state.data.general.heartbeat_status]],
mode: state.data.general.mode,
Stage: state.data.general.stage,
};
});



const blockStyle = "rounded-lg m-1 p-4 bg-gray-100";
const abortStyle = "animate-ping rounded-lg m-1 p-4 bg-pink-300";
const groupHeaderStyle = "font-bold mb-1";
Expand All @@ -89,9 +94,9 @@ const Data = () => {
className="flexFont"
>
<img
src={PandidBoxed}
id="pandidboxed"
alt="pandidboxed"
src={NitrousPID}
id="nitrouspid"
alt="nitrouspid"
style={{ width: "100%" }}
/>
{Object.entries(SENSOR_TEXT_PADDING).map(([sensor, padding]) => (
Expand Down Expand Up @@ -143,7 +148,7 @@ const Data = () => {
<p
style={{
color:
"green" /*getColor(data.sensorState[sensor][loc])*/,
sensorColor(data.sensorState.sensors[type][locations], data.Stage),
}}
key={type + "." + loc}
>
Expand Down
8 changes: 4 additions & 4 deletions client/src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,22 +206,22 @@
"safe": [100, 500],
"warn": [50, 550],
"critical": [0, 600],
"waiting": {
"waiting": {
"safe": [100, 500],
"warn": [50, 550],
"critical": [0, 600]
},
"pressurization": {
"pressurization": {
"safe": [100, 500],
"warn": [50, 550],
"critical": [0, 600]
},
"autosequence": {
"autosequence": {
"safe": [100, 500],
"warn": [50, 550],
"critical": [0, 600]
},
"postburn": {
"postburn": {
"safe": [100, 500],
"warn": [50, 550],
"critical": [0, 600]
Expand Down
16 changes: 16 additions & 0 deletions client/src/lib/getColor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import caelusLogger from "./caelusLogger";
import stats from "../store/reducers/stats";
import config from "../config.json";

const getColor = (status: any) => {
if (status.length === 0) {
Expand All @@ -17,4 +19,18 @@ const getColor = (status: any) => {
}
};

const sensorColor = (sensor, stage) => {
var measure = sensor.measured;
var stages = config.sensors.list.pressure.sensor.boundaries.stage;

if (measure >= stages.safe[0] && measure <= stages.safe[1]) return "green";
else if (measure >= stages.warn[0] && measure <= stages.warn[1]) return "orange";
else if (measure >= stages.critical[0] && measure <= stages.critical[1]) return "red";

//go into state and find the sensor
//based on stage, check if value is in safe, warn, or critical

};

export default getColor;
export default sensorColor;