alexanderlavrushko / BLE-HUD-navigation-ESP32

Shows navigation instructions received from the phone (e.g. "After 200m turn right")
75 stars 23 forks source link

only half of the display used? #16

Open seriojel opened 2 years ago

seriojel commented 2 years ago

0FFC638C-AB1E-4898-8B5C-C6C96AEB4DB9

ii feels like a waste of space on such a small display. are there any other information that will be displayed on the other half?

alexanderlavrushko commented 2 years ago

Originally it was made for 128x128 display, and later just shown on 135x240 TTGO display, so the half remains unused. Currently there is no any other information to show.

Maybe in future I'll make visualization part separated from BLE part, it would receive HUDData structure (or similar) - then it can be easier for you to make adjustments (for example, make bigger fonts to use the whole display).

seriojel commented 2 years ago

got it, thanks

i tried to make those bigger but no success yet.

erikkt commented 2 years ago

Any easy way of centering the information on the TTGO (so it is not placed on left side)?

alexanderlavrushko commented 2 years ago

Yes, in main file BLEHUDNaviESP32.ino, add a few lines in function SetPixelCanvas (begins at line 501):

void SetPixelCanvas(int16_t x, int16_t y, uint16_t value)
{
...
// existing code (don't modify)
#elif DISPLAY_ROTATION == 270
    const int16_t xOriginal = x;
    x = y;
    y = CANVAS_HEIGHT - xOriginal;
#endif

// NEW CODE - add these 3 lines
    const int16_t deltaY = 56;
    const int16_t sign = (DISPLAY_ROTATION < 180 ? 1 : -1);
    y += sign * deltaY;

// existing code (don't modify)
    if (x < 0 || y < 0 || x >= CANVAS_WIDTH || y >= CANVAS_HEIGHT)
    {
        return;
    }
    g_canvas[y * CANVAS_WIDTH + x] = value;
}
Nithesh2003 commented 5 months ago

I just need to access the upcoming direction like turn right in 150m. I am not using an Oled display just want to print it, how can I implement that?

alexanderlavrushko commented 5 months ago

@Nithesh2003 see BLEHUDNaviESP32.ino, at line 256 you can see access to text like "150m": const char* text = currentData.c_str() + textOffset;

At line 270 there is access to instruction data: currentData.c_str()[instructionOffset], you can put the value into a variable, and then check what to do with it, like this:

char instruction = currentData.c_str()[instructionOffset];
switch (instruction)
{
    // see all values in DataConstants.h
    case DirectionRight:
        // your code
        break;
    case DirectionLeft:
        break;
    // ...
}
Nithesh2003 commented 5 months ago

@Nithesh2003 see BLEHUDNaviESP32.ino, at line 256 you can see access to text like "150m": const char* text = currentData.c_str() + textOffset;

At line 270 there is access to instruction data: currentData.c_str()[instructionOffset], you can put the value into a variable, and then check what to do with it, like this:

char instruction = currentData.c_str()[instructionOffset];
switch (instruction)
{
    // see all values in DataConstants.h
    case DirectionRight:
        // your code
        break;
    case DirectionLeft:
        break;
    // ...
}

I am not using oled so how can i connect the esp32 module with sygic app.

alexanderlavrushko commented 5 months ago

@Nithesh2003 if you have just ESP32 module without display and other hardware, it's OK, you can use this program as is (so ESP32 will actually try to send image to OLED display, but this image will be lost because you have corresponding pins unconnected as you don't have display, other parts of this program should work normally).

nihalsaran commented 4 months ago

Hey can i connect LEDs and get the turn signal output from esp32 to LEDs?

Apollyon-mxc commented 4 months ago

Is it possible to use a lcd display? I have one with 240x280 resolution with ST7789v2 driver. Can i use TFT_eSPI library?

Apollyon-mxc commented 4 months ago
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
#include <BLE2902.h>
#include <Button2.h>
#include "IDisplay.h"
#include "ImagesOther.h"
#include "ImagesDirections.h"
#include "ImagesLanes.h"
#include "Font8x8GlyphShifter.h"
#include "DataConstants.h"
#include "VoltageMeasurement.h"

// Include the library for ST7789V2 display
#include <TFT_eSPI.h>
TFT_eSPI selectedDisplay = TFT_eSPI();

constexpr bool ENABLE_VOLTAGE_MEASUREMENT = false;

// Constants for display
#define COLOR_BLACK    0x0000
#define COLOR_WHITE    0xFFFF
#define COLOR_MAGENTA  0xF81F

// Variables for BLE
BLEServer* g_pServer = NULL;
BLECharacteristic* g_pCharIndicate = NULL;
bool g_deviceConnected = false;
uint32_t g_lastActivityTime = 0;
bool g_isNaviDataUpdated = false;
std::string g_naviData;

// Buttons
Button2 g_btnDeepSleep(TTGO_LEFT_BUTTON);
bool g_sleepRequested = false;

Button2 g_btn1(TTGO_RIGHT_BUTTON);

// Voltage measurement
#define VOLTAGE_ADC_ENABLE          14
#define VOLTAGE_ADC_PIN             34
static VoltageMeasurement g_voltage(VOLTAGE_ADC_PIN, VOLTAGE_ADC_ENABLE);
static bool g_showVoltage = false;

void setup() {
    Serial.begin(115200);
    Serial.println("BLENaviPeripheral2 setup() started");

    selectedDisplay.init(); // Initialize the ST7789V2 display
    selectedDisplay.setRotation(1); // Adjust rotation if needed
    selectedDisplay.fillScreen(TFT_BLACK);

    Serial.println("Display init done");

    // BLE initialization
    Serial.println("BLE init started");

    BLEDevice::init("ESP32 HUD");
    g_pServer = BLEDevice::createServer();
    g_pServer->setCallbacks(new MyServerCallbacks());
    BLEService *pService = g_pServer->createService(SERVICE_UUID);

    // characteristic for indicate
    {
        uint32_t charProperties = BLECharacteristic::PROPERTY_INDICATE;
        g_pCharIndicate = pService->createCharacteristic(CHAR_INDICATE_UUID, charProperties);
        g_pCharIndicate->addDescriptor(new BLE2902());
        g_pCharIndicate->setValue("");
    }

    // characteristic for write
    {
        uint32_t charProperties = BLECharacteristic::PROPERTY_WRITE;
        BLECharacteristic *pCharWrite = pService->createCharacteristic(CHAR_WRITE_UUID, charProperties);
        pCharWrite->setCallbacks(new MyCharWriteCallbacks());
    }

    pService->start();
    BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
    pAdvertising->addServiceUUID(SERVICE_UUID);
    pAdvertising->setScanResponse(true);
    pAdvertising->setMinPreferred(0x06);  // functions that help with iPhone connections issue
    pAdvertising->setMinPreferred(0x12);
    BLEDevice::startAdvertising();
    Serial.println("BLE init done");

    // setup deep sleep button
    g_btnDeepSleep.setLongClickTime(500);
    g_btnDeepSleep.setLongClickDetectedHandler([](Button2& b) {
        g_sleepRequested = true;
    });
    g_btnDeepSleep.setReleasedHandler([](Button2& b) {
        if (!g_sleepRequested) {
            return;    
        }

        selectedDisplay.sleep();

        // without this the module won't wake up with button if powered from battery,
        // especially if entered deep sleep when powered from USB
        g_voltage.end();

        esp_sleep_enable_ext0_wakeup(GPIO_NUM_WAKEUP, 0);
        delay(200);
        esp_deep_sleep_start();
    });

    // setup voltage measurement
    if (ENABLE_VOLTAGE_MEASUREMENT) {
        g_voltage.begin();
        g_btn1.setPressedHandler([](Button2& b) {
            g_showVoltage = true;
        });
        g_btn1.setReleasedHandler([](Button2& b) {
            g_showVoltage = false;
        });
    }

    Serial.println("setup() finished");
}

void loop() {
    g_btnDeepSleep.loop();
    g_btn1.loop();
    if (g_sleepRequested) {
        // Handle sleep
    }
    else if (g_showVoltage) {
        // Handle voltage display
    }
    else if (g_deviceConnected) {
        // Handle device connected state
    }
    else if (millis() > 3000) {
        // Handle disconnected state
    }
    delay(10);
}