Skip to content
42 changes: 42 additions & 0 deletions edge-apps/peripheral-integration-demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,48 @@
</div>
</div>
</div>

<!-- Sensor Data -->
<div class="glass-card glass-card--left">
<div class="glass-card-heading">
<!-- Activity icon -->
<svg
class="glass-card-icon"
width="48"
height="48"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
>
<polyline points="22 12 18 12 15 21 9 3 6 12 2 12" />
</svg>
<span class="glass-card-title">Sensor Data</span>
</div>

<div class="operator-grid">
<div class="operator-field">
<span class="operator-label">Temperature</span>
<span id="sensor-temperature" class="operator-value"
>No Data</span
>
</div>
<div class="operator-field">
<span class="operator-label">Humidity</span>
<span id="sensor-humidity" class="operator-value"
>No Data</span
>
</div>
<div class="operator-field">
<span class="operator-label">Air Pressure</span>
<span id="sensor-air-pressure" class="operator-value"
>No Data</span
>
</div>
</div>
</div>
</div>

<!-- Maintenance Screen -->
Expand Down
3 changes: 2 additions & 1 deletion edge-apps/peripheral-integration-demo/src/core/screen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function syncScreensToState(state: ReturnType<typeof getState>) {
}

const publicTemp = getEl('public-temperature')
publicTemp.textContent = `${Math.round(state.temperature)}°C`
publicTemp.textContent =
state.temperature !== null ? `${Math.round(state.temperature)}°C` : '--'

if (state.currentScreen === 'maintenance') {
getEl('maintenance-network').textContent = getNetworkStatus()
Expand Down
18 changes: 16 additions & 2 deletions edge-apps/peripheral-integration-demo/src/core/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ export interface AppState {
currentScreen: ScreenType
timezone: string
locale: string
temperature: number
temperature: number | null
humidity: number | null
airPressure: number | null
}

const state: AppState = {
currentScreen: 'public',
timezone: 'UTC',
locale: 'en',
temperature: 22,
temperature: null,
humidity: null,
airPressure: null,
}

type Listener = (state: AppState) => void
Expand Down Expand Up @@ -50,6 +54,16 @@ export function setTemperature(value: number) {
notify()
}

export function setHumidity(value: number) {
state.humidity = value
notify()
}

export function setAirPressure(value: number) {
state.airPressure = value
notify()
}
Comment thread
nicomiguelino marked this conversation as resolved.
Outdated

export function getState(): Readonly<AppState> {
return { ...state }
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,33 @@ function stopUpdates() {
}
}

function updateSensorData(state: ReturnType<typeof getState>) {
getEl('sensor-temperature').textContent =
state.temperature !== null
? `${Math.round(state.temperature)}°C`
: 'No Data'
getEl('sensor-humidity').textContent =
state.humidity !== null ? `${Math.round(state.humidity)}%` : 'No Data'
getEl('sensor-air-pressure').textContent =
state.airPressure !== null
? `${Math.round(state.airPressure)} hPa`
: 'No Data'
}

function onStateChange(state: ReturnType<typeof getState>) {
if (state.currentScreen === 'operator') {
startUpdates()
} else {
stopUpdates()
}
updateSensorData(state)
}

export function initOperatorDashboard() {
subscribe(onStateChange)
if (getState().currentScreen === 'operator') startUpdates()
const state = getState()
if (state.currentScreen === 'operator') startUpdates()
updateSensorData(state)
}

export function updateOperatorDashboard() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { createPeripheralClient } from '@screenly/edge-apps'
import type { PeripheralStateMessage } from '@screenly/edge-apps'

import { getState, setTemperature } from '../core/state'
import {
getState,
setTemperature,
setHumidity,
setAirPressure,
} from '../core/state'
import { showWelcomeThenSwitch } from '../core/screen'
import { restartLogoutTimer } from '../core/timer'
import { authenticate } from './authenticate'
Expand All @@ -21,6 +26,16 @@ export function initPeripherals() {
setTemperature(tempReading.ambient_temperature as number)
}

const humidityReading = readings.find((r) => 'humidity' in r)
if (humidityReading) {
setHumidity(humidityReading.humidity as number)
}

const pressureReading = readings.find((r) => 'air_pressure' in r)
if (pressureReading) {
setAirPressure(pressureReading.air_pressure as number)
}
Comment thread
nicomiguelino marked this conversation as resolved.
Outdated

const cardReading = readings.find((r) => 'secure_card' in r)
if (cardReading) {
const MAX_CARD_AGE_MS = 60_000
Expand Down
Loading