reduced count, created sample set with two rotations: up and sideways

This commit is contained in:
John Poole 2026-04-17 15:54:26 -07:00
commit 3c6db4f5ff

View file

@ -61,7 +61,7 @@ static constexpr uint8_t kMagCandidateCount = 3;
static constexpr uint8_t kMagCandidates[kMagCandidateCount] = {0x1C, 0x3C, 0x0D};
static constexpr float kDeclinationDeg = MAG_DECLINATION_DEG;
static constexpr float kDegPerRad = 57.29577951308232f;
static constexpr char kApPassword[] = "microreticulum";
struct ClockDateTime {
uint16_t year = 0;
@ -385,16 +385,18 @@ void handleWebDownload() {
file.close();
}
void startWebServer() {
snprintf(g_apSsid, sizeof(g_apSsid), "Compass-%s", kBoardId);
void startWebServerOLD() {
// GPSQA-CY is a carry-over from previous exercises, but we can keep the SSID for continuity.
//The unique board ID is in the suffix, and the IP address is fixed based on LOG_AP_IP_OCTET.
snprintf(g_apSsid, sizeof(g_apSsid), "GPSQA-%s", kBoardId);
WiFi.mode(WIFI_AP);
WiFi.setSleep(false);
const IPAddress ip(192, 168, LOG_AP_IP_OCTET, 1);
const IPAddress gw(192, 168, LOG_AP_IP_OCTET, 1);
const IPAddress nm(255, 255, 255, 0);
WiFi.softAPConfig(ip, gw, nm);
if (!WiFi.softAP(g_apSsid, kApPassword)) {
// no password required.
if (!WiFi.softAP(g_apSsid)) {
Serial.println("wifi_ap=failed");
return;
}
@ -409,6 +411,52 @@ void startWebServer() {
Serial.printf("wifi_ap_url=http://192.168.%u.1/\n", (unsigned)LOG_AP_IP_OCTET);
}
void startWebServer() {
// GPSQA-CY is a carry-over from previous exercises, but we can keep the SSID for continuity.
//The unique board ID is in the suffix, and the IP address is fixed based on LOG_AP_IP_OCTET.
snprintf(g_apSsid, sizeof(g_apSsid), "GPSQA-%s", kBoardId);
WiFi.mode(WIFI_AP);
WiFi.setSleep(false);
const IPAddress ip(192, 168, LOG_AP_IP_OCTET, 1);
const IPAddress gw(192, 168, LOG_AP_IP_OCTET, 1);
const IPAddress nm(255, 255, 255, 0);
const bool cfgOk = WiFi.softAPConfig(ip, gw, nm);
Serial.printf("wifi_ap_config=%s\n", cfgOk ? "ok" : "failed");
// no password required.
if (!WiFi.softAP(g_apSsid)) {
Serial.println("wifi_ap=failed");
return;
}
Serial.println("wifi_ap=started");
Serial.printf("wifi_ap_ssid=%s\n", g_apSsid);
Serial.printf("wifi_ap_ip=%s\n", WiFi.softAPIP().toString().c_str());
Serial.printf("wifi_station_count=%d\n", WiFi.softAPgetStationNum());
g_server.on("/", HTTP_GET, []() {
Serial.println("http_hit=/");
handleWebIndex();
});
g_server.on("/files", HTTP_GET, []() {
Serial.println("http_hit=/files");
handleWebFiles();
});
g_server.on("/download", HTTP_GET, []() {
Serial.println("http_hit=/download");
handleWebDownload();
});
g_server.onNotFound([]() {
Serial.printf("http_404 uri=%s\n", g_server.uri().c_str());
g_server.send(404, "text/plain", "not found\n");
});
g_server.begin();
g_webReady = true;
}
bool probeI2cAddr(TwoWire& wire, uint8_t addr) {
wire.beginTransmission(addr);
return wire.endTransmission() == 0;
@ -721,6 +769,14 @@ void appSetup() {
g_lastHeartbeatMs = millis();
}
// We want to capture a reasonable amount of data for calibration and testing,
// bu we also want to avoid creating huge logs or overwhelming the display.
// 600 samples at 200ms intervals is 2 minutes of data, which should be enough
// for calibration and testing.
// Adjust the sample_limit as needed based on your specific requirements and constraints.
uint32_t sample_limit = 600;
uint32_t sample_count = 0;
void appLoop() {
if (g_webReady) {
g_server.handleClient();
@ -730,10 +786,12 @@ void appLoop() {
g_sdMounted = g_sd.isMounted();
const uint32_t now = millis();
if (sample_count <= sample_limit) {
if ((uint32_t)(now - g_lastSampleMs) >= kSampleIntervalMs) {
g_lastSampleMs = now;
MagSample sample{};
if (captureSample(sample)) {
sample_count++;
g_lastSample = sample;
printSampleToSerial(sample);
appendSampleToLog(sample);
@ -744,14 +802,16 @@ void appLoop() {
g_lastDisplayMs = now;
drawLiveUi();
}
}
if ((uint32_t)(now - g_lastHeartbeatMs) >= 5000) {
g_lastHeartbeatMs = now;
Serial.printf("alive seq=%lu log=%s web=%s sd=%s\n",
Serial.printf("alive seq=%lu log=%s web=%s sd=%s sta=%d\n",
(unsigned long)g_lastSample.seq,
g_logOpen ? "open" : "closed",
g_webReady ? "up" : "down",
g_sdMounted ? "mounted" : "absent");
g_sdMounted ? "mounted" : "absent",
WiFi.softAPgetStationNum());
}
}