mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-09-19 02:04:31 -04:00
46 lines
42 KiB
HTML
46 lines
42 KiB
HTML
<!DOCTYPE html> <html lang="en-US"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=Edge"> <link rel="stylesheet" href="/Meshtastic-Android/assets/css/just-the-docs-default.css"> <link rel="stylesheet" href="/Meshtastic-Android/assets/css/just-the-docs-head-nav.css" id="jtd-head-nav-stylesheet"> <style id="jtd-nav-activation"> .site-nav > ul.nav-list:first-child > li > a, .site-nav > ul.nav-list:first-child > li > ul > li:not(:nth-child(9)) > a, .site-nav > ul.nav-list:first-child > li > ul > li > ul > li a { background-image: none; } .site-nav > ul.nav-list:not(:first-child) a, .site-nav li.external a { background-image: none; } .site-nav > ul.nav-list:first-child > li:nth-child(3) > ul > li:nth-child(9) > a { font-weight: 600; text-decoration: none; }.site-nav > ul.nav-list:first-child > li:nth-child(3) > button svg, .site-nav > ul.nav-list:first-child > li:nth-child(3) > ul > li:nth-child(9) > button svg { transform: rotate(-90deg); }.site-nav > ul.nav-list:first-child > li.nav-list-item:nth-child(3) > ul.nav-list, .site-nav > ul.nav-list:first-child > li.nav-list-item:nth-child(3) > ul.nav-list > li.nav-list-item:nth-child(9) > ul.nav-list { display: block; } </style> <script src="/Meshtastic-Android/assets/js/vendor/lunr.min.js"></script> <script src="/Meshtastic-Android/assets/js/just-the-docs.js"></script> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Begin Jekyll SEO tag v2.9.0 --> <title>Measurement & Formatting | Meshtastic Android</title> <meta name="generator" content="Jekyll v4.4.1" /> <meta property="og:title" content="Measurement & Formatting" /> <meta property="og:locale" content="en_US" /> <meta name="description" content="User and developer documentation for the Meshtastic Android, Desktop, and iOS applications." /> <meta name="twitter:description" property="og:description" content="User and developer documentation for the Meshtastic Android, Desktop, and iOS applications." /> <link rel="canonical" href="/Meshtastic-Android/en/developer/measurement.html" /> <meta property="og:url" content="/Meshtastic-Android/en/developer/measurement.html" /> <meta property="og:site_name" content="Meshtastic Android" /> <meta property="og:type" content="website" /> <meta name="twitter:card" content="summary" /> <meta name="twitter:title" content="Measurement & Formatting" /> <script type="application/ld+json"> {"@context":"https://schema.org","@type":"WebPage","description":"User and developer documentation for the Meshtastic Android, Desktop, and iOS applications.","headline":"Measurement & Formatting","url":"/Meshtastic-Android/en/developer/measurement.html"}</script> <!-- End Jekyll SEO tag --> <!-- Inter font from Google Fonts --> <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet"> <style> /* M3-inspired typography */ :root { --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif; --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', ui-monospace, monospace; } body, .site-title, .search-input { font-family: var(--font-sans) !important; } code, pre, .highlight { font-family: var(--font-mono) !important; font-size: 0.875em; } /* M3 surface elevation & rounding */ .main-content table { border-radius: 12px; overflow: hidden; } .main-content blockquote { border-radius: 12px; padding: 1rem 1.25rem; border-left-width: 4px; } .main-content pre { border-radius: 12px; } .main-content code { border-radius: 6px; padding: 0.15em 0.4em; } /* Smooth transitions for theme switching */ body, .side-bar, .main, .main-content, .site-header, .search-input, .search-results, a { transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease; } /* Theme toggle button styling */ .theme-toggle { background: none; border: 1px solid var(--border-color, #D5D6E0); border-radius: 20px; padding: 6px 12px; cursor: pointer; font-family: var(--font-sans); font-size: 0.75rem; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; color: inherit; margin: 0 auto; transition: background-color 0.2s ease, border-color 0.2s ease; } .theme-toggle:hover { background-color: rgba(128, 128, 128, 0.1); } .theme-toggle-wrap { text-align: center; padding: 12px 0 4px; } /* Heading weight refinement */ h1, h2, h3, h4, h5, h6 { font-weight: 600; letter-spacing: -0.01em; } h1 { font-weight: 700; letter-spacing: -0.02em; } /* Smooth anchor scroll */ html { scroll-behavior: smooth; } /* Language switcher */ .language-switcher { display: inline-block; position: relative; margin-left: 8px; } .language-switcher-btn { cursor: pointer; font-size: 0.8rem; font-weight: 500; font-family: var(--font-sans); list-style: none; padding: 4px 10px; border: 1px solid var(--border-color, #D5D6E0); border-radius: 16px; display: inline-flex; align-items: center; gap: 4px; transition: background-color 0.2s ease; } .language-switcher-btn:hover { background-color: rgba(128, 128, 128, 0.1); } .language-switcher[open] .language-switcher-list { display: block; } .language-switcher-list { position: absolute; top: 100%; right: 0; left: auto; z-index: 100; list-style: none; padding: 8px 0; margin: 4px 0 0; min-width: 140px; background: var(--body-background-color, #fff); border: 1px solid var(--border-color, #D5D6E0); border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); } .language-switcher-list li { padding: 0; } .language-switcher-list a { display: block; padding: 6px 16px; text-decoration: none; font-size: 0.85rem; color: inherit; } .language-switcher-list a:hover { background-color: rgba(103, 234, 148, 0.15); } /* Version switcher (shares the language-switcher dropdown styling) */ .version-switcher { margin-left: 8px; } .version-switcher[hidden] { display: none; } /* Link out to the upstream meshtastic.org docs */ .upstream-docs-link { display: inline-flex; align-items: center; margin-left: 8px; padding: 4px 10px; border: 1px solid var(--border-color, #D5D6E0); border-radius: 16px; font-size: 0.8rem; font-weight: 500; font-family: var(--font-sans); text-decoration: none; color: inherit; transition: background-color 0.2s ease; } .upstream-docs-link:hover { background-color: rgba(128, 128, 128, 0.1); } </style> <script> // Respect OS preference on first visit, then remember user choice (function() { var stored = localStorage.getItem('jtd-theme'); if (stored) return; // will be applied by jtd.setTheme below if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { localStorage.setItem('jtd-theme', 'meshtastic-dark'); } })(); </script> </head> <body> <a class="skip-to-main" href="#main-content">Skip to main content</a> <svg xmlns="http://www.w3.org/2000/svg" class="d-none"> <symbol id="svg-link" viewBox="0 0 24 24"> <title>Link</title> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-link"> <path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path> </svg> </symbol> <symbol id="svg-menu" viewBox="0 0 24 24"> <title>Menu</title> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-menu"> <line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="18" x2="21" y2="18"></line> </svg> </symbol> <symbol id="svg-arrow-right" viewBox="0 0 24 24"> <title>Expand</title> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-right"> <polyline points="9 18 15 12 9 6"></polyline> </svg> </symbol> <!-- Feather. MIT License: https://github.com/feathericons/feather/blob/master/LICENSE --> <symbol id="svg-external-link" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-external-link"> <title id="svg-external-link-title">(external link)</title> <path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path><polyline points="15 3 21 3 21 9"></polyline><line x1="10" y1="14" x2="21" y2="3"></line> </symbol> <symbol id="svg-doc" viewBox="0 0 24 24"> <title>Document</title> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-file"> <path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"></path><polyline points="13 2 13 9 20 9"></polyline> </svg> </symbol> <symbol id="svg-search" viewBox="0 0 24 24"> <title>Search</title> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search"> <circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line> </svg> </symbol> <!-- Bootstrap Icons. MIT License: https://github.com/twbs/icons/blob/main/LICENSE.md --> <symbol id="svg-copy" viewBox="0 0 16 16"> <title>Copy</title> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-clipboard" viewBox="0 0 16 16"> <path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/> <path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/> </svg> </symbol> <symbol id="svg-copied" viewBox="0 0 16 16"> <title>Copied</title> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-clipboard-check-fill" viewBox="0 0 16 16"> <path d="M6.5 0A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3Zm3 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3Z"/> <path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1A2.5 2.5 0 0 1 9.5 5h-3A2.5 2.5 0 0 1 4 2.5v-1Zm6.854 7.354-3 3a.5.5 0 0 1-.708 0l-1.5-1.5a.5.5 0 0 1 .708-.708L7.5 10.793l2.646-2.647a.5.5 0 0 1 .708.708Z"/> </svg> </symbol> </svg> <header class="side-bar"> <div class="site-header"> <a href="/Meshtastic-Android/" class="site-title lh-tight"> Meshtastic Android </a> <button id="menu-button" class="site-button btn-reset" aria-label="Menu" aria-expanded="false"> <svg viewBox="0 0 24 24" class="icon" aria-hidden="true"><use xlink:href="#svg-menu"></use></svg> </button> </div> <nav aria-label="Main" id="site-nav" class="site-nav"> <ul class="nav-list"><li class="nav-list-item"><a href="/Meshtastic-Android/en/" class="nav-list-link">Home</a></li><li class="nav-list-item"><button class="nav-list-expander btn-reset" aria-label="User Guide submenu" aria-expanded="false"> <svg viewBox="0 0 24 24" aria-hidden="true"><use xlink:href="#svg-arrow-right"></use></svg> </button><a href="/Meshtastic-Android/en/user.html" class="nav-list-link">User Guide</a><ul class="nav-list"><li class="nav-list-item"><a href="/Meshtastic-Android/en/user/onboarding.html" class="nav-list-link">Getting Started</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/user/connections.html" class="nav-list-link">Connections</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/user/messages-and-channels.html" class="nav-list-link">Messages & Channels</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/user/nodes.html" class="nav-list-link">Nodes</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/user/node-metrics.html" class="nav-list-link">Node Metrics</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/user/map-and-waypoints.html" class="nav-list-link">Map & Waypoints</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/user/settings-radio-user.html" class="nav-list-link">Settings — Radio & User</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/user/settings-module-admin.html" class="nav-list-link">Settings — Modules & Admin</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/user/telemetry-and-sensors.html" class="nav-list-link">Telemetry & Sensors</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/user/tak.html" class="nav-list-link">TAK Integration</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/user/mqtt.html" class="nav-list-link">MQTT</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/user/discovery.html" class="nav-list-link">Discovery</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/user/firmware.html" class="nav-list-link">Firmware Updates</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/user/desktop.html" class="nav-list-link">Desktop App</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/user/signal-meter.html" class="nav-list-link">How the Meshtastic Signal Meter Works</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/user/units-and-locale.html" class="nav-list-link">Units, Measurement & Locale</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/user/translate.html" class="nav-list-link">Translate the App</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/user/android-auto.html" class="nav-list-link">Android Auto</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/user/app-functions.html" class="nav-list-link">App Functions</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/user/widget.html" class="nav-list-link">Home Screen Widget</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/user/help-and-docs.html" class="nav-list-link">Help & In-App Docs</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/user/debug-logs.html" class="nav-list-link">Debug Logs</a></li></ul></li><li class="nav-list-item"><button class="nav-list-expander btn-reset" aria-label="Developer Guide submenu" aria-expanded="false"> <svg viewBox="0 0 24 24" aria-hidden="true"><use xlink:href="#svg-arrow-right"></use></svg> </button><a href="/Meshtastic-Android/en/developer.html" class="nav-list-link">Developer Guide</a><ul class="nav-list"><li class="nav-list-item"><a href="/Meshtastic-Android/en/developer/architecture.html" class="nav-list-link">Architecture</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/developer/codebase.html" class="nav-list-link">Codebase</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/developer/adding-a-feature-module.html" class="nav-list-link">Adding a Feature Module</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/developer/navigation-and-deep-links.html" class="nav-list-link">Navigation & Deep Links</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/developer/transport.html" class="nav-list-link">Transport</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/developer/persistence.html" class="nav-list-link">Persistence</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/developer/testing.html" class="nav-list-link">Testing</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/developer/contributing.html" class="nav-list-link">Contributing</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/developer/measurement.html" class="nav-list-link">Measurement & Formatting</a></li><li class="nav-list-item"><a href="/Meshtastic-Android/en/developer/test-builds.html" class="nav-list-link">Test Builds & Obtainium</a></li></ul></li></ul> </nav> <div class="d-md-block d-sm-none"> <div class="site-footer"> This site uses <a href="https://github.com/just-the-docs/just-the-docs">Just the Docs</a>, a documentation theme for Jekyll. </div> </div> </header> <div class="main" id="top"> <div id="main-header" class="main-header"> <div class="search" role="search"> <div class="search-input-wrap"> <input type="text" id="search-input" class="search-input" tabindex="0" placeholder="Search Meshtastic Android" autocomplete="off"> <label for="search-input" class="search-label"> <span class="sr-only">Search Meshtastic Android</span> <svg viewBox="0 0 24 24" class="search-icon" aria-hidden="true"><use xlink:href="#svg-search"></use></svg> </label> </div> <div id="search-results" class="search-results"></div> </div> <div class="theme-toggle-wrap"> <button class="theme-toggle" id="theme-toggle" aria-label="Toggle dark mode" title="Toggle light/dark theme" onclick="toggleMeshtasticTheme()"> <span id="theme-icon">🌙</span> <span id="theme-label">Dark</span> </button> <details class="language-switcher version-switcher" id="version-switcher" aria-label="Documentation version" hidden> <summary class="language-switcher-btn" title="Switch documentation version"> 🏷️ <span id="version-current"></span> </summary> <ul class="language-switcher-list" id="version-switcher-list"></ul> </details> <script> (function() { var baseurl = '/Meshtastic-Android'; var root = baseurl; var channel = 'latest'; // /main/, /vX.Y.Z/ or a prerelease snapshot like /v2.8.0-open.1/. var match = baseurl.match(/^(.*)\/(main|v\d+\.\d+\.\d+(?:-(?:open|closed)\.\d+)?)$/); if (match) { root = match[1]; channel = match[2]; } fetch(root + '/versions.json') .then(function(res) { return res.ok ? res.json() : Promise.reject(); }) .then(function(data) { var switcher = document.getElementById('version-switcher'); var list = document.getElementById('version-switcher-list'); var current = document.getElementById('version-current'); if (!switcher || !list || !current) return; // Keep the reader on the same page when switching channels; a page // that doesn't exist in the target version lands on the 404 page. var relativePath = location.pathname.slice(baseurl.length) + location.hash; var entries = []; if (data.latest) { entries.push({ id: 'latest', label: 'latest (v' + data.latest + ')', base: root }); } // Prereleases are documented ahead of general availability, so the track // is always spelled out — a reader must not mistake a closed-testing // snapshot for a shipped release. (data.prereleases || []).forEach(function(p) { entries.push({ id: p.dir, label: p.dir.replace(/^v/, 'v') + ' — ' + p.track + ' testing', base: root + '/' + p.dir }); }); if (data.hasMain) { entries.push({ id: 'main', label: 'main (unreleased snapshot)', base: root + '/main' }); } (data.versions || []).forEach(function(v) { entries.push({ id: 'v' + v, label: 'v' + v, base: root + '/v' + v }); }); var currentEntry = entries.filter(function(e) { return e.id === channel; })[0]; current.textContent = currentEntry ? currentEntry.label : channel; var others = entries.filter(function(e) { return e.id !== channel; }); if (others.length === 0) return; others.forEach(function(e) { var li = document.createElement('li'); var a = document.createElement('a'); a.href = e.base + relativePath; a.textContent = e.label; li.appendChild(a); list.appendChild(li); }); switcher.hidden = false; }) .catch(function() { /* no manifest (local build) — leave switcher hidden */ }); })(); </script> <a class="upstream-docs-link" href="https://meshtastic.org/docs/" title="Official Meshtastic documentation (meshtastic.org)">Meshtastic Docs ↗</a> </div> <script> function toggleMeshtasticTheme() { var current = localStorage.getItem('jtd-theme') || 'meshtastic'; var next = (current === 'meshtastic-dark') ? 'meshtastic' : 'meshtastic-dark'; if (typeof jtd !== 'undefined' && typeof jtd.setTheme === 'function') { jtd.setTheme(next); } localStorage.setItem('jtd-theme', next); var icon = document.getElementById('theme-icon'); var label = document.getElementById('theme-label'); if (icon && label) { icon.textContent = (next === 'meshtastic-dark') ? '☀️' : '🌙'; label.textContent = (next === 'meshtastic-dark') ? 'Light' : 'Dark'; } } // Apply stored/OS theme on page load (function() { var theme = localStorage.getItem('jtd-theme') || 'meshtastic'; // Sync toggle label immediately var icon = document.getElementById('theme-icon'); var label = document.getElementById('theme-label'); if (icon && label) { icon.textContent = (theme === 'meshtastic-dark') ? '☀️' : '🌙'; label.textContent = (theme === 'meshtastic-dark') ? 'Light' : 'Dark'; } // Apply theme once jtd is ready function tryApply() { if (typeof jtd !== 'undefined' && typeof jtd.setTheme === 'function') { jtd.setTheme(theme); } else { setTimeout(tryApply, 50); } } tryApply(); })(); </script> </div> <div class="main-content-wrap"> <nav aria-label="Breadcrumb" class="breadcrumb-nav"> <ol class="breadcrumb-nav-list"> <li class="breadcrumb-nav-list-item"><a href="/Meshtastic-Android/en/developer.html">Developer Guide</a></li> <li class="breadcrumb-nav-list-item"><span>Measurement & Formatting</span></li> </ol> </nav> <div id="main-content" class="main-content"> <main> <h1 id="measurement--formatting"> <a href="#measurement--formatting" class="anchor-heading" aria-labelledby="measurement--formatting"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Measurement & Formatting </h1> <p>How the Meshtastic Android/KMP app formats numbers, units, and locale-sensitive values.</p><hr /> <h2 id="overview"> <a href="#overview" class="anchor-heading" aria-labelledby="overview"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Overview </h2> <p>All measurement data transmitted by Meshtastic radios uses <strong>metric units</strong> (meters, °C, hPa, m/s, etc.). The app converts and formats these values for display using two core utilities:</p> <div class="table-wrapper"><table> <thead> <tr> <th>Utility</th> <th>Location</th> <th>Purpose</th> </tr> </thead> <tbody> <tr> <td><code class="language-plaintext highlighter-rouge">MetricFormatter</code></td> <td><code class="language-plaintext highlighter-rouge">core/common/.../util/MetricFormatter.kt</code></td> <td>Converts and formats physical measurements (temperature, pressure, speed, etc.)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">NumberFormatter</code></td> <td><code class="language-plaintext highlighter-rouge">core/common/.../util/NumberFormatter.kt</code></td> <td>Low-level fixed-point number formatting with locale-independent dot separator</td> </tr> </tbody> </table></div> <p>Both live in <code class="language-plaintext highlighter-rouge">org.meshtastic.core.common.util</code> and are available to all KMP targets (Android, Desktop, iOS).</p><hr /> <h2 id="metricformatter-api"> <a href="#metricformatter-api" class="anchor-heading" aria-labelledby="metricformatter-api"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> MetricFormatter API </h2> <p><code class="language-plaintext highlighter-rouge">MetricFormatter</code> is a Kotlin <code class="language-plaintext highlighter-rouge">object</code> with pure functions for each measurement type:</p> <div class="language-kotlin highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">object</span> <span class="nc">MetricFormatter</span> <span class="p">{</span>
|
||
<span class="k">fun</span> <span class="nf">temperature</span><span class="p">(</span><span class="n">celsius</span><span class="p">:</span> <span class="nc">Float</span><span class="p">,</span> <span class="n">isFahrenheit</span><span class="p">:</span> <span class="nc">Boolean</span><span class="p">):</span> <span class="nc">String</span>
|
||
<span class="k">fun</span> <span class="nf">voltage</span><span class="p">(</span><span class="n">volts</span><span class="p">:</span> <span class="nc">Float</span><span class="p">,</span> <span class="n">decimalPlaces</span><span class="p">:</span> <span class="nc">Int</span> <span class="p">=</span> <span class="mi">2</span><span class="p">):</span> <span class="nc">String</span>
|
||
<span class="k">fun</span> <span class="nf">current</span><span class="p">(</span><span class="n">milliAmps</span><span class="p">:</span> <span class="nc">Float</span><span class="p">,</span> <span class="n">decimalPlaces</span><span class="p">:</span> <span class="nc">Int</span> <span class="p">=</span> <span class="mi">1</span><span class="p">):</span> <span class="nc">String</span>
|
||
<span class="k">fun</span> <span class="nf">percent</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="nc">Float</span><span class="p">,</span> <span class="n">decimalPlaces</span><span class="p">:</span> <span class="nc">Int</span> <span class="p">=</span> <span class="mi">1</span><span class="p">):</span> <span class="nc">String</span>
|
||
<span class="k">fun</span> <span class="nf">humidity</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="nc">Float</span><span class="p">):</span> <span class="nc">String</span>
|
||
<span class="k">fun</span> <span class="nf">pressure</span><span class="p">(</span><span class="n">hPa</span><span class="p">:</span> <span class="nc">Float</span><span class="p">,</span> <span class="n">decimalPlaces</span><span class="p">:</span> <span class="nc">Int</span> <span class="p">=</span> <span class="mi">1</span><span class="p">):</span> <span class="nc">String</span>
|
||
<span class="k">fun</span> <span class="nf">snr</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="nc">Float</span><span class="p">,</span> <span class="n">decimalPlaces</span><span class="p">:</span> <span class="nc">Int</span> <span class="p">=</span> <span class="mi">1</span><span class="p">):</span> <span class="nc">String</span>
|
||
<span class="k">fun</span> <span class="nf">rssi</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="nc">Int</span><span class="p">):</span> <span class="nc">String</span>
|
||
<span class="k">fun</span> <span class="nf">windSpeed</span><span class="p">(</span><span class="n">metersPerSecond</span><span class="p">:</span> <span class="nc">Float</span><span class="p">,</span> <span class="n">isImperial</span><span class="p">:</span> <span class="nc">Boolean</span><span class="p">,</span> <span class="n">decimalPlaces</span><span class="p">:</span> <span class="nc">Int</span> <span class="p">=</span> <span class="mi">1</span><span class="p">):</span> <span class="nc">String</span>
|
||
<span class="k">fun</span> <span class="nf">rainfall</span><span class="p">(</span><span class="n">millimeters</span><span class="p">:</span> <span class="nc">Float</span><span class="p">,</span> <span class="n">isImperial</span><span class="p">:</span> <span class="nc">Boolean</span><span class="p">,</span> <span class="n">decimalPlaces</span><span class="p">:</span> <span class="nc">Int</span> <span class="p">=</span> <span class="mi">1</span><span class="p">):</span> <span class="nc">String</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div> <h3 id="usage"> <a href="#usage" class="anchor-heading" aria-labelledby="usage"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Usage </h3> <div class="language-kotlin highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">// Temperature — Fahrenheit conversion is handled automatically</span>
|
||
<span class="nc">MetricFormatter</span><span class="p">.</span><span class="nf">temperature</span><span class="p">(</span><span class="mf">22.5f</span><span class="p">,</span> <span class="n">isFahrenheit</span> <span class="p">=</span> <span class="k">true</span><span class="p">)</span> <span class="c1">// "72.5°F"</span>
|
||
<span class="nc">MetricFormatter</span><span class="p">.</span><span class="nf">temperature</span><span class="p">(</span><span class="mf">22.5f</span><span class="p">,</span> <span class="n">isFahrenheit</span> <span class="p">=</span> <span class="k">false</span><span class="p">)</span> <span class="c1">// "22.5°C"</span>
|
||
|
||
<span class="c1">// Signal metrics</span>
|
||
<span class="nc">MetricFormatter</span><span class="p">.</span><span class="nf">snr</span><span class="p">(-</span><span class="mf">5.2f</span><span class="p">)</span> <span class="c1">// "-5.2 dB"</span>
|
||
<span class="nc">MetricFormatter</span><span class="p">.</span><span class="nf">rssi</span><span class="p">(-</span><span class="mi">97</span><span class="p">)</span> <span class="c1">// "-97 dBm"</span>
|
||
|
||
<span class="c1">// Environment</span>
|
||
<span class="nc">MetricFormatter</span><span class="p">.</span><span class="nf">pressure</span><span class="p">(</span><span class="mf">1013.25f</span><span class="p">)</span> <span class="c1">// "1013.3 hPa"</span>
|
||
<span class="nc">MetricFormatter</span><span class="p">.</span><span class="nf">humidity</span><span class="p">(</span><span class="mf">65.0f</span><span class="p">)</span> <span class="c1">// "65%"</span>
|
||
<span class="nc">MetricFormatter</span><span class="p">.</span><span class="nf">windSpeed</span><span class="p">(</span><span class="mf">3.7f</span><span class="p">,</span> <span class="n">isImperial</span> <span class="p">=</span> <span class="k">false</span><span class="p">)</span> <span class="c1">// "3.7 m/s"</span>
|
||
<span class="nc">MetricFormatter</span><span class="p">.</span><span class="nf">windSpeed</span><span class="p">(</span><span class="mf">3.7f</span><span class="p">,</span> <span class="n">isImperial</span> <span class="p">=</span> <span class="k">true</span><span class="p">)</span> <span class="c1">// "8.3 mph"</span>
|
||
<span class="nc">MetricFormatter</span><span class="p">.</span><span class="nf">rainfall</span><span class="p">(</span><span class="mf">12.3f</span><span class="p">,</span> <span class="n">isImperial</span> <span class="p">=</span> <span class="k">false</span><span class="p">)</span> <span class="c1">// "12.3 mm"</span>
|
||
<span class="nc">MetricFormatter</span><span class="p">.</span><span class="nf">rainfall</span><span class="p">(</span><span class="mf">12.3f</span><span class="p">,</span> <span class="n">isImperial</span> <span class="p">=</span> <span class="k">true</span><span class="p">)</span> <span class="c1">// "0.5 in"</span>
|
||
|
||
<span class="c1">// Power</span>
|
||
<span class="nc">MetricFormatter</span><span class="p">.</span><span class="nf">voltage</span><span class="p">(</span><span class="mf">3.95f</span><span class="p">)</span> <span class="c1">// "3.95 V"</span>
|
||
<span class="nc">MetricFormatter</span><span class="p">.</span><span class="nf">current</span><span class="p">(</span><span class="mf">125.0f</span><span class="p">)</span> <span class="c1">// "125.0 mA"</span>
|
||
</code></pre></div></div><hr /> <h2 id="numberformatter"> <a href="#numberformatter" class="anchor-heading" aria-labelledby="numberformatter"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> NumberFormatter </h2> <p><code class="language-plaintext highlighter-rouge">NumberFormatter</code> provides locale-independent decimal formatting using pure arithmetic (no <code class="language-plaintext highlighter-rouge">String.format</code> or <code class="language-plaintext highlighter-rouge">DecimalFormat</code>):</p> <div class="language-kotlin highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">object</span> <span class="nc">NumberFormatter</span> <span class="p">{</span>
|
||
<span class="k">fun</span> <span class="nf">format</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="nc">Double</span><span class="p">,</span> <span class="n">decimalPlaces</span><span class="p">:</span> <span class="nc">Int</span><span class="p">):</span> <span class="nc">String</span>
|
||
<span class="k">fun</span> <span class="nf">format</span><span class="p">(</span><span class="n">value</span><span class="p">:</span> <span class="nc">Float</span><span class="p">,</span> <span class="n">decimalPlaces</span><span class="p">:</span> <span class="nc">Int</span><span class="p">):</span> <span class="nc">String</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div></div> <blockquote> <p><strong>Why locale-independent?</strong> Meshtastic is a mesh networking app where consistency matters — sensor readings shared between nodes should look the same everywhere. <code class="language-plaintext highlighter-rouge">NumberFormatter</code> always uses <code class="language-plaintext highlighter-rouge">.</code> as the decimal separator.</p> </blockquote><hr /> <h2 id="unit-conversion"> <a href="#unit-conversion" class="anchor-heading" aria-labelledby="unit-conversion"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Unit Conversion </h2> <p>Three measurements convert away from metric for display, each gated by a boolean flag sourced from the user’s device locale or preferences:</p> <div class="table-wrapper"><table> <thead> <tr> <th>Measurement</th> <th>Flag</th> <th>Source</th> <th>Conversion</th> </tr> </thead> <tbody> <tr> <td><code class="language-plaintext highlighter-rouge">temperature</code></td> <td><code class="language-plaintext highlighter-rouge">isFahrenheit</code></td> <td><code class="language-plaintext highlighter-rouge">getSystemTemperatureUnit()</code></td> <td><code class="language-plaintext highlighter-rouge">°F = °C × 1.8 + 32</code></td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">windSpeed</code></td> <td><code class="language-plaintext highlighter-rouge">isImperial</code></td> <td><code class="language-plaintext highlighter-rouge">getSystemMeasurementSystem()</code></td> <td>m/s × 2.23694 → mph</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">rainfall</code></td> <td><code class="language-plaintext highlighter-rouge">isImperial</code></td> <td><code class="language-plaintext highlighter-rouge">getSystemMeasurementSystem()</code></td> <td>mm ÷ 25.4 → in</td> </tr> </tbody> </table></div> <p>The two source functions (in <code class="language-plaintext highlighter-rouge">core/common/.../util/MeasurementSystem.kt</code>) are deliberately separate: some locales mix systems (the UK uses miles for distance but Celsius for temperature), so temperature must never be derived from the distance unit. On Android, <code class="language-plaintext highlighter-rouge">getSystemTemperatureUnit()</code> delegates to <code class="language-plaintext highlighter-rouge">androidx.core.text.util.LocalePreferences</code>, which resolves CLDR locale data and honors the Android 14+ Regional preferences temperature override.</p> <p>Everything else (voltage, current, pressure, SNR, RSSI, humidity, percent) displays in its native metric units. The user-facing <a href="../user/units-and-locale">Units & Locale</a> page explains what end users see.</p><hr /> <h2 id="adding-a-new-measurement-type"> <a href="#adding-a-new-measurement-type" class="anchor-heading" aria-labelledby="adding-a-new-measurement-type"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Adding a New Measurement Type </h2> <p>To add a new measurement formatter:</p> <ol> <li> <p><strong>Add a function to <code class="language-plaintext highlighter-rouge">MetricFormatter</code></strong> in <code class="language-plaintext highlighter-rouge">core/common/src/commonMain/kotlin/org/meshtastic/core/common/util/MetricFormatter.kt</code>:</p> <div class="language-kotlin highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">fun</span> <span class="nf">radiation</span><span class="p">(</span><span class="n">microSieverts</span><span class="p">:</span> <span class="nc">Float</span><span class="p">,</span> <span class="n">decimalPlaces</span><span class="p">:</span> <span class="nc">Int</span> <span class="p">=</span> <span class="mi">2</span><span class="p">):</span> <span class="nc">String</span> <span class="p">=</span>
|
||
<span class="s">"${NumberFormatter.format(microSieverts, decimalPlaces)} μSv/h"</span>
|
||
</code></pre></div> </div> </li> <li> <p><strong>Add tests</strong> in <code class="language-plaintext highlighter-rouge">core/common/src/commonTest/</code>:</p> <div class="language-kotlin highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nd">@Test</span>
|
||
<span class="k">fun</span> <span class="nf">radiationFormatting</span><span class="p">()</span> <span class="p">{</span>
|
||
<span class="nf">assertEquals</span><span class="p">(</span><span class="s">"0.15 μSv/h"</span><span class="p">,</span> <span class="nc">MetricFormatter</span><span class="p">.</span><span class="nf">radiation</span><span class="p">(</span><span class="mf">0.15f</span><span class="p">))</span>
|
||
<span class="nf">assertEquals</span><span class="p">(</span><span class="s">"1.23 μSv/h"</span><span class="p">,</span> <span class="nc">MetricFormatter</span><span class="p">.</span><span class="nf">radiation</span><span class="p">(</span><span class="mf">1.234f</span><span class="p">))</span>
|
||
<span class="p">}</span>
|
||
</code></pre></div> </div> </li> <li> <p><strong>Use in UI</strong> — call from any <code class="language-plaintext highlighter-rouge">commonMain</code> composable or ViewModel:</p> <div class="language-kotlin highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nc">Text</span><span class="p">(</span><span class="n">text</span> <span class="p">=</span> <span class="nc">MetricFormatter</span><span class="p">.</span><span class="nf">radiation</span><span class="p">(</span><span class="n">node</span><span class="p">.</span><span class="n">radiationLevel</span><span class="p">))</span>
|
||
</code></pre></div> </div> </li> <li> <p><strong>Run verification</strong>:</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>./gradlew :core:common:allTests
|
||
</code></pre></div> </div> </li> </ol><hr /> <h2 id="dateformatter"> <a href="#dateformatter" class="anchor-heading" aria-labelledby="dateformatter"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> DateFormatter </h2> <p>Date and time formatting uses the <code class="language-plaintext highlighter-rouge">DateFormatter</code> <code class="language-plaintext highlighter-rouge">expect object</code> with platform-specific <code class="language-plaintext highlighter-rouge">actual</code> implementations:</p> <div class="table-wrapper"><table> <thead> <tr> <th>Function</th> <th>Output Example</th> </tr> </thead> <tbody> <tr> <td><code class="language-plaintext highlighter-rouge">formatRelativeTime()</code></td> <td>“5 min ago”</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">formatDateTime()</code></td> <td>“May 13, 2026 2:30 PM”</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">formatShortDate()</code></td> <td>“May 13”</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">formatTime()</code></td> <td>“2:30 PM”</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">formatTimeWithSeconds()</code></td> <td>“2:30:45 PM”</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">formatDate()</code></td> <td>“2026-05-13”</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">formatDateTimeShort()</code></td> <td>“5/13/26 2:30 PM”</td> </tr> </tbody> </table></div> <p>Unlike <code class="language-plaintext highlighter-rouge">MetricFormatter</code>, <code class="language-plaintext highlighter-rouge">DateFormatter</code> is declared with <code class="language-plaintext highlighter-rouge">expect</code>/<code class="language-plaintext highlighter-rouge">actual</code> (an <code class="language-plaintext highlighter-rouge">expect object</code> in <code class="language-plaintext highlighter-rouge">commonMain</code>, an <code class="language-plaintext highlighter-rouge">actual object</code> per platform) because date formatting inherently depends on platform locale APIs.</p><hr /> <h2 id="design-decisions"> <a href="#design-decisions" class="anchor-heading" aria-labelledby="design-decisions"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Design Decisions </h2> <div class="table-wrapper"><table> <thead> <tr> <th>Decision</th> <th>Rationale</th> </tr> </thead> <tbody> <tr> <td>Locale-independent decimal separator (<code class="language-plaintext highlighter-rouge">.</code>)</td> <td>Mesh data shared between nodes must be consistent</td> </tr> <tr> <td>Pure arithmetic formatting (no <code class="language-plaintext highlighter-rouge">DecimalFormat</code>)</td> <td>Works identically on JVM, Native, and JS targets</td> </tr> <tr> <td>Only temperature, wind speed, and rainfall convert</td> <td>The remaining metric units are universally understood in their native form</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">object</code> singleton pattern</td> <td>Stateless utility — no instance management needed</td> </tr> </tbody> </table></div><hr /> <h2 id="related"> <a href="#related" class="anchor-heading" aria-labelledby="related"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Related </h2> <ul> <li><strong>User-facing docs</strong>: <a href="../user/units-and-locale">Units & Locale</a> explains what end users see</li> <li><strong>Source code</strong>: <code class="language-plaintext highlighter-rouge">core/common/src/commonMain/kotlin/org/meshtastic/core/common/util/MetricFormatter.kt</code></li> <li><strong>Tests</strong>: <code class="language-plaintext highlighter-rouge">core/common/src/commonTest/kotlin/org/meshtastic/core/common/util/MetricFormatterTest.kt</code></li> </ul> </main> <hr> <footer> <footer class="site-footer"> Copyright © 2026 Meshtastic LLC. Distributed under the <a href="https://www.gnu.org/licenses/gpl-3.0.html">GPL v3 License.</a> </footer> <div class="d-sm-block d-md-none"> <div class="mt-4 fs-2"> This site uses <a href="https://github.com/just-the-docs/just-the-docs">Just the Docs</a>, a documentation theme for Jekyll. </div> </div> </footer> </div> </div> <div class="search-overlay"></div> </div> </body> </html>
|