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
29 changes: 29 additions & 0 deletions esp32_marauder/BootSplash.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "BootSplash.h"

namespace marauder {

BootSplashLayout bootSplashLayout(int16_t screen_width,
int16_t screen_height) {
const bool compact = screen_height <= 160 || screen_width <= 160;
const bool v8_portrait = screen_width == 240 && screen_height == 320;
BootSplashLayout layout{};
layout.text_size = compact || v8_portrait ? 1 : 2;
layout.title_y = compact ? 4 : screen_height / 16;
layout.status_y = screen_height - (compact ? 12 : 24);
layout.version_y = layout.status_y - (compact ? 14 : 24);

layout.logo_y = layout.title_y + (compact ? 16 : 28);
const int16_t logo_bottom = layout.version_y - (compact ? 4 : 10);
const int16_t available_height = logo_bottom - layout.logo_y;
const int16_t maximum_width = screen_width * (compact ? 55 : 68) / 100;
const int16_t height_from_width = maximum_width * 316 / 240;

layout.logo_height = available_height < height_from_width
? available_height : height_from_width;
if (layout.logo_height < 24) layout.logo_height = 24;
layout.logo_width = layout.logo_height * 240 / 316;
layout.logo_x = (screen_width - layout.logo_width) / 2;
return layout;
}

} // namespace marauder
21 changes: 21 additions & 0 deletions esp32_marauder/BootSplash.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include <stdint.h>

namespace marauder {

struct BootSplashLayout {
int16_t title_y;
int16_t logo_x;
int16_t logo_y;
int16_t logo_width;
int16_t logo_height;
int16_t version_y;
int16_t status_y;
uint8_t text_size;
};

BootSplashLayout bootSplashLayout(int16_t screen_width,
int16_t screen_height);

} // namespace marauder
3,171 changes: 3,171 additions & 0 deletions esp32_marauder/BootSplashBitmap.h

Large diffs are not rendered by default.

87 changes: 87 additions & 0 deletions esp32_marauder/Display.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,53 @@
#include "Display.h"
#include "BootSplashBitmap.h"
#include "DisplayLine.h"
#include "lang_var.h"

#ifdef HAS_SCREEN

namespace {

uint8_t readLogoAlpha(uint16_t x, uint16_t y) {
const uint32_t pixel_index = static_cast<uint32_t>(y) * JCMK_LOGO_WIDTH + x;
const uint8_t packed = pgm_read_byte(JCMK_LOGO_BITMAP + pixel_index / 2);
return pixel_index & 1 ? packed & 0x0F : packed >> 4;
}

uint8_t sampleLogoAlpha(uint32_t source_x, uint32_t source_y) {
const uint16_t x0 = source_x >> 8;
const uint16_t y0 = source_y >> 8;
const uint16_t x1 = x0 + 1 < JCMK_LOGO_WIDTH ? x0 + 1 : x0;
const uint16_t y1 = y0 + 1 < JCMK_LOGO_HEIGHT ? y0 + 1 : y0;
const uint8_t x_fraction = source_x & 0xFF;
const uint8_t y_fraction = source_y & 0xFF;

const uint16_t top = readLogoAlpha(x0, y0) * (256 - x_fraction) +
readLogoAlpha(x1, y0) * x_fraction;
const uint16_t bottom = readLogoAlpha(x0, y1) * (256 - x_fraction) +
readLogoAlpha(x1, y1) * x_fraction;
return ((top * (256 - y_fraction) + bottom * y_fraction) + 32768) >> 16;
}

bool cleanLogoPixel(int16_t x, int16_t y, int16_t width, int16_t height,
uint32_t source_x_step, uint32_t source_y_step) {
uint8_t white_neighbors = 0;
for (int8_t y_offset = -1; y_offset <= 1; ++y_offset) {
const int16_t sample_y = y + y_offset;
if (sample_y < 0 || sample_y >= height) continue;
for (int8_t x_offset = -1; x_offset <= 1; ++x_offset) {
const int16_t sample_x = x + x_offset;
if (sample_x < 0 || sample_x >= width) continue;
if (sampleLogoAlpha(sample_x * source_x_step,
sample_y * source_y_step) >= 8) {
++white_neighbors;
}
}
}
return white_neighbors >= 5;
}

} // namespace

Display::Display()
#ifdef HAS_CYD_TOUCH
: touchscreenSPI(VSPI),
Expand Down Expand Up @@ -242,6 +286,49 @@ void Display::RunSetup() {
#endif
}

void Display::drawBootSplash() {
const int16_t width = tft.width();
const int16_t height = tft.height();
const marauder::BootSplashLayout layout =
marauder::bootSplashLayout(width, height);

tft.fillScreen(TFT_BLACK);
tft.setTextWrap(false);
tft.setFreeFont(NULL);
tft.setTextSize(layout.text_size);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.drawCentreString("ESP32 Marauder", width / 2, layout.title_y, 1);

const uint32_t source_x_step = layout.logo_width > 1
? (static_cast<uint32_t>(JCMK_LOGO_WIDTH - 1) << 8) /
(layout.logo_width - 1)
: 0;
const uint32_t source_y_step = layout.logo_height > 1
? (static_cast<uint32_t>(JCMK_LOGO_HEIGHT - 1) << 8) /
(layout.logo_height - 1)
: 0;
for (int16_t y = 0; y < layout.logo_height; ++y) {
int16_t run_start = -1;
for (int16_t x = 0; x <= layout.logo_width; ++x) {
const bool white = x < layout.logo_width &&
cleanLogoPixel(x, y, layout.logo_width, layout.logo_height,
source_x_step, source_y_step);
if (white && run_start < 0) run_start = x;
if (!white && run_start >= 0) {
tft.drawFastHLine(layout.logo_x + run_start, layout.logo_y + y,
x - run_start, TFT_WHITE);
run_start = -1;
}
}
}

tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.drawCentreString(version_number, width / 2, layout.version_y, 1);
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.drawCentreString("Initializing...", width / 2, layout.status_y, 1);
tft.setTextSize(1);
}

void Display::tftDrawGraphObjects(byte x_scale)
{
//draw the graph objects
Expand Down
6 changes: 4 additions & 2 deletions esp32_marauder/Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#include <LinkedList.h>
#include <SPI.h>
#include "SPIFFS.h"
#include "Assets.h"
#include "Assets.h"
#include "BootSplash.h"

#include <TFT_eSPI.h>

Expand Down Expand Up @@ -141,7 +142,8 @@ class Display
void tftDrawChanHopButton(bool lnd_an = true, bool en = false);
void buildBanner(String msg, int xpos);
void clearScreen();
void displayBuffer(bool do_clear = false);
void displayBuffer(bool do_clear = false);
void drawBootSplash();
void getTouchWhileFunction(bool pressed);
void init();
void RunSetup();
Expand Down
78 changes: 78 additions & 0 deletions esp32_marauder/GpsTrackerStats.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include "GpsTrackerStats.h"

#include <math.h>

namespace marauder {
namespace {
constexpr double kDegreesToRadians = 0.017453292519943295;
constexpr double kEarthRadiusMeters = 6371000.0;
constexpr float kMaximumPlausibleSpeedMps = 120.0f;
}

void GpsTrackerStats::reset(uint32_t now_ms) {
start_ms_ = now_ms;
last_fix_ms_ = now_ms;
last_latitude_e6_ = 0;
last_longitude_e6_ = 0;
distance_m_ = 0.0f;
speed_mps_ = 0.0f;
logged_points_ = 0;
has_fix_ = false;
}

uint32_t GpsTrackerStats::elapsedMs(uint32_t now_ms) const {
return now_ms - start_ms_;
}

float GpsTrackerStats::distanceBetweenMeters(int32_t latitude_a_e6,
int32_t longitude_a_e6,
int32_t latitude_b_e6,
int32_t longitude_b_e6) {
const double lat_a = latitude_a_e6 * 0.000001 * kDegreesToRadians;
const double lat_b = latitude_b_e6 * 0.000001 * kDegreesToRadians;
const double delta_lat = lat_b - lat_a;
const double delta_lon =
(longitude_b_e6 - longitude_a_e6) * 0.000001 * kDegreesToRadians;
const double sin_lat = sin(delta_lat * 0.5);
const double sin_lon = sin(delta_lon * 0.5);
const double haversine = sin_lat * sin_lat +
cos(lat_a) * cos(lat_b) * sin_lon * sin_lon;
const double bounded_haversine = haversine > 1.0 ? 1.0 : haversine;
const double arc = 2.0 * atan2(sqrt(bounded_haversine),
sqrt(1.0 - bounded_haversine));
return static_cast<float>(kEarthRadiusMeters * arc);
}

bool GpsTrackerStats::update(int32_t latitude_e6, int32_t longitude_e6,
float accuracy_m, uint32_t now_ms) {
++logged_points_;
if (!has_fix_) {
last_latitude_e6_ = latitude_e6;
last_longitude_e6_ = longitude_e6;
last_fix_ms_ = now_ms;
has_fix_ = true;
return true;
}

const uint32_t delta_ms = now_ms - last_fix_ms_;
const float step_m = distanceBetweenMeters(last_latitude_e6_,
last_longitude_e6_, latitude_e6,
longitude_e6);
const float jitter_floor_m = accuracy_m > 3.0f ? accuracy_m : 3.0f;
const float maximum_step_m = delta_ms * 0.001f * kMaximumPlausibleSpeedMps;

last_latitude_e6_ = latitude_e6;
last_longitude_e6_ = longitude_e6;
last_fix_ms_ = now_ms;

if (delta_ms == 0 || step_m < jitter_floor_m || step_m > maximum_step_m) {
speed_mps_ = 0.0f;
return false;
}

distance_m_ += step_m;
speed_mps_ = step_m / (delta_ms * 0.001f);
return true;
}

} // namespace marauder
35 changes: 35 additions & 0 deletions esp32_marauder/GpsTrackerStats.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

#include <stdint.h>

namespace marauder {

class GpsTrackerStats {
public:
void reset(uint32_t now_ms);
bool update(int32_t latitude_e6, int32_t longitude_e6, float accuracy_m,
uint32_t now_ms);

uint32_t elapsedMs(uint32_t now_ms) const;
float distanceMeters() const { return distance_m_; }
float speedMetersPerSecond() const { return speed_mps_; }
uint32_t loggedPoints() const { return logged_points_; }
bool hasFix() const { return has_fix_; }

static float distanceBetweenMeters(int32_t latitude_a_e6,
int32_t longitude_a_e6,
int32_t latitude_b_e6,
int32_t longitude_b_e6);

private:
uint32_t start_ms_ = 0;
uint32_t last_fix_ms_ = 0;
int32_t last_latitude_e6_ = 0;
int32_t last_longitude_e6_ = 0;
float distance_m_ = 0.0f;
float speed_mps_ = 0.0f;
uint32_t logged_points_ = 0;
bool has_fix_ = false;
};

} // namespace marauder
2 changes: 1 addition & 1 deletion esp32_marauder/MenuFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ void MenuFunctions::main(uint32_t currentTime)
if (currentTime - initTime >= BANNER_TIME) {
this->initTime = millis();
if ((wifi_scan_obj.currentScanMode != LV_JOIN_WIFI) &&
(wifi_scan_obj.currentScanMode != LV_ADD_SSID))
(wifi_scan_obj.currentScanMode != LV_ADD_SSID) && (wifi_scan_obj.currentScanMode != WIFI_PACKET_MONITOR)) // GCOVR_EXCL_LINE -- Packet Monitor owns its full hardware display.
this->updateStatusBar();

// Do channel analyzer stuff
Expand Down
Loading
Loading