优化了火箭模拟发射台

main
mula.liu 2026-10-21 14:52:28 +08:00
parent 4d3cdf11d3
commit 3ad329460c
17 changed files with 712 additions and 150 deletions

View File

@ -389,7 +389,7 @@ class TerminalService:
return grouped
@staticmethod
def _pick_events(events: List[CelestialEvent], limit: int = 3) -> List[dict]:
def _pick_events(events: List[CelestialEvent], limit: int = 4) -> List[dict]:
"""Upcoming events first, then the most recent past ones."""
now = datetime.utcnow()
upcoming = sorted((e for e in events if e.event_time >= now), key=lambda e: e.event_time)
@ -411,8 +411,8 @@ class TerminalService:
# Rockets (平台管理 -> 火箭型号 里启用的那些)
# ------------------------------------------------------------------
#: 详情页右栏一次最多列几条发射任务,屏宽只放得下三行
_ROCKET_EVENT_LIMIT = 3
#: 详情页右栏一次最多列几条发射任务(固件详情页现在排四行)
_ROCKET_EVENT_LIMIT = 4
@staticmethod
def _kn(newtons) -> Optional[float]:

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 KiB

View File

@ -6,7 +6,7 @@ import type { OrbitControls as OrbitControlsImpl } from 'three-stdlib';
import type { RocketConfig, SimulationState } from './types';
import { useOptionalTexture } from '../../hooks/useOptionalTexture';
import { RocketModel } from './RocketModel';
import { clamp, fogColor, groundDrop, separationAge, skyColor, starOpacity } from './sceneMath';
import { clamp, fogColor, groundDrop, separationAge, skyColor, starOpacity, stageGeometry } from './sceneMath';
export type CameraMode = 'follow' | 'global';
@ -22,12 +22,14 @@ interface RocketFlightSceneProps {
const EARTH_RADIUS_METERS = 6_371_000;
const EARTH_RADIUS = 34;
const EARTH_DAY_TEXTURE = '/upload/assets/2k_earth_daymap.jpg';
const EARTH_NIGHT_TEXTURE = '/upload/assets/2k_earth_nightmap.jpg';
// 夜间改用「夜半球」合成图:原图只有城市灯光,几乎看不出大陆轮廓,
// 这里叠加了压暗的昼间地表 + 海岸线辉光(生成脚本 scripts/gen_night_earth.py)
const EARTH_NIGHT_TEXTURE = '/upload/assets/2k_earth_nightrelief.jpg';
const EARTH_CENTER = new THREE.Vector3(0, -EARTH_RADIUS, 0);
const EARTH_ROTATION = new THREE.Euler(0, -1.25, -0.08);
const VIEW_SCALE_CALIBRATION = 0.7;
/** 地球贴图按系统时间取用:06:00-18:00 用昼间图,其余时间用夜间的城市灯光图。 */
/** 地球贴图按系统时间取用:06:00-18:00 用昼间图,其余时间用带大陆轮廓的夜半球图。 */
function earthTexturePath() {
const hour = new Date().getHours();
return hour >= 6 && hour < 18 ? EARTH_DAY_TEXTURE : EARTH_NIGHT_TEXTURE;
@ -81,105 +83,236 @@ function globalFlightFrame(altitude: number, downrange: number, targetAltitude:
};
}
/** 发射场:混凝土地坪 + 导流槽 + 发射台 + 服务塔 + 避雷塔。 */
function LaunchPadStructure() {
const towerHeight = 13;
/**
* 场坪上的一根杆件:在 XY 平面内从 from 连到 to。
* 服务塔与灯杆的桁架都用它拼,避免每根梁都手写一次长度和角度。
*/
function Beam({ from, to, size = 0.13, color = '#5b666d' }: {
from: [number, number];
to: [number, number];
size?: number;
color?: string;
}) {
const dx = to[0] - from[0];
const dy = to[1] - from[1];
return (
<mesh
position={[(from[0] + to[0]) / 2, (from[1] + to[1]) / 2, 0]}
rotation={[0, 0, Math.atan2(dy, dx)]}
>
<boxGeometry args={[Math.hypot(dx, dy), size, size]} />
<meshStandardMaterial color={color} metalness={0.5} roughness={0.52} />
</mesh>
);
}
/**
* 服务塔:四根立柱 + 各层等间距水平横杆,只有水平与竖直两种杆件,
* 顶部一块平台与避雷针,另有两根笔直的摆杆(加注/脐带臂)伸向箭体。
* 整塔高约 15,略高于星舰一级。
*/
function ServiceTower({ height = 15 }: { height?: number }) {
const half = 1.15;
const levels = Array.from({ length: 6 }, (_, index) => 1.3 + index * ((height - 2.2) / 5));
return (
<group>
{/* 混凝土地坪 */}
<mesh position={[0, -0.74, 0]} rotation={[-Math.PI / 2, 0, 0]} receiveShadow>
<circleGeometry args={[130, 64]} />
<meshStandardMaterial color="#2a3630" metalness={0} roughness={1} />
</mesh>
<mesh position={[0, -0.7, 0]} rotation={[-Math.PI / 2, 0, 0]} receiveShadow>
<circleGeometry args={[26, 48]} />
<meshStandardMaterial color="#4a5350" metalness={0.05} roughness={0.95} />
</mesh>
{/* 尾焰熏黑区域 */}
<mesh position={[0, -0.69, 0]} rotation={[-Math.PI / 2, 0, 0]}>
<circleGeometry args={[8.5, 32]} />
<meshStandardMaterial color="#171b1a" metalness={0.1} roughness={1} />
</mesh>
{/* 发射台 + 导流槽 */}
<mesh position={[0, -0.34, 0]} receiveShadow>
<boxGeometry args={[19, 0.7, 13]} />
<meshStandardMaterial color="#6d736f" metalness={0.08} roughness={0.92} />
</mesh>
<mesh position={[0, -0.5, 0]}>
<boxGeometry args={[7.4, 0.6, 15]} />
<meshStandardMaterial color="#1b1f21" metalness={0.3} roughness={0.7} />
</mesh>
{/* 导流锥 */}
<mesh position={[0, -0.18, 0]} rotation={[Math.PI, 0, 0]}>
<coneGeometry args={[3.1, 1.1, 4]} />
<meshStandardMaterial color="#343b3f" metalness={0.4} roughness={0.6} />
</mesh>
{/* 压紧机构 */}
{[[-2.6, -2.6], [2.6, -2.6], [-2.6, 2.6], [2.6, 2.6]].map(([x, z]) => (
<mesh key={`${x}-${z}`} position={[x, 0.1, z]}>
<boxGeometry args={[0.5, 0.9, 0.5]} />
<meshStandardMaterial color="#7c848a" metalness={0.5} roughness={0.5} />
</mesh>
{[-half, half].map((z) => (
<group key={z} position={[0, 0, z]}>
{/* 桁架片:两根立柱 + 各层水平横撑,只保留水平与竖直两种杆件 */}
<Beam from={[-half, 0]} to={[-half, height]} size={0.2} color="#4f5a61" />
<Beam from={[half, 0]} to={[half, height]} size={0.2} color="#4f5a61" />
{levels.map((y) => (
<Beam key={y} from={[-half, y]} to={[half, y]} size={0.11} />
))}
</group>
))}
{/* 首尾两道沿 Z 的系杆,把两片桁架连成一个方正的塔架 */}
{[0.2, height].map((y) => (
<group key={`tie-${y}`}>
{[-half, half].map((x) => (
<mesh key={x} position={[x, y, 0]}>
<boxGeometry args={[0.12, 0.12, half * 2]} />
<meshStandardMaterial color="#69747b" metalness={0.5} roughness={0.52} />
</mesh>
))}
</group>
))}
{/* 服务塔 */}
<group position={[-6.2, 0, 0]}>
{[-1.2, 1.2].map((offset) => (
<mesh key={offset} position={[offset, towerHeight / 2, 0]}>
<boxGeometry args={[0.42, towerHeight, 0.42]} />
<meshStandardMaterial color="#59636a" metalness={0.5} roughness={0.5} />
</mesh>
))}
{[3.2, 6.4, 9.6, 12.2].map((y) => (
<mesh key={y} position={[0, y, 0]}>
<boxGeometry args={[3.4, 0.28, 0.3]} />
<meshStandardMaterial color="#6b757b" metalness={0.45} roughness={0.55} />
</mesh>
))}
{/* 摆杆 / 加注臂 */}
{[5.4, 9.4].map((y, index) => (
<mesh key={y} position={[2.1 + (index === 0 ? 0.6 : 0), y, 0]}>
<boxGeometry args={[3.6, 0.24, 0.5]} />
<meshStandardMaterial color="#78838a" metalness={0.45} roughness={0.5} />
</mesh>
))}
{/* 塔顶工作平台(避雷针只装在四周的避雷塔上) */}
<mesh position={[0, towerHeight + 0.15, 0]}>
<boxGeometry args={[3.2, 0.3, 3.2]} />
<meshStandardMaterial color="#6b757b" metalness={0.45} roughness={0.55} />
</mesh>
{[-1.55, 1.55].map((offset) => (
<mesh key={offset} position={[offset, towerHeight + 0.85, 0]}>
<boxGeometry args={[0.1, 1.1, 3.2]} />
<meshStandardMaterial color="#828c92" metalness={0.4} roughness={0.6} transparent opacity={0.7} />
</mesh>
))}
<mesh position={[0, towerHeight + 0.85, -1.55]}>
<boxGeometry args={[3.2, 1.1, 0.1]} />
<meshStandardMaterial color="#828c92" metalness={0.4} roughness={0.6} transparent opacity={0.7} />
</mesh>
</group>
{/* 避雷塔(四根柱子顶部的避雷针) */}
{[[-14, -9], [14, -9], [-14, 9], [14, 9]].map(([x, z]) => (
<group key={`${x}-${z}`} position={[x, 0, z]}>
<mesh position={[0, 7.5, 0]}>
<cylinderGeometry args={[0.16, 0.28, 15, 8]} />
<meshStandardMaterial color="#4c555b" metalness={0.5} roughness={0.55} />
</mesh>
<mesh position={[0, 15.4, 0]}>
<cylinderGeometry args={[0.03, 0.07, 1.6, 6]} />
<meshStandardMaterial color="#aeb7bd" metalness={0.7} roughness={0.35} />
{/* 摆杆:靠箭一侧的加注/脐带臂,水平伸到箭体根部外侧 */}
{[6.2, 10.6].map((y) => (
<group key={y} position={[0, y, 0]}>
<mesh position={[2.35, 0, 0]}>
<boxGeometry args={[4.3, 0.22, 0.42]} />
<meshStandardMaterial color="#78838a" metalness={0.5} roughness={0.48} />
</mesh>
</group>
))}
{/* 场坪编号,让地坪有尺度参照 */}
<mesh position={[0, -0.68, 12]} rotation={[-Math.PI / 2, 0, 0]}>
<planeGeometry args={[6, 1.2]} />
<meshStandardMaterial color="#8b949e" metalness={0} roughness={0.9} />
{/* 塔顶平台与避雷针 */}
<mesh position={[0, height + 0.12, 0]} castShadow>
<boxGeometry args={[2.9, 0.26, 2.9]} />
<meshStandardMaterial color="#6b757b" metalness={0.45} roughness={0.55} />
</mesh>
<mesh position={[0, height + 1.1, 0]}>
<boxGeometry args={[0.07, 1.7, 0.07]} />
<meshStandardMaterial color="#8b959b" metalness={0.6} roughness={0.4} />
</mesh>
</group>
);
}
/** 避雷塔:锥形钢杆 + 塔尖避雷针。 */
function LightningMast({ position, height = 17 }: { position: [number, number, number]; height?: number }) {
return (
<group position={position}>
<mesh position={[0, height / 2, 0]}>
<cylinderGeometry args={[0.14, 0.3, height, 8]} />
<meshStandardMaterial color="#4c555b" metalness={0.5} roughness={0.55} />
</mesh>
<mesh position={[0, height + 0.8, 0]}>
<cylinderGeometry args={[0.02, 0.07, 1.6, 6]} />
<meshStandardMaterial color="#aeb7bd" metalness={0.7} roughness={0.35} />
</mesh>
</group>
);
}
/**
* 发射场:场坪 + 环形消防道 + 发射台与导流槽 + 喷水环 + 服务塔 + 避雷塔
* + 灯杆 / 掩体 / 水罐,尽量让镜头拉远时仍认得出是一座发射场。
*/
function LaunchPadStructure() {
const masts: [number, number][] = [[-13, -9.5], [13, -9.5], [-13, 9.5], [13, 9.5]];
return (
<group>
{/* 场坪外围:草地尽量铺远,靠雾自然收边,避免圆盘边缘悬在空中 */}
<mesh position={[0, -0.78, 0]} rotation={[-Math.PI / 2, 0, 0]} receiveShadow>
<circleGeometry args={[320, 72]} />
<meshStandardMaterial color="#31402f" metalness={0} roughness={1} />
</mesh>
{/* 环形消防车道 */}
<mesh position={[0, -0.735, 0]} rotation={[-Math.PI / 2, 0, 0]} receiveShadow>
<ringGeometry args={[23, 30, 64]} />
<meshStandardMaterial color="#33393c" metalness={0.02} roughness={0.98} />
</mesh>
{/* 混凝土场坪(分两块错开色差,模拟分仓浇筑的伸缩缝) */}
<mesh position={[0, -0.72, 0]} rotation={[-Math.PI / 2, 0, 0]} receiveShadow>
<circleGeometry args={[23, 56]} />
<meshStandardMaterial color="#4d5654" metalness={0.05} roughness={0.95} />
</mesh>
<mesh position={[0, -0.7, 0]} rotation={[-Math.PI / 2, 0, 0]} receiveShadow>
<circleGeometry args={[12, 48]} />
<meshStandardMaterial color="#586160" metalness={0.06} roughness={0.92} />
</mesh>
{/* 安全标线:白色警戒环 + 尾焰熏黑区 */}
<mesh position={[0, -0.685, 0]} rotation={[-Math.PI / 2, 0, 0]}>
<ringGeometry args={[9.4, 9.9, 48]} />
<meshBasicMaterial color="#c9d2d4" transparent opacity={0.5} />
</mesh>
<mesh position={[0, -0.68, 0]} rotation={[-Math.PI / 2, 0, 0]}>
<circleGeometry args={[6.6, 32]} />
<meshStandardMaterial color="#2b302f" metalness={0.1} roughness={1} />
</mesh>
<mesh position={[0, -0.675, 0]} rotation={[-Math.PI / 2, 0, 0]}>
<circleGeometry args={[4.6, 32]} />
<meshStandardMaterial color="#171b1a" metalness={0.1} roughness={1} />
</mesh>
{/* 发射台:左右两块台板中间留出一道导流槽口 */}
{[-3.6, 3.6].map((x) => (
<mesh key={x} position={[x, -0.32, 0]} receiveShadow castShadow>
<boxGeometry args={[4.6, 0.74, 8.4]} />
<meshStandardMaterial color="#6d736f" metalness={0.08} roughness={0.92} />
</mesh>
))}
{/* 导流槽:槽口下方的深井(只画内壁)+ 井底导流锥,进深与台板一致,不外露 */}
<mesh position={[0, -2.25, 0]}>
<boxGeometry args={[3.6, 4.3, 8.1]} />
<meshStandardMaterial color="#20272a" metalness={0.25} roughness={0.88} side={THREE.BackSide} />
</mesh>
<mesh position={[0, -4.0, 0]} rotation={[Math.PI, 0, 0]}>
<coneGeometry args={[1.5, 1.4, 4]} />
<meshStandardMaterial color="#3a4246" metalness={0.45} roughness={0.55} />
</mesh>
{/* 喷水降音环:一圈带喷嘴的管道,点火瞬间由 PadExhaust 接管视觉效果 */}
<mesh position={[0, -0.6, 0]} rotation={[-Math.PI / 2, 0, 0]}>
<torusGeometry args={[7.4, 0.14, 8, 56]} />
<meshStandardMaterial color="#5a656d" metalness={0.6} roughness={0.5} />
</mesh>
{Array.from({ length: 16 }, (_, index) => {
const angle = (index / 16) * Math.PI * 2;
return (
<mesh
key={index}
position={[Math.cos(angle) * 7.4, -0.42, Math.sin(angle) * 7.4]}
rotation={[Math.PI, 0, 0]}
>
<coneGeometry args={[0.12, 0.3, 6]} />
<meshStandardMaterial color="#7d878d" metalness={0.6} roughness={0.45} />
</mesh>
);
})}
<group position={[-5.2, 0, 0]}>
<ServiceTower />
</group>
{masts.map(([x, z]) => (
<LightningMast key={`${x}-${z}`} position={[x, -0.7, z]} />
))}
{/* 高杆灯:灯头用自发光,夜间不至于全黑 */}
{[[-16, 25], [16, 25], [0, -28]].map(([x, z]) => (
<group key={`light-${x}-${z}`} position={[x, -0.7, z]}>
<mesh position={[0, 7, 0]}>
<cylinderGeometry args={[0.12, 0.2, 14, 8]} />
<meshStandardMaterial color="#525b61" metalness={0.5} roughness={0.55} />
</mesh>
<mesh position={[0, 14.2, 0]}>
<boxGeometry args={[2.4, 0.5, 0.7]} />
<meshStandardMaterial
color="#f2f0dd"
emissive="#ffe9b8"
emissiveIntensity={0.9}
metalness={0.2}
roughness={0.5}
/>
</mesh>
</group>
))}
{/* 掩体与储罐:给场坪外围一点尺度参照 */}
<group position={[-24, -0.7, 17]}>
<mesh position={[0, 1.3, 0]} castShadow receiveShadow>
<boxGeometry args={[7.5, 2.6, 5]} />
<meshStandardMaterial color="#5d6663" metalness={0.05} roughness={0.95} />
</mesh>
<mesh position={[0, 2.75, 0]}>
<boxGeometry args={[7.7, 0.3, 5.2]} />
<meshStandardMaterial color="#6c7573" metalness={0.1} roughness={0.9} />
</mesh>
<mesh position={[2.2, 1.5, 2.55]}>
<boxGeometry args={[2.4, 0.5, 0.1]} />
<meshStandardMaterial color="#20272b" metalness={0.3} roughness={0.6} />
</mesh>
</group>
<group position={[27, -0.7, -19]}>
<mesh position={[0, 2.2, 0]}>
<cylinderGeometry args={[3.1, 3.1, 4.4, 24]} />
<meshStandardMaterial color="#7c8489" metalness={0.35} roughness={0.7} />
</mesh>
<mesh position={[0, 4.6, 0]}>
<sphereGeometry args={[3.1, 24, 12, 0, Math.PI * 2, 0, Math.PI / 2]} />
<meshStandardMaterial color="#8d959a" metalness={0.4} roughness={0.6} />
</mesh>
{[0, 1, 2, 3].map((index) => (
<mesh key={index} position={[Math.cos(index * 1.57) * 3.1, 1.1, Math.sin(index * 1.57) * 3.1]}>
<boxGeometry args={[0.16, 2.2, 0.16]} />
<meshStandardMaterial color="#5a6266" metalness={0.5} roughness={0.55} />
</mesh>
))}
</group>
</group>
);
}
@ -233,7 +366,7 @@ function PadExhaust({ state }: { state: SimulationState }) {
}
/** 地面场景容器:随飞行高度下移、随射程后移。 */
function LaunchRack({ state }: { state: SimulationState }) {
function LaunchRack({ state, scale }: { state: SimulationState; scale: number }) {
const groupRef = useRef<THREE.Group>(null);
useFrame(() => {
@ -246,13 +379,20 @@ function LaunchRack({ state }: { state: SimulationState }) {
return (
<group ref={groupRef}>
<LaunchPadStructure />
<PadExhaust state={state} />
{/* 场坪尺寸按箭体粗细缩放:细箭(电子号)不该站在星舰那么大的台子上 */}
<group scale={scale}>
<LaunchPadStructure />
<PadExhaust state={state} />
</group>
</group>
);
}
function EarthSurface({ texture, state }: { texture: THREE.Texture | null; state?: SimulationState }) {
/**
* 高空/轨道视角下的地球。夜半球图本身已经把「月光下的地表 + 海岸辉光 + 城市灯光」
* 烘进贴图,因此不再受方向光影响(否则背对光源的那一面会整片死黑,看不出大陆)。
*/
function EarthSurface({ texture, state, unlit }: { texture: THREE.Texture | null; state?: SimulationState; unlit?: boolean }) {
const highAltitude = state ? state.altitude >= 9_000 : true;
if (!highAltitude) return null;
@ -264,7 +404,11 @@ function EarthSurface({ texture, state }: { texture: THREE.Texture | null; state
<group position={[0, centerY, 0]}>
<mesh rotation={[0, -1.25, -0.08]} receiveShadow>
<sphereGeometry args={[radius, 96, 64]} />
<meshStandardMaterial map={texture ?? undefined} color={texture ? '#ffffff' : '#295c72'} roughness={0.9} metalness={0} />
{unlit ? (
<meshBasicMaterial map={texture ?? undefined} color={texture ? '#ffffff' : '#16283a'} />
) : (
<meshStandardMaterial map={texture ?? undefined} color={texture ? '#ffffff' : '#295c72'} roughness={0.9} metalness={0} />
)}
</mesh>
<mesh>
<sphereGeometry args={[radius * 1.018, 72, 48]} />
@ -329,7 +473,7 @@ function FlightPath({ state, targetAltitude, launchSite }: { state: SimulationSt
return <primitive ref={lineRef} object={line} />;
}
function GlobalEarthView({ rocket, state, texture }: { rocket: RocketConfig; state: SimulationState; texture: THREE.Texture | null }) {
function GlobalEarthView({ rocket, state, texture, unlit }: { rocket: RocketConfig; state: SimulationState; texture: THREE.Texture | null; unlit: boolean }) {
const targetAltitude = rocket.target_orbit_km * 1000;
const launchSite = launchSiteForRocket(rocket);
const frame = globalFlightFrame(state.altitude, state.downrange, targetAltitude, launchSite);
@ -342,7 +486,7 @@ function GlobalEarthView({ rocket, state, texture }: { rocket: RocketConfig; sta
return (
<>
<EarthSurface texture={texture} />
<EarthSurface texture={texture} unlit={unlit} />
<TargetOrbit targetAltitude={targetAltitude} launchSite={launchSite} />
<FlightPath state={state} targetAltitude={targetAltitude} launchSite={launchSite} />
<mesh position={markerPosition}>
@ -469,7 +613,11 @@ function Atmosphere({ state, mode }: { state: SimulationState; mode: CameraMode
function SceneContents({ rocket, state, cameraMode, viewScale, viewScaleResetTrigger, onViewScaleChange }: RocketFlightSceneProps) {
// 只在挂载时取一次小时数,免得一次飞行中途跨过 6/18 点导致贴图来回跳。
const earthTexture = useOptionalTexture(useMemo(() => earthTexturePath(), []));
// 星舰(场景半径约 0.55)用满尺寸场坪,细箭按同比例缩小
const padScale = useMemo(() => clamp(stageGeometry(rocket).radius / 0.55, 0.4, 1), [rocket]);
const earthPath = useMemo(() => earthTexturePath(), []);
const nightEarth = earthPath === EARTH_NIGHT_TEXTURE;
const earthTexture = useOptionalTexture(earthPath);
const manualCameraRef = useRef(false);
const orbitControlsRef = useRef<OrbitControlsImpl>(null);
const manualDistanceRef = useRef<number | null>(null);
@ -520,12 +668,12 @@ function SceneContents({ rocket, state, cameraMode, viewScale, viewScaleResetTri
</group>
{cameraMode === 'follow' ? (
<>
<LaunchRack state={state} />
<EarthSurface texture={earthTexture} state={state} />
<LaunchRack state={state} scale={padScale} />
<EarthSurface texture={earthTexture} state={state} unlit={nightEarth} />
<FollowVehicle rocket={rocket} state={state} />
</>
) : (
<GlobalEarthView rocket={rocket} state={state} texture={earthTexture} />
<GlobalEarthView rocket={rocket} state={state} texture={earthTexture} unlit={nightEarth} />
)}
</>
);

View File

@ -632,7 +632,7 @@ function RocketMission({ rockets }: { rockets: RocketConfig[] }) {
<label className="sx-select sx-select--speed">
<span>倍速 / SPEED</span>
<div className="sx-speed-switch" role="group" aria-label="模拟倍速">
{[1, 2, 4].map((value) => (
{[1, 4, 8].map((value) => (
<button
key={value}
type="button"

View File

@ -0,0 +1,72 @@
#!/usr/bin/env python3
"""生成火箭模拟用的夜间地球贴图。
原始的 2k_earth_nightmap.jpg 只有城市灯光(98% 的像素亮度低于 30),
镜头拉远时几乎看不出大陆轮廓。这里以昼间图为底:
- 保留昼间图的海陆与地形起伏,压暗、去饱和、偏冷,作为「月光下的地球」;
- 沿海岸线加一圈向外衰减的冷色辉光,让大陆轮廓一眼可辨;
- 叠加原夜间图的城市灯光(含少量辉光),只落在陆地上。
全程在线性光域混合,最后再编码回 sRGB。
用法:python3 scripts/gen_night_earth.py
输入/输出都在 backend/upload/assets/ 下(随 git 分发)。
"""
from pathlib import Path
import numpy as np
from PIL import Image, ImageFilter
ASSETS = Path(__file__).resolve().parent.parent / "backend" / "upload" / "assets"
DAY = ASSETS / "2k_earth_daymap.jpg"
NIGHT = ASSETS / "2k_earth_nightmap.jpg"
OUT = ASSETS / "2k_earth_nightrelief.jpg"
# 昼间贴图里海洋是一整块纯色,直接按色距判定海陆
OCEAN_RGB = np.array([30, 59, 117]) / 255.0
def to_linear(c):
return np.where(c <= 0.04045, c / 12.92, ((c + 0.055) / 1.055) ** 2.4)
def to_srgb(c):
return np.where(c <= 0.0031308, c * 12.92, 1.055 * np.power(np.maximum(c, 0), 1 / 2.4) - 0.055)
def blur(mask, sigma):
grown = Image.fromarray((mask * 255).astype("uint8")).filter(ImageFilter.GaussianBlur(sigma))
return np.asarray(grown).astype("float32") / 255.0
def main():
day = np.asarray(Image.open(DAY).convert("RGB")).astype("float32") / 255.0
lights_src = np.asarray(Image.open(NIGHT).convert("RGB")).astype("float32") / 255.0
d, n = to_linear(day), to_linear(lights_src)
# 海陆掩膜先模糊一次再取半阈值,免得沿 JPEG 方块长出毛刺
raw = (np.abs(day - OCEAN_RGB).sum(axis=2) < 0.06).astype("float32")
ocean = blur(raw, 1.2) >= 0.5
ice = day.min(axis=2) > 0.72
lum = d.mean(axis=2, keepdims=True)
land = (0.14 + 0.86 * (d * 0.35 + lum * 0.65)) * 0.175 * np.array([0.78, 0.90, 1.16])
land = land + ice[..., None] * np.array([0.012, 0.017, 0.026])
base = np.where(ocean[..., None], np.array([0.0022, 0.0062, 0.0155]), land)
coast = (blur(ocean, 1.4) * (~ocean))[..., None] * np.array([0.045, 0.068, 0.100])
shelf = (blur(~ocean, 2.4) * ocean)[..., None] * np.array([0.016, 0.030, 0.056])
strength = np.clip(n.mean(axis=2, keepdims=True) * 7, 0, 1)
lights = n * strength * 0.95
bloom = np.asarray(
Image.fromarray((lights.max(axis=2) * 255).clip(0, 255).astype("uint8")).filter(ImageFilter.MaxFilter(3))
).astype("float32") / 255.0
lights = (lights + bloom[..., None] * np.array([0.022, 0.014, 0.007])) * (~ocean)[..., None]
out = (to_srgb(base + coast + shelf + lights).clip(0, 1) * 255).astype("uint8")
Image.fromarray(out).save(OUT, quality=88)
print(f"{OUT.name}: {OUT.stat().st_size // 1024} KB")
if __name__ == "__main__":
main()

View File

@ -579,7 +579,9 @@ static void load_rocket_detail()
/* 模式选择页:两个模式大图标,选完落 NVS,以后开机直达对应列表 */
static void open_mode()
{
g_ui.mode_sel = (g_mode >= 0) ? g_mode : 0;
/* 进去时两格都不高亮:这页是"选一个进去",默认亮着某格会让人以为已经在里面了。
上一次选的模式仍然记在 g_mode 里,设置页照旧显示。 */
g_ui.mode_sel = -1;
set_screen(SC_MODE);
}
@ -737,9 +739,11 @@ static void on_key_press(uint16_t bits)
if (ref) request_code();
break;
case SC_MODE:
if (up && g_ui.mode_sel > 0) { g_ui.mode_sel--; g_dirty = true; }
if (dn && g_ui.mode_sel < 1) { g_ui.mode_sel++; g_dirty = true; }
if (ok) choose_mode(g_ui.mode_sel);
/* 没有高亮时光标先落一格:UP=天体 DN=火箭;两格都已高亮才正常移动 */
if (up && g_ui.mode_sel != 0) { g_ui.mode_sel = 0; g_dirty = true; }
if (dn && g_ui.mode_sel != 1) { g_ui.mode_sel = 1; g_dirty = true; }
/* 一屏都没有高亮 = 还没选,确认不做任何事(点卡片走的是另一条路,不受影响)*/
if (ok && g_ui.mode_sel >= 0) choose_mode(g_ui.mode_sel);
if (ref) { Serial.println("[key] open settings"); set_screen(SC_SETTINGS); }
break;
case SC_SETTINGS:
@ -854,6 +858,12 @@ static void tp_gesture_run(const TpGesture &g)
Serial.printf("[tp] (%d,%d) key=0x%04X idx=%d%s\n",
g.x, g.y, g.bits, g.idx, g.swipe ? " slide" : "");
if (!g.bits) return;
#if BOARD_HAS_BATTERY
if (g.bits == UI_ACT_POWOFF) { /* 设置页的关机键:这板上触摸是唯一一路输入 */
pwr_power_off();
return;
}
#endif
if (g.bits == UI_ACT_TAB) { /* 详情页的分页标签:直接翻到那一页 */
if (g_ui.screen == SC_ROCKET) g_ui.rocket_tab = g.idx;
else g_ui.detail_tab = g.idx;
@ -1403,9 +1413,10 @@ void loop()
忙碌线 120ms 一格(请求已经下来、只剩补图的那段也得继续动),连接页 250ms。 */
{
const uint32_t step = g_ui.busy ? 120 : 250;
/* 设置页的时钟要跳秒。整秒判断放在节流之后:先问再丢弃的话会把那一秒的翻转吃掉,
秒数就地跳两格。 */
const bool clock_tick = (g_ui.screen == SC_SETTINGS) && clock_second_ticked();
/* 设置页的时钟和首页的核子时钟要跳秒。整秒判断放在节流之后:先问再丢弃的话会把那一秒的
翻转吃掉,秒数就地跳两格。 */
const bool clock_tick = (g_ui.screen == SC_SETTINGS || g_ui.screen == SC_MODE) &&
clock_second_ticked();
if ((clock_tick || g_ui.busy || g_ui.screen == SC_CONNECTING) && now - s_anim_last >= step) {
s_anim_last = now;
g_dirty = true;

View File

@ -5,7 +5,7 @@
#include <stdint.h>
#define MAX_BODIES 6
#define MAX_EVENTS 3
#define MAX_EVENTS 4
struct BodyData {
char id[16]; /* 后端天体 id,拉取后台维护的图标要用 */
@ -54,7 +54,7 @@ bool api_icon(const char *base, const char *token, const char *body_id, int size
/* ---------------- 火箭模式 ---------------- */
#define MAX_ROCKETS 12
#define MAX_ROCKET_EV 3
#define MAX_ROCKET_EV 4
struct RocketData {
char code[24]; /* 后端型号 code,拉取立绘要用 */

View File

@ -390,6 +390,22 @@ void disp_add_bitmap(int x, int y, int w, int h, const uint16_t *px, uint8_t sca
}
}
void disp_blit(int x, int y, int w, int h, const uint16_t *px)
{
if (!px) return;
for (int j = 0; j < h; j++) {
int yy = y + j;
if ((unsigned)yy >= LCD_HEIGHT) continue;
const uint16_t *src = px + (size_t)j * w;
uint16_t *dst = s_fb + (size_t)yy * LCD_WIDTH;
for (int i = 0; i < w; i++) {
int xx = x + i;
if ((unsigned)xx >= LCD_WIDTH) continue;
dst[xx] = pack(src[i]);
}
}
}
void disp_ring(int cx, int cy, int r, uint16_t color)
{
int x = r, y = 0, err = 1 - r;

View File

@ -26,6 +26,7 @@
#define C_GOLD_DIM 0x7A80 /* 金色弱化 rgb(120,80,0) */
#define C_STAR 0x1966 /* 中档星点 rgb(24,44,48) */
#define C_TRACE 0x0105 /* 背景电路走线 rgb(0,32,40) */
#define C_FLAP_DOT 0xDF1C /* 翻页钟冒号方点 浅灰白 rgb(222,226,230) */
bool disp_init();
void disp_clear(uint16_t color);
@ -45,6 +46,9 @@ void disp_panel_glow(int x, int y, int w, int h, int cut, uint16_t glow);
/** 叠加混合贴内置图标(无 alpha:黑色加上去等于没画,霓虹线条自动发光)
* scale 把 1 个源像素放大成 scale*scale(最近邻),线稿图标放大到全高格子才不糊 */
void disp_add_bitmap(int x, int y, int w, int h, const uint16_t *px, uint8_t scale = 1);
/** 不透明贴图:源像素整块盖住帧缓冲。翻页钟那种白底黑字必须用它——
* 叠加混合下黑色等于没画,黑字会直接消失 */
void disp_blit(int x, int y, int w, int h, const uint16_t *px);
/** 详情页天体底纹:同心圆 + 十字 + 刻度 */
void disp_radar(int cx, int cy, int r);

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,15 @@
// 由 terminal/tools/gen_nixie.py 生成,请勿手改。
/* 翻页钟卡片:整张(白面+分裂线+轴套+数字)不透明 RGB565,固件用 disp_blit 直接覆盖。
点阵两侧各含 2px 面板底色边,所以贴图 X 要减 2;FLAP_*_BW 是含边的宽度。 */
#pragma once
#include <stdint.h>
#define FLAP_W 42
#define FLAP_H 66
#define FLAP_TIME_BW 46
#define FLAP_DW 30
#define FLAP_DH 46
#define FLAP_DATE_BW 34
extern const uint16_t *const flap_time[11];
extern const uint16_t *const flap_date[11];

View File

@ -83,6 +83,18 @@ void pwr_hold_early()
所以 USB 在位直接忽略。 */
#define PWR_OFF_MS 3000
/* SYS_EN 写 0:松手瞬间 Q2 关断 -> 整板断电。读不到扩展器就不敢乱写(那等于瞎猜其余 7 位)。 */
static bool cut_power()
{
uint8_t out = 0;
if (!tca_read8(TCA_REG_OUTPUT, &out)) {
Serial.println(F("[pwr] TCA9554 read failed, refuse to cut power"));
return false;
}
tca_write8(TCA_REG_OUTPUT, (uint8_t)(out & (uint8_t)~TCA_IO_SYS_EN));
return true;
}
static uint32_t s_press; /* 本次按下的起始时刻,0 = 没按 */
static bool s_boot_hold = true; /* 开机那一次长按,作废 */
@ -101,13 +113,8 @@ void pwr_key_poll(uint32_t now)
(unsigned long)held);
return;
}
uint8_t out = 0;
if (!tca_read8(TCA_REG_OUTPUT, &out)) {
Serial.println(F("[pwr] long press: TCA9554 read failed, refuse to cut power"));
return;
}
if (!cut_power()) return;
Serial.printf("[pwr] PWR held %lums -> SYS_EN=0, power off\n", (unsigned long)held);
tca_write8(TCA_REG_OUTPUT, (uint8_t)(out & (uint8_t)~TCA_IO_SYS_EN));
}
void bat_begin()
@ -172,4 +179,18 @@ void bat_report()
bat_charging() ? "yes" : "no(usb absent)");
Serial.printf("[bat] TCA9554 out=0x%02X SYS_EN=%s\n", out, latched ? "1 (held)" : "0/off");
}
/* 设置页那颗 POWER OFF:和长按 PWR 走同一套断电逻辑。
USB 插着时 VBUS 经 D1 直接供 VSYS,写 0 也不会断电,所以直接拒绝——
界面上这颗钮那时也是压暗且点不动的。 */
bool pwr_power_off()
{
if (bat_charging()) {
Serial.println(F("[pwr] UI power off ignored: USB powered, SYS_EN=0 cannot cut VBUS"));
return false;
}
if (!cut_power()) return false;
Serial.println(F("[pwr] UI power off -> SYS_EN=0"));
return true;
}
#endif

View File

@ -38,5 +38,7 @@ bool bat_charging(); /* USB 在位就当作在充 */
void bat_report(); /* 串口 batt:现场判断电池到底装没装上 */
/* loop 里调:长按 PWR 3 秒后松手 = SYS_EN 写 0 = 断电关机(只在电池供电时生效) */
void pwr_key_poll(uint32_t now);
/* 设置页那颗 POWER OFF:和长按 PWR 同一套逻辑。USB 供电时切不断 VBUS,拒绝并返回 false */
bool pwr_power_off();
#endif

View File

@ -11,6 +11,7 @@
#include "board_config.h"
#include "ota.h"
#include "clock.h"
#include "nixie.h"
#include <esp_ota_ops.h>
/* 版面:header 那行 0..HDR_LINE / 内容区 TOP_Y..BOT_Y / 按键条。
@ -42,11 +43,17 @@
static int s_info_r = CONT_W - 4;
#define LIST_ROWS (STRIP ? 2 : 3) /* 长条屏 2 张卡 y=31/101,h=66,铺到 167 */
#define CARD_H (STRIP ? 66 : 60)
#define CARD_X 3
#define RAIL_W (STRIP ? 30 : 0) /* 长条屏列表页右缘那一竖条(上/下键)占的列宽 */
#define CARD_W (CONT_W - 6 - RAIL_W)
/* 列表页的留白:卡片到屏左、翻页按钮到屏右、卡片到翻页按钮,三段用同一个值,
改一处就整体一起变宽。横屏没有翻页按钮那一列,维持原来的 3。 */
#define LIST_PAD (STRIP ? 16 : 3)
#define CARD_X LIST_PAD
#define RAIL_BTN_W 26 /* 上/下按钮本体宽 */
#define RAIL_W (STRIP ? (RAIL_BTN_W + LIST_PAD) : 0) /* 右缘那一列含左侧的缝 */
#define CARD_W (CONT_W - 2 * LIST_PAD - RAIL_W)
#define CARD_PITCH (STRIP ? 70 : 65)
#define SB_X (CONT_W - 3) /* 右缘滚动条 */
/* 滚动条贴屏右缘。翻页按钮的热区右界是 CONT_W-LIST_PAD+6,
LIST_PAD 加宽之后这条缝容得下 2px 的滚动条,两者不重迭。 */
#define SB_X (CONT_W - 3)
#define SPLASH_PAD 52
#define CARD_TY (STRIP ? 14 : 8) /* 卡内标题行 / 副行的 y 偏移 */
#define CARD_SY (STRIP ? 42 : 34)
@ -211,11 +218,14 @@ static void body_title(const BodyData &b, char *dst, size_t cap)
}
/* 图标优先用后台「平台管理 -> 天体信息」里维护的那张(已缓存到 PSRAM),
没维护或还没拉下来时退回固件内置线稿,尺寸一致所以版面不用分叉 */
没维护或还没拉下来时统一退回入口页那张天体线稿:ic_planet_* 和模式页的
ic_mode_planet_96 是同一张源图(资源文件/行星小.jpeg)的三个尺寸,
所以列表/详情/入口三处兜底看到的是同一个图案。
不再按名字挑各家专用线稿——那会让没图的天体之间长得不一样。 */
static const IconArt *body_art(const BodyData &b, int detail)
{
const IconArt *dyn = icon_store_get(&b, detail);
return dyn ? dyn : icon_for(b.name, b.name_zh, b.type, detail);
return dyn ? dyn : (detail ? &ic_planet_detail : &ic_planet_list);
}
#if BOARD_HAS_BATTERY
@ -261,9 +271,10 @@ static void status_bar(const UiState &st, const char *right)
char sig[28];
uint16_t net_c = C_CYAN;
if (st.wifi_up) {
/* 连着热点不等于通网:后端连续取不到数据时这里得变脸,否则旧数据看着像在线 */
/* 连着热点不等于通网:后端连续取不到数据时这里得变脸,否则旧数据看着像在线。
只显示在/离线,不再跟在后面念信号强度——设置页那一栏里还有。 */
if (st.api_fail) snprintf(sig, sizeof(sig), "NET:ONLINE API FAIL");
else snprintf(sig, sizeof(sig), "NET:ONLINE RSSI:%d", st.rssi);
else strlcpy(sig, "NET:ONLINE", sizeof(sig));
net_c = st.api_fail ? C_ORANGE : C_CYAN;
} else {
strlcpy(sig, "NET:OFFLINE", sizeof(sig));
@ -560,7 +571,7 @@ static void draw_list(const UiState &st)
char line[32], v[16];
fmt_au(v, sizeof(v), b.dist);
snprintf(line, sizeof(line), "DIST: %s AU", v);
disp_text(60, y + CARD_SY, line, 16, sel ? C_GOLD : C_CYAN_DIM, bg);
disp_text(CARD_X + 57, y + CARD_SY, line, 16, sel ? C_GOLD : C_CYAN_DIM, bg);
HIT(CARD_X, y, CARD_W, CARD_H, XL_IO_KEY2, i);
}
@ -700,8 +711,9 @@ static void draw_detail(const UiState &st)
disp_text(qx + 8, py + 24, "NO EVENTS", 16, C_DIM, C_PANEL);
return;
}
const int evr = STRIP ? 24 : 18; /* 栏高了 16px,三行事件摊开一点 */
for (int i = 0; i < b.ev_count && i < MAX_EVENTS; i++) {
const int evr = STRIP ? 24 : 18; /* 栏高了 16px,四行事件摊开一点 */
const int evn = STRIP ? MAX_EVENTS : 3; /* 横屏那块面板纵向只放得下三行 */
for (int i = 0; i < b.ev_count && i < evn; i++) {
int y = py + 24 + i * evr;
char ds[8];
snprintf(ds, sizeof(ds), "%.5s ", (strlen(b.ev_date[i]) >= 10) ? b.ev_date[i] + 5 : b.ev_date[i]);
@ -741,7 +753,72 @@ static void rocket_title(const RocketData &r, char *dst, size_t cap)
else strlcpy(dst, r.name, cap);
}
/* 入口页:两块面板,图标是 96x96 的大图(gen_assets.py 烘进固件) */
#if STRIP
/* ---------------- 首页中间的核子时钟(翻页钟样式,见 gen_nixie.py) ----------------
只借翻页钟的外观(白卡/分裂线/轴套),不做翻页动画:到点整张卡换一张。
卡片点阵两侧各含 2px 面板底色边,贴图 X 减 2,轴套才有地方凸出到缝里。
版面(内容区 31..171,中间格 165..475):
时间行 = 3组 x (42*2+2) + 2个16px冒号位 = 290 -> 175..465
日期行 = 年4张+月2张+日2张 + 2个20px斜杠缝 = 290,与时间行同宽同左边
时间卡 y=40..105,日期卡 y=116..161,上下留白 9/10px
两行分隔符同尺寸(都 5x5):冒号浅灰白,日期分组点纯白。 */
#define NX_CARD_W 155
#define NX_CLK_X (4 + NX_CARD_W + 6) /* 165 */
#define NX_CLK_W (CONT_W - 2 * NX_CLK_X) /* 310 = 155*2 */
#define NX_MARG 2 /* 点阵含的背景边,与 gen_nixie.py 的 MARG 一致 */
#define NX_GAPY 10 /* 时间行与日期行的缝 */
#define NX_COLON_W 16 /* 时:分:秒 两个冒号位 */
#define NX_TROW (3 * (2 * FLAP_W + 2) + 2 * NX_COLON_W) /* 290 */
#define NX_BLANK 10 /* 点阵第 11 张:卡面 + 一条墨杠 */
/* 六张时间卡的 X(相对整行左端):时/时 分/分 秒/秒 */
static const int NX_T_X[6] = { 0, 44, 102, 146, 204, 248 };
static const int NX_D_X[8] = { 0, 32, 64, 96, 146, 178, 228, 260 }; /* 年月 月 日 */
static const int NX_DOT_X[2] = { 92, 194 }; /* 冒号方点左上角(5x5) */
static const int NX_SEP_X[2] = { 136, 218 }; /* 年/月、月/日 两条 20px 缝的中心 */
/* 日期分组之间的圆点,5x5 和上面那对冒号一样大:两行的分隔符要在同一套视觉里,
上一行是 5x5 方点、这一行小一号的话,眼睛会把它当成数字的一部分而不是分隔符。
用点不用斜杠/横线:斜杠在这个尺寸上全是锯齿,横线会和卡片分裂线混在一起。
5x5 居中在 20px 缝里,左右净空 8/7px(20-5 是奇数),压不到卡片也不碰轴套。 */
static void flap_dot(int cx, int cy)
{
disp_fill(cx - 2, cy - 2, 5, 5, C_WHITE);
}
static void draw_nixie(int px, int pw)
{
disp_panel_glow(px, TOP_Y, pw, BOT_Y - TOP_Y + 1, 10, C_GOLD_DK);
disp_panel(px, TOP_Y, pw, BOT_Y - TOP_Y + 1, 10, C_PANEL, C_GOLD_DIM);
char buf[24];
int y, mo, d, hh, mi, ss;
clock_local(buf, sizeof(buf));
const bool live = clock_ready() &&
sscanf(buf, "%d-%d-%d %d:%d:%d", &y, &mo, &d, &hh, &mi, &ss) == 6;
if (!live) { y = mo = d = hh = mi = ss = 0; }
const int ty = TOP_Y + ((BOT_Y - TOP_Y + 1) - (FLAP_H + NX_GAPY + FLAP_DH)) / 2;
const int dy = ty + FLAP_H + NX_GAPY;
const int x0 = px + (pw - NX_TROW) / 2;
const int tv[6] = { hh / 10, hh % 10, mi / 10, mi % 10, ss / 10, ss % 10 };
const int dv[8] = { y / 1000, y / 100 % 10, y / 10 % 10, y % 10, mo / 10, mo % 10, d / 10, d % 10 };
for (int i = 0; i < 6; i++) /* 没对时 14 张卡全显示墨杠,不摆假时间 */
disp_blit(x0 + NX_T_X[i] - NX_MARG, ty, FLAP_TIME_BW, FLAP_H,
flap_time[live ? tv[i] : NX_BLANK]);
for (int i = 0; i < 8; i++)
disp_blit(x0 + NX_D_X[i] - NX_MARG, dy, FLAP_DATE_BW, FLAP_DH,
flap_date[live ? dv[i] : NX_BLANK]);
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
disp_fill(x0 + NX_DOT_X[i], ty + FLAP_H / 2 - 11 + j * 17, 5, 5, C_FLAP_DOT);
for (int i = 0; i < 2; i++)
flap_dot(x0 + NX_SEP_X[i], dy + FLAP_DH / 2);
}
#endif
/* 入口页:长条屏是三分屏(卡片 / 核子时钟 / 卡片),横屏是两块并排面板。
图标是 96x96 的大图(gen_assets.py 烘进固件) */
static void draw_mode(const UiState &st)
{
#if !STRIP
@ -754,8 +831,8 @@ static void draw_mode(const UiState &st)
for (int i = 0; i < 2; i++) {
#if STRIP
/* 面板铺满内容区:96 的图标 + 两行标签,两张卡左右并排平分整宽 */
const int w = (CONT_W - 24) / 2, x = 8 + i * (w + 8), y = TOP_Y, h = BOT_Y - TOP_Y + 1;
/* 左右两格各 155 宽(1:2:1 的 1),中间 310 留给核子时钟;96 图标 + 两行标签正好铺满一格 */
const int w = NX_CARD_W, x = 4 + i * (NX_CARD_W + 12 + NX_CLK_W), y = TOP_Y, h = BOT_Y - TOP_Y + 1;
const int iy = y + 4, ty = y + 104;
#else
const int x = 8 + i * 154, y = 42, w = 150, h = 146;
@ -773,6 +850,9 @@ static void draw_mode(const UiState &st)
disp_text_center(x, ty + 18, w, en[i], 16, sel ? C_GOLD : C_CYAN_DIM, bg);
HIT(x, y, w, h, XL_IO_KEY2, i);
}
#if STRIP
draw_nixie(NX_CLK_X, NX_CLK_W);
#endif
}
/* 和天体列表同一种卡片,右侧换成"还有几次发射",因为火箭没有订阅开关那种状态 */
@ -808,7 +888,7 @@ static void draw_rockets(const UiState &st)
snprintf(line, sizeof(line), "H %d.%dM PAY %d.%dT",
(int)r.height_m, ((int)(r.height_m * 10)) % 10,
(int)(r.payload_kg / 1000.0f), ((int)(r.payload_kg / 100.0f)) % 10);
disp_text_clipped(60, y + CARD_SY, STRIP ? CARD_W - 130 : 186, line, 16, sel ? C_GOLD : C_CYAN_DIM, bg);
disp_text_clipped(CARD_X + 57, y + CARD_SY, STRIP ? CARD_W - 130 : 186, line, 16, sel ? C_GOLD : C_CYAN_DIM, bg);
char nb[8];
snprintf(nb, sizeof(nb), (r.upcoming > 0) ? "%u" : "--", (unsigned)r.upcoming);
@ -921,7 +1001,7 @@ static void draw_rocket(const UiState &st)
/* LAUNCH / STAGE / INFO 三页,KEY3 或点底部 TAB 循环 */
disp_panel_glow(qx, py, qw, bh, 6, C_CYAN_DIM);
disp_panel(qx, py, qw, bh, 6, C_PANEL, C_CYAN);
const int ry[3] = { py + 26, py + 26 + tp, py + 26 + 2 * tp };
const int ry[4] = { py + 26, py + 26 + tp, py + 26 + 2 * tp, py + 26 + 3 * tp };
char tab[16];
snprintf(tab, sizeof(tab), "LAUNCH %u", (unsigned)d->event_total);
const char *tabs[3] = { tab, "STAGE", "INFO" };
@ -941,7 +1021,8 @@ static void draw_rocket(const UiState &st)
16, C_DIM, C_PANEL);
return;
}
for (int i = 0; i < d->ev_count && i < MAX_ROCKET_EV; i++) {
const int evn = STRIP ? MAX_ROCKET_EV : 3; /* 横屏那块面板纵向只放得下三行 */
for (int i = 0; i < d->ev_count && i < evn; i++) {
/* 任务名是主角,占满左边;发射日期挪到行尾成一列,读起来还是"什么时候打什么" */
char ds[8];
snprintf(ds, sizeof(ds), "%.5s", (strlen(d->ev[i].date) >= 10) ? d->ev[i].date + 5 : d->ev[i].date);
@ -1049,13 +1130,21 @@ static void s_row(int ix, int ir, int y, const char *l, uint16_t lc, int lw,
}
#if STRIP
/* 172 高放不下三张横卡:左右两张长卡,左网络右本机。行距 22,最后一行才不会压到卡片底边 */
/* 172 高放不下三张横卡:左网络右本机两张长卡,右端再留一竖列两个大按钮。
按钮列的定义排在下面 ui_glyph 之后(它要用图标)。 */
#define SET_BTN_W 104 /* 右列按钮宽:"POWER OFF" 九个字符放得下 */
#define SET_BTN_GAP 7 /* 两颗按钮之间的缝,也是按钮列和右栏之间的缝 */
/* 定义在下面:那节才有图标线稿 */
static void settings_actions(const UiState &st);
static void draw_settings_strip(const UiState &st)
{
const int ch = BOT_Y - TOP_Y + 1;
const int lw = (CONT_W - 14) / 2; /* 两栏等宽,中间留 6 */
/* 两栏等宽:整宽减掉左右边距、右列按钮、两道缝 */
const int lw = (CONT_W - 8 - SET_BTN_W - 2 * SET_BTN_GAP) / 2;
const int lx = 4, lix = 14, lir = lx + lw - 10;
const int rx = lx + lw + 6, rw = lw, rix = rx + 10, rir = rx + rw - 10;
const int rx = lx + lw + SET_BTN_GAP, rw = lw, rix = rx + 10, rir = rx + rw - 10;
char val[64], rv[32];
disp_panel_glow(lx, TOP_Y, lw, ch, 10, C_CYAN_DIM);
@ -1089,6 +1178,8 @@ static void draw_settings_strip(const UiState &st)
s_row(rix, rir, TOP_Y + 94, "BOARD", C_GOLD, 100, BOARD_NAME, C_TEXT);
clock_local(rv, sizeof(rv)); /* 服务器同步来的本地时间,没同步过时是 "--" */
s_row(rix, rir, TOP_Y + 116, "TIME", C_GOLD, 100, rv, C_TEXT);
settings_actions(st);
}
#endif
@ -1153,7 +1244,7 @@ static void draw_settings(const UiState &st)
剩下的页面级动作(返回/设置/配网/换码/重试/安装)满打满算两颗,画在状态栏右端。
屏一共 172 高,按钮画成 14x14 线稿图标 + 一个英文词:图标好认,英文比中文省一半宽度。
点它等价于按下 on_key_press 早就认识的那颗键,所以每一页的业务逻辑一行都不用改。 */
enum Glyph { G_BACK, G_GEAR, G_TUNE, G_REDO, G_DL, G_UP, G_DOWN };
enum Glyph { G_BACK, G_GEAR, G_TUNE, G_REDO, G_DL, G_POWER, G_UP, G_DOWN };
struct HdrBtn { Glyph g; const char *label; uint16_t bits; };
#define GLYPH_SZ 14 /* 线稿图标的方框边长 */
@ -1219,6 +1310,10 @@ static void ui_glyph(int x, int y, Glyph g, uint16_t c)
disp_fill(x + 11 - i, y + 3 - i, 1, 1 + 2 * i, c);
}
break;
case G_POWER: /* 关机:顶部缺口的圆环 + 中轴线 */
arc_px(cx, cy, 5, 115, 425, c);
disp_fill(cx - 1, y, 2, 7, c);
break;
case G_DL: /* 安装:向下箭头 + 托盘 */
disp_fill(x + 6, y + 1, 2, 8, c);
for (int i = 0; i < 4; i++) {
@ -1230,6 +1325,32 @@ static void ui_glyph(int x, int y, Glyph g, uint16_t c)
}
}
/* 设置页右列的两个大按钮:CONFIG 进配网门户(等价 on_key_press 的 KEY2),
POWER OFF 断掉 SYS_EN 关机。
USB 插着时 VBUS 供着整板,关机关不掉,所以那时 POWER OFF 整颗压暗并且
**不登记热区**——点了没反应的东西不能还长得像能点(和列表页的 nav_rail 同一个原则)。 */
static void settings_actions(const UiState &st)
{
const int bw = SET_BTN_W;
const int bh = (BOT_Y - TOP_Y + 1 - SET_BTN_GAP) / 2;
const int bx = CONT_W - 4 - bw;
const struct { Glyph g; const char *label; uint16_t bits; uint16_t c; bool en; } b[2] = {
{ G_TUNE, "CONFIG", XL_IO_KEY2, C_GOLD, true },
{ G_POWER, "POWER OFF", UI_ACT_POWOFF, C_RED, !st.bat_chg },
};
for (int i = 0; i < 2; i++) {
const int y = TOP_Y + i * (bh + SET_BTN_GAP);
const uint16_t line = b[i].en ? b[i].c : C_TRACE;
const uint16_t fg = b[i].en ? b[i].c : C_DIM;
disp_panel(bx, y, bw, bh, 8, C_PANEL, line);
const int tw = disp_text_width(b[i].label, 16, 1);
/* 图标 14 + 缝 8 + 文字 16 = 38,在 67 高里上下各留 14 */
ui_glyph(bx + (bw - GLYPH_SZ) / 2, y + 14, b[i].g, fg);
disp_text(bx + (bw - tw) / 2, y + 36, b[i].label, 16, fg, C_PANEL);
if (b[i].en) HIT(bx, y, bw, bh, b[i].bits, -1);
}
}
/* 每一页右上角放哪几颗,顺序 = 从右往左;语义照 on_key_press。
齿轮 SETUP 进的是只读的设置页,滑杆 CONFIG 直接进配网门户(改 WiFi、改后端地址都在那里)。 */
static int header_actions(const UiState &st, HdrBtn *b)
@ -1242,8 +1363,8 @@ static int header_actions(const UiState &st, HdrBtn *b)
case SC_DETAIL: case SC_ROCKET:
b[n++] = { G_BACK, "BACK", XL_IO_KEY2 }; break;
case SC_CONNECTING: b[n++] = { G_TUNE, "CONFIG", XL_IO_KEY3 }; break;
case SC_SETTINGS: b[n++] = { G_BACK, "BACK", XL_IO_KEY3 };
b[n++] = { G_TUNE, "CONFIG", XL_IO_KEY2 }; break;
case SC_SETTINGS: /* CONFIG 在这页是右列的大按钮,header 只留返回 */
b[n++] = { G_BACK, "BACK", XL_IO_KEY3 }; break;
case SC_PAIR: b[n++] = { G_REDO, "CODE", XL_IO_KEY3 };
b[n++] = { G_TUNE, "CONFIG", XL_IO_KEY2 }; break;
case SC_ERROR: b[n++] = { G_REDO, "RETRY", XL_IO_KEY3 };
@ -1283,8 +1404,9 @@ static void header_buttons(const HdrBtn *b, int n, uint8_t flash)
并且**不登记热区**——点了没反应的东西不能还长得像能点。 */
static void nav_rail(uint8_t flash, bool enabled)
{
const int bw = 24, bh = 26;
const int x = CONT_W - RAIL_W + (RAIL_W - bw) / 2;
const int bw = RAIL_BTN_W, bh = 26;
/* 贴右缘留 LIST_PAD,和卡片左边距、卡片与按钮之间的缝是同一个值 */
const int x = CONT_W - bw - LIST_PAD;
const int mid = (TOP_Y + BOT_Y) / 2;
const uint16_t key[2] = { XL_IO_KEY0, XL_IO_KEY1 };
const Glyph gl[2] = { G_UP, G_DOWN };

View File

@ -34,7 +34,7 @@ struct UiState {
const Snapshot *snap = nullptr;
const RocketSnapshot *rsnap = nullptr;
const RocketDetail *rdet = nullptr;
int mode_sel = 0; /* 模式选择页:0=天体 1=火箭 */
int mode_sel = -1; /* 模式选择页:0=天体 1=火箭,-1=还没选(进首页时不高亮任何一格)*/
int mode = -1; /* 已生效的模式,设置页显示;-1=没选过 */
int sel = 0; /* 天体列表光标 */
int rsel = 0; /* 火箭列表光标:分开记,切模式不会把对方光标带乱 */
@ -66,3 +66,4 @@ uint16_t ui_hit_test(int x, int y, int *index);
/* 热区里混在按键位之外的动作:不是按键,tap_at 自己消化,不进 on_key_press */
#define UI_ACT_TAB 0x0040 /* 面板内的分页标签,index = 目标页 */
#define UI_ACT_POWOFF 0x0080 /* 设置页右列的关机按钮(长条屏:这板上没有第二路输入) */

View File

@ -2,4 +2,4 @@
* 发 OTA 包必须先改这里再编译:终端拿它和后端版本号比,
* 版本号没变的话新包会被当成"已是最新"而永不安装。 */
#pragma once
#define FW_VERSION "1.5.4"
#define FW_VERSION "1.5.8"

View File

@ -0,0 +1,116 @@
#!/usr/bin/env python3
"""生成首页核子时钟(翻页钟样式)的卡片点阵。
/usr/bin/python3 terminal/tools/gen_nixie.py
输出 terminal/firmware/cosmo_terminal/src/nixie.{h,cpp}(提交进仓库,编译时不需要 PIL)。
文件名沿用 nixie(第一代是拟辉光管),内容已经是翻页钟卡片。
一张卡片 = 白面(上下叶各一档渐变)+ 1px 深色描边 + 分裂线(压在数字上)+ 两侧轴套 + 数字,
整张烘成不透明 RGB565,固件只用 disp_blit 覆盖一次,不做任何混合:
黑色数字在 disp_add_bitmap 的叠加混合下等于"没画",所以这条路径必须是不透明贴图。
左右各留 2px 背景边(就是面板底色 C_PANEL),轴套才有地方凸出卡片边缘;
相邻卡片的点阵会在缝里重叠 2 列,重叠处两边颜色完全相同,先后覆盖看不出来。
不做翻页动画:到点整张卡换一张,一次整屏 flush。
"""
from pathlib import Path
from PIL import Image, ImageDraw, ImageFont
ROOT = Path(__file__).resolve().parents[2]
OUT = ROOT / "terminal/firmware/cosmo_terminal/src"
SS = 4 # 4x 超采样渲染后降采样,圆角和字模边缘才不毛
FONT = "/System/Library/Fonts/Helvetica.ttc"
FONT_IDX = 1 # Helvetica Bold,翻页钟那种饱满无衬线
SIZES = (("time", 42, 66, 0.80), ("date", 30, 46, 0.74)) # (名字, 卡宽, 卡高, 字号/卡高)
MARG = 2 # 卡片两侧的背景边,轴套凸出用
C_PANEL = (16, 20, 32) # = display.h 的 C_PANEL,缝里要一模一样
TOP_A, TOP_B = (250, 252, 252), (240, 243, 244) # 上叶渐变:亮 -> 略暗
BOT_A, BOT_B = (233, 237, 239), (221, 226, 228) # 下叶比上叶暗一档,翻页钟的光影
OUTLINE, INK = (44, 48, 52), (18, 20, 22)
SEAM, SEAM_HI, NUB = (122, 128, 134), (204, 208, 212), (52, 56, 60)
def rgb565(r, g, b):
return ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3)
def lerp(a, b, k):
return tuple(int(x + (y - x) * k) for x, y in zip(a, b))
def card(w, h, ch, fsize):
"""一张完整卡片 -> RGB565 列表,宽 w+2*MARG,行优先"""
bw, bh = w + 2 * MARG, h
img = Image.new("RGB", (bw * SS, bh * SS), C_PANEL)
d = ImageDraw.Draw(img)
x0, mid = MARG * SS, (bh // 2) * SS
# 卡面白:上叶和下叶各一条渐变,中间那个台阶是翻页钟的关键光影
face = Image.new("RGB", (w * SS, h * SS))
fd = ImageDraw.Draw(face)
for yy in range(h * SS):
k = yy / (h * SS)
fd.line([(0, yy), (w * SS, yy)],
fill=lerp(TOP_A, TOP_B, k * 2) if yy < bh // 2 * SS else lerp(BOT_A, BOT_B, (k - .5) * 2))
mask = Image.new("L", (w * SS, h * SS), 0)
ImageDraw.Draw(mask).rounded_rectangle([0, 0, w * SS - 1, h * SS - 1],
radius=max(2, w // 12) * SS, fill=255)
img.paste(face, (x0, 0), mask)
d.rounded_rectangle([x0, 0, x0 + w * SS - 1, h * SS - 1], radius=max(2, w // 12) * SS,
outline=OUTLINE, width=SS)
r = max(2, w // 12) * SS
# 分裂线:先埋在数字底下,数字画完再压回一道,看起来才像两块叶片
d.line([x0 + r, mid, x0 + w * SS - r, mid], fill=SEAM, width=SS)
d.line([x0 + r, mid + SS, x0 + w * SS - r, mid + SS], fill=SEAM_HI, width=SS)
for nx in (x0 - 2 * SS, x0 + w * SS - SS): # 左右轴套,跨出卡片边缘压住缝
d.rounded_rectangle([nx, mid - 3 * SS, nx + 3 * SS - 1, mid + 3 * SS], radius=SS, fill=NUB)
if ch.isdigit():
f = ImageFont.truetype(FONT, int(h * fsize) * SS, index=FONT_IDX)
bb = d.textbbox((0, 0), ch, font=f)
d.text(((x0 + w * SS / 2) - (bb[2] - bb[0]) / 2 - bb[0],
bh * SS / 2 - (bb[3] + bb[1]) / 2), ch, fill=INK, font=f)
else: # 没对时:卡面照常,位置上一条墨杠
d.rounded_rectangle([x0 + w * SS * .29, mid - 2 * SS, x0 + w * SS * .71, mid + 2 * SS],
radius=SS, fill=INK)
d.line([x0 + r, mid, x0 + w * SS - r, mid], fill=(150, 156, 162), width=SS)
img = img.resize((bw, bh), Image.LANCZOS)
return [rgb565(*px) for px in img.getdata()]
def emit():
heads, body = [], ['// 由 terminal/tools/gen_nixie.py 生成,请勿手改。', '#include "nixie.h"']
for name, w, h, fs in SIZES:
glyphs = [card(w, h, c, fs) for c in "0123456789-"]
bw = w + 2 * MARG
heads += [f"#define FLAP_{'W' if name == 'time' else 'DW'} {w}",
f"#define FLAP_{'H' if name == 'time' else 'DH'} {h}",
f"#define FLAP_{name.upper()}_BW {bw}"]
body.append("")
body += [f"static const uint16_t {name}{i}[] = {{{', '.join(map(str, px))}}};"
for i, px in enumerate(glyphs)]
body += ["", f"const uint16_t *const flap_{name}[11] = {{",
" " + ", ".join(f"{name}{i}" for i in range(11)) + ",", "};"]
print(f"flap_{name}: 11 张卡片 @{bw}x{h}(卡片本体 {w}x{h}),"
f"{11 * bw * h * 2 // 1024} KB flash")
(OUT / "nixie.h").write_text("\n".join([
"// 由 terminal/tools/gen_nixie.py 生成,请勿手改。",
"/* 翻页钟卡片:整张(白面+分裂线+轴套+数字)不透明 RGB565,固件用 disp_blit 直接覆盖。",
" 点阵两侧各含 2px 面板底色边,所以贴图 X 要减 2;FLAP_*_BW 是含边的宽度。 */",
"#pragma once", "#include <stdint.h>", "", *heads,
"", "extern const uint16_t *const flap_time[11];",
"extern const uint16_t *const flap_date[11];", ""]), encoding="utf-8")
(OUT / "nixie.cpp").write_text("\n".join(body + [""]), encoding="utf-8")
if __name__ == "__main__":
OUT.mkdir(parents=True, exist_ok=True)
emit()