Format code with pw format
Change-Id: I0c11f7e663fb0a873391109ae7084e2684d81162
Reviewed-on: https://pigweed-internal-review.git.corp.google.com/c/pigweed/showcase/rp2/+/74420
Reviewed-by: Armando Montanez <amontanez@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
Presubmit-Verified: CQ Bot Account <pigweed-internal-scoped@luci-project-accounts.iam.gserviceaccount.com>
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
diff --git a/.buildifier.json b/.buildifier.json
index 8c1d292..d0ffbbe 100644
--- a/.buildifier.json
+++ b/.buildifier.json
@@ -1,8 +1,8 @@
{
- "type": "auto",
- "warningsList": [
- "load",
- "native-build",
- "unsorted-dict-items"
- ]
-}
\ No newline at end of file
+ "type": "auto",
+ "warningsList": [
+ "load",
+ "native-build",
+ "unsorted-dict-items"
+ ]
+}
diff --git a/apps/blinky/BUILD.bazel b/apps/blinky/BUILD.bazel
index 7005d8a..b25740d 100644
--- a/apps/blinky/BUILD.bazel
+++ b/apps/blinky/BUILD.bazel
@@ -15,7 +15,7 @@
load("@pigweed//targets/host_device_simulator:transition.bzl", "host_device_simulator_binary")
load("@pigweed//targets/rp2040:flash.bzl", "flash_rp2040")
load("//targets/rp2:binary.bzl", "rp2040_binary", "rp2350_binary")
-load("//tools:tools.bzl", "sense_device_console", "sense_device_script", "sense_host_console",)
+load("//tools:tools.bzl", "sense_device_console", "sense_device_script", "sense_host_console")
package(default_visibility = ["//visibility:public"])
@@ -75,7 +75,7 @@
sense_device_console(
name = "rp2040_webconsole",
binary = ":rp2040_blinky.elf",
- extra_args = ["--browser"]
+ extra_args = ["--browser"],
)
sense_device_console(
@@ -86,7 +86,7 @@
sense_device_console(
name = "rp2350_webconsole",
binary = ":rp2350_blinky.elf",
- extra_args = ["--browser"]
+ extra_args = ["--browser"],
)
sense_device_script(
diff --git a/device/bme68x.BUILD.bazel b/device/bme68x.BUILD.bazel
index 5fad893..0093cde 100644
--- a/device/bme68x.BUILD.bazel
+++ b/device/bme68x.BUILD.bazel
@@ -16,7 +16,7 @@
cc_library(
name = "bme68x",
- srcs = [ "bme68x.c" ],
+ srcs = ["bme68x.c"],
hdrs = [
"bme68x.h",
"bme68x_defs.h",
diff --git a/modules/blinky/BUILD.bazel b/modules/blinky/BUILD.bazel
index 6c21c29..400cbb6 100644
--- a/modules/blinky/BUILD.bazel
+++ b/modules/blinky/BUILD.bazel
@@ -67,8 +67,8 @@
deps = [
":blinky",
":nanopb_rpc",
- "@pigweed//pw_assert:check",
"@pigweed//pw_allocator:allocator",
+ "@pigweed//pw_assert:check",
"@pigweed//pw_async2:dispatcher",
],
)
diff --git a/modules/blinky/service.cc b/modules/blinky/service.cc
index 6ba158e..78cd321 100644
--- a/modules/blinky/service.cc
+++ b/modules/blinky/service.cc
@@ -13,9 +13,10 @@
// the License.
#define PW_LOG_MODULE_NAME "BLINKY"
-#include "pw_assert/check.h"
#include "modules/blinky/service.h"
+#include "pw_assert/check.h"
+
namespace sense {
void BlinkyService::Init(pw::async2::Dispatcher& dispatcher,
diff --git a/modules/buttons/manager.h b/modules/buttons/manager.h
index 6ea9e4a..d87c5a6 100644
--- a/modules/buttons/manager.h
+++ b/modules/buttons/manager.h
@@ -15,9 +15,9 @@
#include <chrono>
-#include "pw_assert/check.h"
#include "modules/pubsub/pubsub_events.h"
#include "modules/worker/worker.h"
+#include "pw_assert/check.h"
#include "pw_chrono/system_clock.h"
#include "pw_chrono/system_timer.h"
#include "pw_digital_io/digital_io.h"
@@ -32,7 +32,8 @@
constexpr static pw::chrono::SystemClock::duration kDebounceInterval =
std::chrono::milliseconds(30);
- Debouncer(pw::digital_io::State initial_state) : last_input_(initial_state){};
+ Debouncer(pw::digital_io::State initial_state)
+ : last_input_(initial_state) {};
pw::digital_io::State UpdateState(pw::chrono::SystemClock::time_point now,
pw::digital_io::State state);
@@ -46,7 +47,7 @@
class EdgeDetector final {
public:
EdgeDetector(pw::digital_io::State initial_state)
- : current_state_(initial_state){};
+ : current_state_(initial_state) {};
enum StateChange {
kNone,
@@ -62,7 +63,9 @@
class Button {
public:
- Button(pw::digital_io::DigitalIn& io) : io_(io) { PW_CHECK_OK(io_.Enable()); };
+ Button(pw::digital_io::DigitalIn& io) : io_(io) {
+ PW_CHECK_OK(io_.Enable());
+ };
pw::Result<EdgeDetector::StateChange> Sample(
pw::chrono::SystemClock::time_point now);
diff --git a/modules/buttons/manager_test.cc b/modules/buttons/manager_test.cc
index e4ec9e6..a5ea527 100644
--- a/modules/buttons/manager_test.cc
+++ b/modules/buttons/manager_test.cc
@@ -17,7 +17,6 @@
#include "modules/worker/test_worker.h"
#include "pw_digital_io/digital_io.h"
#include "pw_status/status.h"
-#include "pw_sync/timed_thread_notification.h"
#include "pw_sync/interrupt_spin_lock.h"
#include "pw_sync/timed_thread_notification.h"
#include "pw_unit_test/framework.h"
diff --git a/modules/led/BUILD.bazel b/modules/led/BUILD.bazel
index b5eb25e..7cd299f 100644
--- a/modules/led/BUILD.bazel
+++ b/modules/led/BUILD.bazel
@@ -30,7 +30,7 @@
hdrs = ["monochrome_led_fake.h"],
deps = [
":monochrome_led",
- "//modules/pwm:digital_out_fake",
+ "//modules/pwm:digital_out_fake",
"@pigweed//pw_digital_io:digital_io_mock",
],
)
diff --git a/modules/led/monochrome_led.cc b/modules/led/monochrome_led.cc
index 36cdebb..a665017 100644
--- a/modules/led/monochrome_led.cc
+++ b/modules/led/monochrome_led.cc
@@ -12,9 +12,10 @@
// License for the specific language governing permissions and limitations under
// the License.
-#include "pw_assert/check.h"
#include "modules/led/monochrome_led.h"
+#include "pw_assert/check.h"
+
namespace sense {
MonochromeLed::MonochromeLed(pw::digital_io::DigitalInOut& sio,
diff --git a/modules/lerp/lerp_test.cc b/modules/lerp/lerp_test.cc
index d6f9ef1..cbb6e46 100644
--- a/modules/lerp/lerp_test.cc
+++ b/modules/lerp/lerp_test.cc
@@ -16,8 +16,12 @@
#include "pw_unit_test/framework.h"
-TEST(LerpTest, ZeroFractionReturnsA) { EXPECT_EQ(sense::Lerp(0, 20, 0, 10), 0); }
-TEST(LerpTest, OneFractionReturnsB) { EXPECT_EQ(sense::Lerp(0, 20, 10, 10), 20); }
+TEST(LerpTest, ZeroFractionReturnsA) {
+ EXPECT_EQ(sense::Lerp(0, 20, 0, 10), 0);
+}
+TEST(LerpTest, OneFractionReturnsB) {
+ EXPECT_EQ(sense::Lerp(0, 20, 10, 10), 20);
+}
TEST(LerpTest, HalfFractionReturnsHalfwayPoint) {
EXPECT_EQ(sense::Lerp(0, 20, 5, 10), 10);
}
diff --git a/modules/pubsub/pubsub.h b/modules/pubsub/pubsub.h
index d4aaef8..e5fe835 100644
--- a/modules/pubsub/pubsub.h
+++ b/modules/pubsub/pubsub.h
@@ -145,7 +145,7 @@
struct IsVariant : std::false_type {};
template <typename... Types>
- struct IsVariant<std::variant<Types...>> : std::true_type{};
+ struct IsVariant<std::variant<Types...>> : std::true_type {};
// Events (or their variant elements) must be standard layout and trivially
// copyable & destructible.
diff --git a/targets/host/system.cc b/targets/host/system.cc
index 53d9a1a..665ae2e 100644
--- a/targets/host/system.cc
+++ b/targets/host/system.cc
@@ -91,12 +91,11 @@
static std::byte channel_buffer[16384];
static pw::multibuf::SimpleAllocator multibuf_alloc(channel_buffer,
pw::System().allocator());
- static pw::NoDestructor<StreamChannel> channel(
- multibuf_alloc,
- pw::system::GetReader(),
- pw::thread::stl::Options(),
- pw::system::GetWriter(),
- pw::thread::stl::Options());
+ static pw::NoDestructor<StreamChannel> channel(multibuf_alloc,
+ pw::system::GetReader(),
+ pw::thread::stl::Options(),
+ pw::system::GetWriter(),
+ pw::thread::stl::Options());
pw::SystemStart(*channel);
PW_UNREACHABLE;
diff --git a/targets/rp2/BUILD.bazel b/targets/rp2/BUILD.bazel
index ba7ed72..df39db5 100644
--- a/targets/rp2/BUILD.bazel
+++ b/targets/rp2/BUILD.bazel
@@ -103,9 +103,9 @@
"@pico-sdk//src/rp2_common/hardware_adc",
"@pico-sdk//src/rp2_common/hardware_exception:hardware_exception",
"@pico-sdk//src/rp2_common/pico_stdlib:pico_stdlib",
- "@pigweed//pw_cpu_exception:entry_backend_impl",
"@pigweed//pw_channel",
"@pigweed//pw_channel:rp2_stdio_channel",
+ "@pigweed//pw_cpu_exception:entry_backend_impl",
"@pigweed//pw_digital_io_rp2040",
"@pigweed//pw_i2c_rp2040",
"@pigweed//pw_multibuf:simple_allocator",
diff --git a/targets/rp2/binary.bzl b/targets/rp2/binary.bzl
index c3be6c0..dd19858 100644
--- a/targets/rp2/binary.bzl
+++ b/targets/rp2/binary.bzl
@@ -26,14 +26,14 @@
"//apps/production:threads": "//targets/rp2:production_app_threads",
"//system:system": "//targets/rp2:system",
"@freertos//:freertos_config": "//targets/rp2:freertos_config",
- "@pigweed//pw_system:extra_platform_libs": "//targets/rp2:extra_platform_libs",
- "@pigweed//pw_system:io_backend": "@pigweed//pw_system:sys_io_target_io",
- "@pigweed//pw_build:default_module_config": "//system:module_config",
"@pico-sdk//bazel/config:PICO_CLIB": "llvm_libc",
"@pico-sdk//bazel/config:PICO_TOOLCHAIN": "clang",
+ "@pigweed//pw_build:default_module_config": "//system:module_config",
+ "@pigweed//pw_system:extra_platform_libs": "//targets/rp2:extra_platform_libs",
+ "@pigweed//pw_system:io_backend": "@pigweed//pw_system:sys_io_target_io",
"@pigweed//pw_toolchain:cortex-m_toolchain_kind": "clang",
"@pigweed//pw_unit_test:config_override": "//targets/rp2:64k_unit_tests",
- }
+ },
)
_RP2040_FLAGS = {
diff --git a/tools/tools.bzl b/tools/tools.bzl
index 653bdf6..2ded762 100644
--- a/tools/tools.bzl
+++ b/tools/tools.bzl
@@ -90,4 +90,4 @@
data = [
binary,
],
- )
\ No newline at end of file
+ )
diff --git a/web_app/copy_protos.ts b/web_app/copy_protos.ts
index 51d880c..1fae207 100644
--- a/web_app/copy_protos.ts
+++ b/web_app/copy_protos.ts
@@ -39,8 +39,8 @@
},
{
prefix: "state_manager",
- protos: ["../modules/state_manager/state_manager.proto"]
- }
+ protos: ["../modules/state_manager/state_manager.proto"],
+ },
];
/**
diff --git a/web_app/src/common/rpcService.ts b/web_app/src/common/rpcService.ts
index e30cc64..cea9bf6 100644
--- a/web_app/src/common/rpcService.ts
+++ b/web_app/src/common/rpcService.ts
@@ -15,9 +15,15 @@
import { WebSerial, pw_hdlc, pw_rpc, pw_status } from "pigweedjs";
import { ProtoCollection } from "../../protos/collection/collection";
import { BlinkRequest } from "../../protos/collection/blinky/blinky_pb";
-import { OnboardTempStreamRequest, OnboardTempResponse } from "../../protos/collection/board/board_pb";
-import {MeasureStreamRequest, Measurement} from "../../protos/collection/air_sensor/air_sensor_pb";
-import {State} from "../../protos/collection/state_manager/state_manager_pb";
+import {
+ OnboardTempStreamRequest,
+ OnboardTempResponse,
+} from "../../protos/collection/board/board_pb";
+import {
+ MeasureStreamRequest,
+ Measurement,
+} from "../../protos/collection/air_sensor/air_sensor_pb";
+import { State } from "../../protos/collection/state_manager/state_manager_pb";
class RPCService {
transport;
decoder;
@@ -70,7 +76,7 @@
});
}
- async disconnect(){
+ async disconnect() {
await this.transport.disconnect();
}
@@ -84,45 +90,54 @@
async streamTemp(onTemp?: (temp: number) => void) {
const req = new OnboardTempStreamRequest();
req.setSampleIntervalMs(500);
- await this.boardTempService.invoke(req, (m: OnboardTempResponse)=>{
- console.log(m.toObject());
- if (onTemp) onTemp(m.getTemp());
- }, undefined, (err)=>{
- console.error(err);
- });
+ await this.boardTempService.invoke(
+ req,
+ (m: OnboardTempResponse) => {
+ console.log(m.toObject());
+ if (onTemp) onTemp(m.getTemp());
+ },
+ undefined,
+ (err) => {
+ console.error(err);
+ },
+ );
}
- async streamMeasure(onMeasure?: (measurement: Measurement) => void){
- // We check if this RPC exists on device,
+ async streamMeasure(onMeasure?: (measurement: Measurement) => void) {
+ // We check if this RPC exists on device,
// if not we fallback to just onboardTemp.
- return new Promise(async (resolve, reject)=>{
+ return new Promise(async (resolve, reject) => {
let resolveCalled = false;
const req = new MeasureStreamRequest();
req.setSampleIntervalMs(500);
- await this.measureService.invoke(req, (m: Measurement)=>{
- if (!resolveCalled) {
- resolveCalled = true;
- resolve(true);
- }
- if (onMeasure) onMeasure(m);
- }, undefined, (status: pw_status.Status)=>{
- if (status = pw_status.Status.NOT_FOUND){
- reject(status);
- }
- });
+ await this.measureService.invoke(
+ req,
+ (m: Measurement) => {
+ if (!resolveCalled) {
+ resolveCalled = true;
+ resolve(true);
+ }
+ if (onMeasure) onMeasure(m);
+ },
+ undefined,
+ (status: pw_status.Status) => {
+ if ((status = pw_status.Status.NOT_FOUND)) {
+ reject(status);
+ }
+ },
+ );
});
}
- async getState(): Promise<State>{
+ async getState(): Promise<State> {
const [status, response] = await this.stateService.call();
return response;
}
}
-
// We keep a singleton of this service.
const rpc = new RPCService();
export function getRpcService(): RPCService {
return rpc;
-}
\ No newline at end of file
+}
diff --git a/web_app/src/common/state.ts b/web_app/src/common/state.ts
index 82de86f..450e9dd 100644
--- a/web_app/src/common/state.ts
+++ b/web_app/src/common/state.ts
@@ -12,111 +12,145 @@
// License for the specific language governing permissions and limitations under
// the License.
-import { create } from 'zustand'
+import { create } from "zustand";
type AlarmState = {
- alarmActive: boolean;
- aqDescription: "superb" | "excellent" | "very good" | "good" | "okay" | "mediocre" | "bad" | "terrible" | "invalid";
- alarmThreshold: number;
-}
+ alarmActive: boolean;
+ aqDescription:
+ | "superb"
+ | "excellent"
+ | "very good"
+ | "good"
+ | "okay"
+ | "mediocre"
+ | "bad"
+ | "terrible"
+ | "invalid";
+ alarmThreshold: number;
+};
type Reading = {
- temperature: number;
- score: number;
- humidity: number;
- alarmState: AlarmState;
-}
+ temperature: number;
+ score: number;
+ humidity: number;
+ alarmState: AlarmState;
+};
export type HistoricReading = {
- timestamp: Date;
- data: Reading;
-}
-
-export type AppState = {
- connected: boolean;
- basicMode: boolean;
- currentReading: Reading;
- historicReadings: HistoricReading[];
- setConnected: (connected: boolean) => void;
- addReading: (reading: Reading) => void;
- setBasicMode: (basicMode: boolean) => void;
-}
+ timestamp: Date;
+ data: Reading;
+};
-const getTimeMinusMs = (ms: number) => new Date(new Date(new Date().getTime() - 60000).toISOString().replace('T', ' ').substring(0, 19))
+export type AppState = {
+ connected: boolean;
+ basicMode: boolean;
+ currentReading: Reading;
+ historicReadings: HistoricReading[];
+ setConnected: (connected: boolean) => void;
+ addReading: (reading: Reading) => void;
+ setBasicMode: (basicMode: boolean) => void;
+};
+
+const getTimeMinusMs = (ms: number) =>
+ new Date(
+ new Date(new Date().getTime() - 60000)
+ .toISOString()
+ .replace("T", " ")
+ .substring(0, 19),
+ );
const dummyHistory: HistoricReading[] = [
- {timestamp: getTimeMinusMs(160000), data: {
- temperature: 50,
- score: 50,
- humidity: 50,
- alarmState: {
- alarmActive: false,
- aqDescription: "okay",
- alarmThreshold: 0
- }
- }},
- {timestamp: getTimeMinusMs(120000), data: {
- temperature: 50,
- score: 99,
- humidity: 50,
- alarmState: {
- alarmActive: false,
- aqDescription: "superb",
- alarmThreshold: 0
- }
- }},
- {timestamp: getTimeMinusMs(60000), data: {
- temperature: 50,
- score: 1,
- humidity: 50,
- alarmState: {
- alarmActive: false,
- aqDescription: "bad",
- alarmThreshold: 0
- }
- }},
- {timestamp: getTimeMinusMs(30000), data: {
- temperature: 50,
- score: 79,
- humidity: 50,
- alarmState: {
- alarmActive: false,
- aqDescription: "very good",
- alarmThreshold: 0
- }
- }},
- {timestamp: getTimeMinusMs(0), data: {
- temperature: 50,
- score: 99,
- humidity: 50,
- alarmState: {
- alarmActive: false,
- aqDescription: "superb",
- alarmThreshold: 0
- }
- }}
+ {
+ timestamp: getTimeMinusMs(160000),
+ data: {
+ temperature: 50,
+ score: 50,
+ humidity: 50,
+ alarmState: {
+ alarmActive: false,
+ aqDescription: "okay",
+ alarmThreshold: 0,
+ },
+ },
+ },
+ {
+ timestamp: getTimeMinusMs(120000),
+ data: {
+ temperature: 50,
+ score: 99,
+ humidity: 50,
+ alarmState: {
+ alarmActive: false,
+ aqDescription: "superb",
+ alarmThreshold: 0,
+ },
+ },
+ },
+ {
+ timestamp: getTimeMinusMs(60000),
+ data: {
+ temperature: 50,
+ score: 1,
+ humidity: 50,
+ alarmState: {
+ alarmActive: false,
+ aqDescription: "bad",
+ alarmThreshold: 0,
+ },
+ },
+ },
+ {
+ timestamp: getTimeMinusMs(30000),
+ data: {
+ temperature: 50,
+ score: 79,
+ humidity: 50,
+ alarmState: {
+ alarmActive: false,
+ aqDescription: "very good",
+ alarmThreshold: 0,
+ },
+ },
+ },
+ {
+ timestamp: getTimeMinusMs(0),
+ data: {
+ temperature: 50,
+ score: 99,
+ humidity: 50,
+ alarmState: {
+ alarmActive: false,
+ aqDescription: "superb",
+ alarmThreshold: 0,
+ },
+ },
+ },
];
export const useAppState = create<AppState>()((set) => ({
- connected: false,
- basicMode: false,
- currentReading: {
- temperature: 50,
- score: 99,
- humidity: 50,
- alarmState: {
- alarmActive: false,
- aqDescription: "superb",
- alarmThreshold: 0
- }
+ connected: false,
+ basicMode: false,
+ currentReading: {
+ temperature: 50,
+ score: 99,
+ humidity: 50,
+ alarmState: {
+ alarmActive: false,
+ aqDescription: "superb",
+ alarmThreshold: 0,
},
- historicReadings: [],
- setConnected: (connected: boolean) => set({connected}),
- setBasicMode: (basicMode: boolean) => set({basicMode}),
- addReading: (reading: Reading) => set(state =>{
- console.log("new reading", reading);
- return {
- currentReading: reading,
- historicReadings: [...state.historicReadings, {timestamp: new Date(), data: reading}]
- }
- })
-}));
\ No newline at end of file
+ },
+ historicReadings: [],
+ setConnected: (connected: boolean) => set({ connected }),
+ setBasicMode: (basicMode: boolean) => set({ basicMode }),
+ addReading: (reading: Reading) =>
+ set((state) => {
+ console.log("new reading", reading);
+ return {
+ currentReading: reading,
+ historicReadings: [
+ ...state.historicReadings,
+ { timestamp: new Date(), data: reading },
+ ],
+ };
+ }),
+}));
diff --git a/web_app/src/common/status.ts b/web_app/src/common/status.ts
index a5a5aa0..cbd0ee2 100644
--- a/web_app/src/common/status.ts
+++ b/web_app/src/common/status.ts
@@ -13,13 +13,33 @@
// the License.
export const StatusData = {
- superb: {icon: "sentiment_very_satisfied", title: "Superb", color: "#7FE3FF"},
- excellent: {icon: "mood", title: "Excellent", color: "#93F7D9"},
- "very good": {icon: "sentiment_satisfied", title: "Very Good", color: "#8FE8B7"},
- good: {icon: "sentiment_calm", title: "Good", color: "#BBE5A9"},
- okay: {icon: "sentiment_neutral", title: "Okay", color: "#F9FFB2"},
- mediocre: {icon: "sentiment_dissatisfied", title: "Mediocre", color: "#EBA28C"},
- bad: {icon: "mood_bad", title: "Bad", color: "#D76591"},
- terrible: {icon: "sentiment_very_dissatisfied", title: "Terrible", color: "#B996EF"},
- invalid: {icon: "sentiment_very_dissatisfied", title: "-", color: "#B996EF"}
-}
\ No newline at end of file
+ superb: {
+ icon: "sentiment_very_satisfied",
+ title: "Superb",
+ color: "#7FE3FF",
+ },
+ excellent: { icon: "mood", title: "Excellent", color: "#93F7D9" },
+ "very good": {
+ icon: "sentiment_satisfied",
+ title: "Very Good",
+ color: "#8FE8B7",
+ },
+ good: { icon: "sentiment_calm", title: "Good", color: "#BBE5A9" },
+ okay: { icon: "sentiment_neutral", title: "Okay", color: "#F9FFB2" },
+ mediocre: {
+ icon: "sentiment_dissatisfied",
+ title: "Mediocre",
+ color: "#EBA28C",
+ },
+ bad: { icon: "mood_bad", title: "Bad", color: "#D76591" },
+ terrible: {
+ icon: "sentiment_very_dissatisfied",
+ title: "Terrible",
+ color: "#B996EF",
+ },
+ invalid: {
+ icon: "sentiment_very_dissatisfied",
+ title: "-",
+ color: "#B996EF",
+ },
+};