Skip to content

Commit 8356c26

Browse files
committed
Improve history views: remove warnings on console when collapsed, and remove limit
1 parent 0b7f2a3 commit 8356c26

8 files changed

Lines changed: 20 additions & 12 deletions

File tree

src/powermonitor.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ void APB::PowerMonitor::setup(Scheduler &scheduler) {
2828
if(d->status.initialised) {
2929
Log.infoln("Powermonitor initialised: INA219 with address 0x%x", APB_INA1219_ADDRESS);
3030

31+
32+
bool gainValid = d->ina219.setGain(APB_POWER_INA219_GAIN);
33+
bool voltageRangeValid = d->ina219.setBusVoltageRange(APB_POWER_INA219_VOLTAGE_RANGE);
3134
bool shuntValid = d->ina219.setMaxCurrentShunt(APB_POWER_MAX_CURRENT_AMPS, APB_POWER_SHUNT_OHMS);
3235

3336
Log.infoln("Powermonitor settings: valid=%d, %d milliamp max (%d amps), shunt resistor: %d milliohms",
34-
shuntValid,
37+
shuntValid && voltageRangeValid && gainValid,
3538
static_cast<int>(d->ina219.getMaxCurrent() * 1000.0),
3639
static_cast<int>(d->ina219.getMaxCurrent()),
3740
static_cast<int>(d->ina219.getShunt() * 1000.0)
@@ -42,6 +45,9 @@ void APB::PowerMonitor::setup(Scheduler &scheduler) {
4245
d->status.current = d->ina219.getCurrent();
4346
d->status.power = d->ina219.getPower();
4447
d->status.shuntVoltage = d->ina219.getShuntVoltage();
48+
if(d->status.power == 0 || d->status.current == 0) {
49+
Log.warningln("Powermonitor: Reporting power as 0. INA status: %d", d->ina219.isConnected());
50+
}
4551
});
4652
scheduler.addTask(d->loopTask);
4753
d->loopTask.enable();

web/src/features/app/api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fetchJson = async (path, init) => {
22
let url = path;
3-
console.log(process.env)
3+
// console.log(process.env)
44
if(process.env.NODE_ENV === 'development' && 'REACT_APP_ASTROPOWERBOX_API_HOST' in process.env) {
55
url = `${process.env.REACT_APP_ASTROPOWERBOX_API_HOST}${path}`;
66
}

web/src/features/sensors/ambient/Ambient.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const AmbientChart = ({}) => {
2929
}
3030
export const Ambient = () => {
3131
const { dewpoint, humidity, temperature } = useSelector(selectAmbient);
32+
const [historyVisible, setHistoryVisible] = useState(false);
3233
return <>
3334
<Table>
3435
<tbody>
@@ -49,8 +50,8 @@ export const Ambient = () => {
4950
<Accordion>
5051
<Accordion.Item eventKey='0'>
5152
<Accordion.Header>History</Accordion.Header>
52-
<Accordion.Body>
53-
<AmbientChart />
53+
<Accordion.Body onEnter={() => setHistoryVisible(true)} onExited={() => setHistoryVisible(false)}>
54+
{historyVisible && <AmbientChart /> }
5455
</Accordion.Body>
5556
</Accordion.Item>
5657
</Accordion>

web/src/features/sensors/ambient/ambientSlice.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const ambientSlice = createSlice({
2121
state.dewpoint = dewpoint;
2222
state.humidity = humidity;
2323
state.temperature = temperature;
24-
state.history = [...state.history, { timestamp: new Date().getTime(), temperature, humidity, dewpoint}].slice(-1000)
24+
state.history = [...state.history, { timestamp: new Date().getTime(), temperature, humidity, dewpoint}]
2525
},
2626
},
2727
extraReducers: (builder) => {

web/src/features/sensors/heaters/Heaters.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ const Heater = ({heater, index}) => {
176176

177177
export const Heaters = () => {
178178
const heaters = useSelector(selectHeaters);
179+
const [historyVisible, setHistoryVisible] = useState(false);
179180
return <>
180181
<Table>
181182
<thead>
@@ -195,8 +196,8 @@ export const Heaters = () => {
195196
<Accordion>
196197
<Accordion.Item eventKey='0'>
197198
<Accordion.Header>History</Accordion.Header>
198-
<Accordion.Body>
199-
<HeatersChart/>
199+
<Accordion.Body onEnter={() => setHistoryVisible(true)} onExited={() => setHistoryVisible(false)}>
200+
{ historyVisible && <HeatersChart/> }
200201
</Accordion.Body>
201202
</Accordion.Item>
202203
</Accordion>

web/src/features/sensors/heaters/heatersSlice.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const transformDuty = heater => {
2222
return {...heater, duty: heater.active ? heater.duty : 0}
2323
}
2424
const addHeatersToHistory = (state) => {
25-
state.history = [...state.history, { timestamp: new Date().getTime(), heaters: state.heaters.map(transformDuty) }].slice(-1000)
25+
state.history = [...state.history, { timestamp: new Date().getTime(), heaters: state.heaters.map(transformDuty) }]
2626
}
2727
const onHeatersReceived = (state, payload) => {
2828
state.heaters = payload;
@@ -57,7 +57,6 @@ export const heatersSlice = createSlice({
5757
.addCase(getHeatersAsync.fulfilled, (state, action) => onHeatersReceived(state, action.payload))
5858
.addCase(setHeaterAsync.fulfilled, (state, action) => onHeatersReceived(state, action.payload))
5959
.addCase(getHistoryAsync.fulfilled, (state, { payload }) => {
60-
console.log(payload)
6160
if(!payload) {
6261
return;
6362
}

web/src/features/sensors/power/Power.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const PowerChart= ({}) => {
3232

3333
export const Power = () => {
3434
const { busVoltage, current, power } = useSelector(selectPower);
35+
const [historyVisible, setHistoryVisible] = useState(false);
3536
return <>
3637
<Table>
3738
<tbody>
@@ -52,8 +53,8 @@ export const Power = () => {
5253
<Accordion>
5354
<Accordion.Item eventKey='0'>
5455
<Accordion.Header>History</Accordion.Header>
55-
<Accordion.Body>
56-
<PowerChart />
56+
<Accordion.Body onEnter={() => setHistoryVisible(true)} onExited={() => setHistoryVisible(false)}>
57+
{ historyVisible && <PowerChart /> }
5758
</Accordion.Body>
5859
</Accordion.Item>
5960
</Accordion>

web/src/features/sensors/power/powerSlice.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const powerSlice = createSlice({
2323
state.current = current;
2424
state.power = power;
2525
state.shuntVoltage = shuntVoltage;
26-
state.history = [...state.history, { timestamp: new Date().getTime(), busVoltage, current, power}].slice(-1000)
26+
state.history = [...state.history, { timestamp: new Date().getTime(), busVoltage, current, power}]
2727
},
2828
},
2929
extraReducers: (builder) => {

0 commit comments

Comments
 (0)