Skip to content
Merged
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.16)

project(M5CardputerZeroCompass VERSION 0.1.0 LANGUAGES C CXX ASM)
project(M5CardputerZeroCompass VERSION 0.1.1 LANGUAGES C CXX ASM)

option(COMPASS_USE_SDL "Use LVGL's SDL backend for desktop testing" ON)
option(COMPASS_CONVERT_ASSETS "Convert image assets during CMake configure" ON)
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ Run the SDL build:
```

Calibration data is saved to `calibration.conf` for SDL builds. Packaged
CardputerZero launches set `COMPASS_CONFIG_DIR="$HOME/.config/Compass"`, so
calibration data is saved to `$HOME/.config/Compass/calibration.conf`.
CardputerZero launches use `$HOME/.config/Compass/calibration.conf` by default.

Override the calibration path:

Expand Down Expand Up @@ -126,5 +125,5 @@ build and produces an `arm64` APPLaunch package.
The generated package is written to `dist/`:

```text
dist/m5cardputerzero-compass_0.1.0_m5stack1_arm64.deb
dist/m5cardputerzero-compass_0.1.1_m5stack1_arm64.deb
```
2 changes: 1 addition & 1 deletion packaging/deb/compass.desktop.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Desktop Entry]
Name=Compass
Exec=@DESKTOP_EXEC@
Exec=/usr/share/APPLaunch/bin/M5CardputerZero-Compass
Terminal=false
Icon=share/images/@PACKAGE_ICON_NAME@
Type=Application
3 changes: 0 additions & 3 deletions packaging/deb/package_deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ STAGE_DIR="${STAGE_DIR:-${ROOT_DIR}/build/deb-root}"
DIST_DIR="${DIST_DIR:-${ROOT_DIR}/dist}"
BIN_NAME="M5CardputerZero-Compass"
PACKAGE_ICON_NAME="${PACKAGE_ICON_NAME:-m5cardputerzero-compass.png}"
CONFIG_DIR="${CONFIG_DIR:-\$HOME/.config/Compass}"
CMAKE_BIN="${CMAKE:-cmake}"
CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE:-Release}"

Expand Down Expand Up @@ -90,9 +89,7 @@ mkdir -p \
"${DIST_DIR}"

install -m 755 "${EXECUTABLE}" "${STAGE_DIR}/usr/share/APPLaunch/bin/${BIN_NAME}"
DESKTOP_EXEC="mkdir -p \"${CONFIG_DIR}\" && COMPASS_CONFIG_DIR=\"${CONFIG_DIR}\" exec /usr/share/APPLaunch/bin/${BIN_NAME}"
sed \
-e "s|@DESKTOP_EXEC@|${DESKTOP_EXEC}|g" \
-e "s|@PACKAGE_ICON_NAME@|${PACKAGE_ICON_NAME}|g" \
"${DESKTOP_TEMPLATE}" >"${STAGE_DIR}/usr/share/APPLaunch/applications/compass.desktop"
install -m 644 "${ICON_FILE}" "${STAGE_DIR}/usr/share/APPLaunch/share/images/${PACKAGE_ICON_NAME}"
Expand Down
27 changes: 20 additions & 7 deletions src/models/calibration_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ namespace compass {

namespace {

constexpr uint32_t kAutoFinishMs = 20000;
constexpr uint32_t kAutoFinishMs = 20000;
constexpr uint32_t kMinimumCalibrationSamples = 20;
constexpr float kMinimumAxisSpan = 0.01f;
constexpr float kCoverageTarget = 80.0f;
constexpr const char* kCalibrationPathEnv = "COMPASS_CALIBRATION_PATH";
constexpr const char* kConfigDirEnv = "COMPASS_CONFIG_DIR";
constexpr const char* kCalibrationFileName = "calibration.conf";
constexpr float kMinimumAxisSpan = 0.01f;
constexpr float kCoverageTarget = 80.0f;
constexpr const char* kCalibrationPathEnv = "COMPASS_CALIBRATION_PATH";
constexpr const char* kConfigDirEnv = "COMPASS_CONFIG_DIR";
constexpr const char* kCalibrationFileName = "calibration.conf";

float axisValue(const Axis3& value, size_t index)
{
Expand Down Expand Up @@ -68,6 +68,19 @@ bool envValue(const char* key, std::filesystem::path& path)
return true;
}

std::filesystem::path defaultConfigDir()
{
#if COMPASS_USE_MOCK_IMU
return ".";
#else
const char* home = std::getenv("HOME");
if (home && home[0] != '\0') {
return std::filesystem::path(home) / ".config" / "Compass";
}
return "/tmp/Compass";
#endif
}

float configFloat(const std::unordered_map<std::string, std::string>& values, const char* key, float fallback)
{
const auto it = values.find(key);
Expand Down Expand Up @@ -182,7 +195,7 @@ std::filesystem::path CalibrationModel::configPath()
#if COMPASS_USE_MOCK_IMU
return kCalibrationFileName;
#else
return std::filesystem::path("/var/lib/Compass") / kCalibrationFileName;
return defaultConfigDir() / kCalibrationFileName;
#endif
}

Expand Down
Loading