Skip to content

Commit

Permalink
feat(solar): remove chart features
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed Nov 6, 2023
1 parent 76116e0 commit 1a2ada7
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 245 deletions.
4 changes: 0 additions & 4 deletions src/DeviceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ export const Properties = styled.dl`
}
`

export const SolarColor = styled.span`
color: var(--color-nordic-sun);
`

export const ShieldIcon = styled.span`
margin-right: 0.25rem;
`
Expand Down
73 changes: 0 additions & 73 deletions src/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ export const Settings = () => {
settings: {
showSettings,
enableTestDevice,
gainReferenceEveryMinute,
gainReferenceEveryHour,
showFavorites,
consumptionThreshold,
showUpdateWarning,
},
update,
Expand Down Expand Up @@ -86,76 +83,6 @@ export const Settings = () => {
Show firmware update warning?
</label>
</div>
<h2 class="h4 mt-4">Solar</h2>
<label htmlFor={'consumptionThreshold'}>
Above this value, charge is considered sufficiently high enough so
device does not use battery:
</label>
<div class="input-group mb-3">
<input
type="number"
class="form-control"
id="consumptionThreshold"
placeholder="e.g. '3.4 mA'"
step={0.1}
min={0}
value={consumptionThreshold}
onChange={(e) => {
update({
consumptionThreshold: parseFloat(
(e.target as HTMLInputElement).value,
),
})
}}
/>
<span class="input-group-text">mA</span>
</div>
<p class={'mb-0'}>
Configure the reference values shown in the Gain chart. Power
consumption when sending updates:
</p>
<div class="d-md-flex mb-3">
<div class="input-group">
<span class="input-group-text">every minute</span>
<input
type="number"
class="form-control"
id="gainReferenceEveryMinute"
placeholder="e.g. '2 mA'"
step={0.1}
min={0}
value={gainReferenceEveryMinute}
onChange={(e) => {
update({
gainReferenceEveryMinute: parseFloat(
(e.target as HTMLInputElement).value,
),
})
}}
/>
<span class="input-group-text">mA</span>
</div>
<div class="ms-md-3 input-group">
<span class="input-group-text">every hour</span>
<input
type="number"
class="form-control"
id="gainReferenceEveryHour"
placeholder="e.g. '1 mA'"
step={0.1}
min={0}
value={gainReferenceEveryHour}
onChange={(e) => {
update({
gainReferenceEveryHour: parseFloat(
(e.target as HTMLInputElement).value,
),
})
}}
/>
<span class="input-group-text">mA</span>
</div>
</div>
</div>
<div class="card-footer d-flex justify-content-between">
<button
Expand Down
10 changes: 1 addition & 9 deletions src/Tracker.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { identifyIssuer } from 'e118-iin-list'
import { Sun, UploadCloud, Wifi } from 'lucide-preact'
import { UploadCloud, Wifi } from 'lucide-preact'
import styled from 'styled-components'
import { ButtonPress } from './ButtonPress.js'
import { CountryFlag } from './CountryFlag.js'
Expand All @@ -8,7 +8,6 @@ import {
LastUpdate,
Properties,
ShieldIcon,
SolarColor,
Title,
} from './DeviceList.js'
import { DeviceName } from './DeviceName.js'
Expand Down Expand Up @@ -87,13 +86,6 @@ export const Tracker = ({ device }: { device: Device }) => {
/>
</ShieldIcon>
)}
{appV?.includes('solar') === true && (
<ShieldIcon>
<SolarColor>
<Sun />
</SolarColor>
</ShieldIcon>
)}
<DeviceName device={device} />
</span>
<CountryFlag device={device} />
Expand Down
53 changes: 1 addition & 52 deletions src/chart/DeviceHistory.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import { format, subSeconds } from 'date-fns'
import {
Battery,
Sun,
Thermometer,
X,
type LucideProps,
Zap,
} from 'lucide-preact'
import { Battery, Thermometer, X, type LucideProps, Zap } from 'lucide-preact'
import { useRef } from 'preact/hooks'
import styled from 'styled-components'
import { colors } from '../colors.js'
import { useDevices, type Reading } from '../context/Devices.js'
import { useSettings } from '../context/Settings.js'
import { useHistoryChart } from '../context/showHistoryChart.js'
import { HistoryChart } from './HistoryChart.js'
import type { Dataset } from './chartMath.js'
Expand Down Expand Up @@ -71,45 +63,13 @@ const findLowerLimit = (v: Array<Reading>): number =>
export const DeviceHistory = () => {
const { devices } = useDevices()
const { deviceId } = useHistoryChart()
const {
settings: { gainReferenceEveryHour, gainReferenceEveryMinute },
} = useSettings()

if (deviceId === undefined) return null

const history = devices[deviceId]?.history

const charts: ChartInfo[] = []

if (history?.solGain !== undefined) {
charts.push({
Icon: Sun,
title: 'Solar',
color: colors['nordic-sun'],
datasets: [
{
min: 0,
max: 5,
values: history.solGain.map(([v, d]) => [
v,
subSeconds(history.base, d),
]),
color: colors['nordic-sun'],
format: (v) => `${v.toFixed(1)}mA`,
helperLines: [
{
label: '1m',
value: gainReferenceEveryMinute,
},
{
label: '60m',
value: gainReferenceEveryHour,
},
],
},
],
})
}
if (history?.bat !== undefined) {
charts.push({
Icon: Battery,
Expand All @@ -122,17 +82,6 @@ export const DeviceHistory = () => {
values: history.bat.map(([v, d]) => [v, subSeconds(history.base, d)]),
color: colors['nordic-blue'],
format: (v) => `${v.toFixed(1)}V`,
helperLines: (history?.guides ?? [])
.filter(([type]) => type === 'bat')
.map(([, v, d]) => ({
label: `${Math.floor(
(Date.now() - subSeconds(history.base, d).getTime()) /
1000 /
60 /
60,
)}h ago`,
value: v,
})),
},
],
})
Expand Down
16 changes: 3 additions & 13 deletions src/context/Devices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,27 +190,17 @@ export type Reading = [
]
export type Summary = {
base: Date // '2022-12-07T12:09:59.488Z'
/**
* @deprecated use fuel gauge data
*/
bat?: Array<Reading>
temp?: Array<Reading>
solBat?: Array<Reading>
solGain?: Array<Reading>
// Fuel gauge readings, see https://github.com/NordicSemiconductor/asset-tracker-cloud-docs/blob/4713549af719a7e119324853aa117d752ac856e3/docs/cloud-protocol/Reported.ts#L111
fgSoC?: Array<Reading>
fgI?: Array<Reading>
fgTTE?: Array<Reading>
fgTTF?: Array<Reading>
fgT?: Array<Reading>
/**
* Contains one or more significant readings to display as guides.
*
* Used for example to visualize that the battery level did not change for Thingys with Solar shield.
*/
guides?: [
type: 'bat' | 'temp' | 'solGain',
v: number,
// Delta to the base date in seconds
d: number,
][]
}

export const isTracker = (device: Device): boolean => {
Expand Down
12 changes: 0 additions & 12 deletions src/context/LwM2M.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
type ConnectionInformation_14203,
type DeviceInformation_14204,
type Environment_14205,
type SolarCharge_14210,
} from '@hello.nrfcloud.com/proto-lwm2m'
import { useEffect, useState } from 'preact/hooks'
import { MessageContext, useWebsocket } from './WebsocketConnection.js'
Expand Down Expand Up @@ -109,15 +108,6 @@ export const Provider = ({ children }: { children: ComponentChildren }) => {
},
ts: new Date(object.Resources['99']).getTime(),
}
} else if (isSolarCharge(object)) {
const { 0: gain, 1: bat } = object.Resources
reported.fg = {
v: {
I: gain,
V: bat,
},
ts: new Date(object.Resources['99']).getTime(),
}
} else if (isGeolocation(object)) {
const {
1: lng,
Expand Down Expand Up @@ -201,7 +191,5 @@ const isDeviceInformation = (
): object is DeviceInformation_14204 => isLwM2MObject(14204, object)
const isEnvironment = (object: unknown): object is Environment_14205 =>
isLwM2MObject(14205, object)
const isSolarCharge = (object: unknown): object is SolarCharge_14210 =>
isLwM2MObject(14210, object)
const isBatteryAndPower = (object: unknown): object is BatteryAndPower_14202 =>
isLwM2MObject(14202, object)
12 changes: 0 additions & 12 deletions src/context/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,17 @@ import { createContext, type ComponentChildren } from 'preact'
import { useContext, useState } from 'preact/hooks'

type Settings = {
/**
* Above this value, charge is considered sufficiently high enough so device does not use battery.
*/
consumptionThreshold: number
enableTestDevice: boolean
showSettings: boolean
showFavorites: boolean
favorites: string[]
/**
* Configure the reference lines shown in the Gain chart
*/
gainReferenceEveryMinute: number
gainReferenceEveryHour: number
showUpdateWarning: boolean
managementCodes: Record<string, string>
}

const defaultSettings: Settings = {
consumptionThreshold: 3.4,
enableTestDevice: false,
showSettings: false,
gainReferenceEveryMinute: 3.4,
gainReferenceEveryHour: 2.3,
showFavorites: false,
favorites: [],
showUpdateWarning: true,
Expand Down
71 changes: 1 addition & 70 deletions src/test-device/FakeTracker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const fakeTrackerState = (): Reported => ({
iccid: '89470060200703359994',
modV: 'mfw_nrf9160_1.3.2',
brdV: 'thingy91_nrf9160',
appV: '1.7.0-thingy91+debug+solar+memfault',
appV: '1.7.0-thingy91+debug+memfault',
bat: 'LP502540',
},
ts: Date.now(),
Expand Down Expand Up @@ -191,73 +191,4 @@ const fakeTrackerHistory = (): Summary => ({
[22.425, 3532],
[22.435, 3592],
],
solGain: [
[0, 1],
[5, 61],
[3.585, 112],
[3.575, 172],
[3.575, 232],
[3.575, 292],
[3.555, 352],
[3.565, 412],
[3.565, 472],
[3.575, 532],
[3.565, 592],
[3.555, 652],
[3.555, 712],
[3.545, 772],
[3.565, 832],
[3.565, 892],
[3.565, 952],
[3.565, 1012],
[3.565, 1072],
[3.565, 1132],
[3.575, 1192],
[3.555, 1252],
[3.565, 1312],
[3.565, 1372],
[3.575, 1432],
[3.565, 1492],
[3.565, 1552],
[3.555, 1612],
[3.555, 1672],
[3.545, 1732],
[3.545, 1792],
[3.535, 1852],
[3.535, 1912],
[3.535, 1972],
[3.535, 2032],
[3.535, 2092],
[3.535, 2152],
[3.525, 2212],
[3.535, 2272],
[3.535, 2332],
[3.525, 2392],
[3.525, 2452],
[3.535, 2512],
[3.535, 2572],
[3.525, 2632],
[3.535, 2692],
[3.535, 2752],
[3.525, 2812],
[3.505, 2872],
[3.475, 2932],
[3.485, 2992],
[3.485, 3052],
[3.475, 3112],
[3.475, 3172],
[3.475, 3232],
[3.455, 3292],
[3.455, 3352],
[3.455, 3412],
[3.445, 3472],
[3.425, 3532],
[3.435, 3592],
],
/**
* Contains one or more significant readings to display as guides.
*
* Used for example to visualize that the battery level did not change for Thingys with Solar shield.
*/
guides: [['bat', 3.9, 60 * 60 * 8]],
})

0 comments on commit 1a2ada7

Please sign in to comment.