diff --git a/esp32_marauder/Display.cpp b/esp32_marauder/Display.cpp index d2ff431..b8a1fdc 100644 --- a/esp32_marauder/Display.cpp +++ b/esp32_marauder/Display.cpp @@ -1,16 +1,5 @@ #include "Display.h" - -/* -Big thanks to bodmer for having great TFT and JPEG libraries - -https://github.com/bodmer -*/ - -//PROGMEM lv_obj_t * slider_label; -//PROGMEM lv_obj_t * ta1; -//PROGMEM lv_obj_t * ta2; - Display::Display() { } @@ -27,19 +16,19 @@ void Display::RunSetup() tft.setRotation(0); // Portrait tft.setCursor(0, 0); - //tft.setFreeFont(&FreeMonoBold9pt7b); - // Calibration data - //uint16_t calData[5] = { 390, 3516, 253, 3520, 7 }; tft.setRotation(1); // Portrait + #ifndef MARAUDER_MINI + + #ifdef TFT_SHIELD + uint16_t calData[5] = { 275, 3494, 361, 3528, 4 }; // tft.setRotation(0); // Portrait with TFT Shield + Serial.println(F("Using TFT Shield")); + #else if defined(TFT_DIY) + uint16_t calData[5] = { 339, 3470, 237, 3438, 2 }; // tft.setRotation(0); // Portrait with DIY TFT + Serial.println(F("Using TFT DIY")); + #endif + tft.setTouch(calData); - #ifdef TFT_SHIELD - uint16_t calData[5] = { 275, 3494, 361, 3528, 4 }; // tft.setRotation(0); // Portrait with TFT Shield - Serial.println(F("Using TFT Shield")); - #else if defined(TFT_DIY) - uint16_t calData[5] = { 339, 3470, 237, 3438, 2 }; // tft.setRotation(0); // Portrait with DIY TFT - Serial.println(F("Using TFT DIY")); #endif - tft.setTouch(calData); //tft.fillScreen(TFT_BLACK); clearScreen(); @@ -48,102 +37,11 @@ void Display::RunSetup() Serial.println("SPI_READ_FREQUENCY: " + (String)SPI_READ_FREQUENCY); Serial.println("SPI_TOUCH_FREQUENCY: " + (String)SPI_TOUCH_FREQUENCY); - - // Initialize file system - // This should probably have its own class - //if (!SPIFFS.begin()) { - // Serial.println(F("SPIFFS initialisation failed!")); - //while (1) yield(); // Stay here twiddling thumbs waiting - //} - - //this->initLVGL(); - - - // Draw the title screen - //drawJpeg("/marauder3L.jpg", 0 , 0); // 240 x 320 image - - //showCenterText(version_number, 250); - //tft.drawCentreString(version_number, 120, 250, 2); - - //digitalWrite(TFT_BL, HIGH); - - //delay(5000); - #ifdef KIT pinMode(KIT_LED_BUILTIN, OUTPUT); #endif } -/* Interrupt driven periodic handler */ -/* -void Display::lv_tick_handler() -{ - lv_tick_inc(LVGL_TICK_PERIOD); -}*/ - -/* Display flushing */ -/* -void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) -{ - extern Display display_obj; - uint16_t c; - - display_obj.tft.startWrite(); - display_obj.tft.setAddrWindow(area->x1, area->y1, (area->x2 - area->x1 + 1), (area->y2 - area->y1 + 1)); - for (int y = area->y1; y <= area->y2; y++) { - for (int x = area->x1; x <= area->x2; x++) { - c = color_p->full; - display_obj.tft.writeColor(c, 1); - color_p++; - } - } - display_obj.tft.endWrite(); - lv_disp_flush_ready(disp); -} - - -bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data) -{ - extern Display display_obj; - - uint16_t touchX, touchY; - - bool touched = display_obj.tft.getTouch(&touchX, &touchY, 600); - - if(!touched) - { - return false; - } - - if(touchX>WIDTH_1 || touchY > HEIGHT_1) - { - Serial.println("Y or y outside of expected parameters.."); - Serial.print("y:"); - Serial.print(touchX); - Serial.print(" x:"); - Serial.print(touchY); - } - else - { - - data->state = touched ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL; - - //if(data->state == LV_INDEV_STATE_PR) touchpad_get_xy(&last_x, &last_y); - - data->point.x = touchX; - data->point.y = touchY; - - Serial.print("Data x"); - Serial.println(touchX); - - Serial.print("Data y"); - Serial.println(touchY); - - } - - return false; -}*/ - void Display::drawFrame() { tft.drawRect(FRAME_X, FRAME_Y, FRAME_W, FRAME_H, TFT_BLACK); @@ -448,20 +346,24 @@ void Display::setupScrollArea(uint16_t tfa, uint16_t bfa) { Serial.println(" tfa: " + (String)tfa); Serial.println(" bfa: " + (String)bfa); Serial.println("yStart: " + (String)this->yStart); - tft.writecommand(ILI9341_VSCRDEF); // Vertical scroll definition - tft.writedata(tfa >> 8); // Top Fixed Area line count - tft.writedata(tfa); - tft.writedata((YMAX-tfa-bfa)>>8); // Vertical Scrolling Area line count - tft.writedata(YMAX-tfa-bfa); - tft.writedata(bfa >> 8); // Bottom Fixed Area line count - tft.writedata(bfa); + #ifndef MARAUDER_MINI + tft.writecommand(ILI9341_VSCRDEF); // Vertical scroll definition + tft.writedata(tfa >> 8); // Top Fixed Area line count + tft.writedata(tfa); + tft.writedata((YMAX-tfa-bfa)>>8); // Vertical Scrolling Area line count + tft.writedata(YMAX-tfa-bfa); + tft.writedata(bfa >> 8); // Bottom Fixed Area line count + tft.writedata(bfa); + #endif } void Display::scrollAddress(uint16_t vsp) { - tft.writecommand(ILI9341_VSCRSADD); // Vertical scrolling pointer - tft.writedata(vsp>>8); - tft.writedata(vsp); + #ifndef MARAUDER_MINI + tft.writecommand(ILI9341_VSCRSADD); // Vertical scrolling pointer + tft.writedata(vsp>>8); + tft.writedata(vsp); + #endif } @@ -840,7 +742,7 @@ void Display::buildBanner(String msg, int xpos) //img.fillCircle(SCREEN_WIDTH / 2, TEXT_HEIGHT / 2, 10, TFT_ORANGE); // Now print text on top of the graphics - img.setTextSize(2); // Font size scaling is x1 + img.setTextSize(BANNER_TEXT_SIZE); // Font size scaling is x1 img.setTextFont(0); // Font 4 selected img.setTextColor(TFT_WHITE); // Black text, no background colour img.setTextWrap(false); // Turn of wrap so we can print past end of sprite @@ -853,112 +755,6 @@ void Display::buildBanner(String msg, int xpos) img.print(msg); } -/* -void Display::initLVGL() { - tick.attach_ms(LVGL_TICK_PERIOD, lv_tick_handler); - - lv_init(); - - lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10); - - lv_disp_drv_t disp_drv; - lv_disp_drv_init(&disp_drv); - disp_drv.hor_res = WIDTH_1; - disp_drv.ver_res = HEIGHT_1; - disp_drv.flush_cb = my_disp_flush; - disp_drv.buffer = &disp_buf; - lv_disp_drv_register(&disp_drv); - - lv_indev_drv_t indev_drv; - lv_indev_drv_init(&indev_drv); - indev_drv.type = LV_INDEV_TYPE_POINTER; - indev_drv.read_cb = my_touchpad_read; - lv_indev_drv_register(&indev_drv); -} - - -void Display::deinitLVGL() { - Serial.println(F("Deinit LVGL")); - //lv_deinit(); -} - - - -void Display::joinWiFiGFX(){ - - // Create one text area - ta1 = lv_textarea_create(lv_scr_act(), NULL); - lv_textarea_set_one_line(ta1, true); - lv_obj_set_width(ta1, LV_HOR_RES / 2 - 20); - lv_obj_set_pos(ta1, 5, 20); - //lv_ta_set_cursor_type(ta, LV_CURSOR_BLOCK); - lv_textarea_set_text(ta1, ""); - lv_obj_set_event_cb(ta1, ta_event_cb); - - // Create first label - lv_obj_t * ssid_label = lv_label_create(lv_scr_act(), NULL); - lv_label_set_text(ssid_label, "SSID:"); - lv_obj_align(ssid_label, ta1, LV_ALIGN_OUT_TOP_LEFT, 0, 0); - - // Create second text area - ta2 = lv_textarea_create(lv_scr_act(), ta1); - //lv_textarea_set_pwd_mode(ta2, true); // This shit makes it so backspace does not work - //lv_textarea_set_pwd_show_time(ta2, 1000); - lv_textarea_set_cursor_hidden(ta2, true); - lv_obj_align(ta2, NULL, LV_ALIGN_IN_TOP_RIGHT, -5, 20); - - // Create second label - lv_obj_t * pw_label = lv_label_create(lv_scr_act(), NULL); - lv_label_set_text(pw_label, "Password:"); - lv_obj_align(pw_label, ta2, LV_ALIGN_OUT_TOP_LEFT, 0, 0); - - // Create a keyboard and apply the styles - kb = lv_keyboard_create(lv_scr_act(), NULL); - lv_obj_set_size(kb, LV_HOR_RES, LV_VER_RES / 2); - lv_obj_set_event_cb(kb, keyboard_event_cb); - - // Focus it on one of the text areas to start - lv_keyboard_set_textarea(kb, ta1); - lv_keyboard_set_cursor_manage(kb, true); - -} - - -void keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event){ - extern Display display_obj; - lv_keyboard_def_event_cb(kb, event); - if(event == LV_EVENT_APPLY){ - printf("LV_EVENT_APPLY\n"); - //String ta1_text = lv_textarea_get_text(lv_keyboard_get_textarea(kb)); - String ta1_text = lv_textarea_get_text(ta1); - String ta2_text = lv_textarea_get_text(ta2); - Serial.println(ta1_text); - Serial.println(ta2_text); - //joinWiFi(ta1_text, ta2_text); - }else if(event == LV_EVENT_CANCEL){ - printf("LV_EVENT_CANCEL\n"); - //lv_textarea_set_text(lv_keyboard_get_textarea(kb), ""); - display_obj.deinitLVGL(); - display_obj.exit_draw = true; // set everything back to normal - } -} - - -void ta_event_cb(lv_obj_t * ta, lv_event_t event) -{ - if(event == LV_EVENT_CLICKED) { - if(kb != NULL) - lv_keyboard_set_textarea(kb, ta); - } - - //else if(event == LV_EVENT_INSERT) { - // const char * str = lv_event_get_data(); - // if(str[0] == '\n') { - // printf("Ready\n"); - // } - //} -}*/ - void Display::main(uint8_t scan_mode) { if ((scan_mode == LV_JOIN_WIFI) || diff --git a/esp32_marauder/Display.h b/esp32_marauder/Display.h index c2e7896..e68e0a9 100644 --- a/esp32_marauder/Display.h +++ b/esp32_marauder/Display.h @@ -13,19 +13,10 @@ //#include #include "SPIFFS.h" #include "Assets.h" +#include "configs.h" #include -#define TFT_MISO 19 -#define TFT_MOSI 23 -#define TFT_SCLK 18 -#define TFT_CS 27 -#define TFT_DC 26 -#define TFT_RST 5 -#define TFT_BL 32 -#define TOUCH_CS 21 -#define SD_CS 4 - // WiFi stuff #define OTA_UPDATE 100 #define SHOW_INFO 101 @@ -46,50 +37,6 @@ #define LV_ADD_SSID 14 #define WIFI_ATTACK_BEACON_LIST 15 -//#define TFT_SHIELD -#define TFT_DIY -#define KIT - -#define SCREEN_WIDTH 240 -#define SCREEN_HEIGHT 320 -#define HEIGHT_1 240 -#define WIDTH_1 320 -#define STANDARD_FONT_CHAR_LIMIT 40 // number of characters on a single line with normal font -#define TEXT_HEIGHT 16 // Height of text to be printed and scrolled -#define BOT_FIXED_AREA 0 // Number of lines in bottom fixed area (lines counted from bottom of screen) -#define TOP_FIXED_AREA 48 // Number of lines in top fixed area (lines counted from top of screen) -#define YMAX 320 // Bottom of screen area -#define minimum(a,b) (((a) < (b)) ? (a) : (b)) -//#define MENU_FONT NULL -#define MENU_FONT &FreeMono9pt7b // Winner -//#define MENU_FONT &FreeMonoBold9pt7b -//#define MENU_FONT &FreeSans9pt7b -//#define MENU_FONT &FreeSansBold9pt7b -#define BUTTON_ARRAY_LEN 9 -#define STATUS_BAR_WIDTH 16 -#define LVGL_TICK_PERIOD 6 - -#define FRAME_X 100 -#define FRAME_Y 64 -#define FRAME_W 120 -#define FRAME_H 50 - -// Red zone size -#define REDBUTTON_X FRAME_X -#define REDBUTTON_Y FRAME_Y -#define REDBUTTON_W (FRAME_W/2) -#define REDBUTTON_H FRAME_H - -// Green zone size -#define GREENBUTTON_X (REDBUTTON_X + REDBUTTON_W) -#define GREENBUTTON_Y FRAME_Y -#define GREENBUTTON_W (FRAME_W/2) -#define GREENBUTTON_H FRAME_H - -#define STATUSBAR_COLOR 0x4A49 - -#define KIT_LED_BUILTIN 13 - /* PROGMEM void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p); PROGMEM bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data); @@ -104,6 +51,9 @@ PROGMEM static void keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event); PROGMEM static lv_obj_t *kb; */ +// #define KIT +// #define TFT_FIY + class Display { private: @@ -131,7 +81,7 @@ class Display TFT_eSPI tft = TFT_eSPI(); TFT_eSprite img = TFT_eSprite(&tft); TFT_eSPI_Button key[BUTTON_ARRAY_LEN]; - const String PROGMEM version_number = "v0.9.5"; + const String PROGMEM version_number = MARAUDER_VERSION; bool printing = false; bool loading = false; diff --git a/esp32_marauder/MenuFunctions.cpp b/esp32_marauder/MenuFunctions.cpp index ecb4f37..8c51b6d 100644 --- a/esp32_marauder/MenuFunctions.cpp +++ b/esp32_marauder/MenuFunctions.cpp @@ -776,6 +776,16 @@ void ta_event_cb(lv_obj_t * ta, lv_event_t event) //} } +void MenuFunctions::buttonNotSelected(uint8_t b) { + display_obj.tft.setFreeFont(NULL); + display_obj.key[b].drawButton(false, current_menu->list->get(b).name); +} + +void MenuFunctions::buttonSelected(uint8_t b) { + display_obj.tft.setFreeFont(NULL); + display_obj.key[b].drawButton(true, current_menu->list->get(b).name); +} + // Function to check menu input void MenuFunctions::main(uint32_t currentTime) { @@ -798,9 +808,11 @@ void MenuFunctions::main(uint32_t currentTime) //{ // this->drawStatusBar(); //} - if ((wifi_scan_obj.currentScanMode != LV_JOIN_WIFI) && - (wifi_scan_obj.currentScanMode != LV_ADD_SSID)) - display_obj.updateBanner(current_menu->name); + #ifndef MARAUDER_MINI + if ((wifi_scan_obj.currentScanMode != LV_JOIN_WIFI) && + (wifi_scan_obj.currentScanMode != LV_ADD_SSID)) + display_obj.updateBanner(current_menu->name); + #endif } if (currentTime != 0) { @@ -809,10 +821,12 @@ void MenuFunctions::main(uint32_t currentTime) if ((wifi_scan_obj.currentScanMode != LV_JOIN_WIFI) && (wifi_scan_obj.currentScanMode != LV_ADD_SSID)) this->updateStatusBar(); + #ifdef MARAUDER_MINI + display_obj.updateBanner(current_menu->name); + #endif } } - //this->displayCurrentMenu(); boolean pressed = false; // This is code from bodmer's keypad example @@ -835,15 +849,9 @@ void MenuFunctions::main(uint32_t currentTime) // getTouch causes a 10ms delay which makes beacon spam less effective //if (wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF) - pressed = display_obj.tft.getTouch(&t_x, &t_y); - - //if (pressed) - // Serial.println("Pressed, son"); - //boolean pressed = false; - - //Serial.print("getTouch: "); - //Serial.print(millis() - pre_getTouch); - //Serial.println("ms"); + #ifndef MARAUDER_MINI + pressed = display_obj.tft.getTouch(&t_x, &t_y); + #endif // This is if there are scans/attacks going on @@ -888,67 +896,93 @@ void MenuFunctions::main(uint32_t currentTime) // Check if any key coordinate boxes contain the touch coordinates // This is for when on a menu - if ((wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM) && - (wifi_scan_obj.currentScanMode != WIFI_ATTACK_AUTH) && - (wifi_scan_obj.currentScanMode != WIFI_ATTACK_DEAUTH) && - (wifi_scan_obj.currentScanMode != WIFI_ATTACK_MIMIC) && - (wifi_scan_obj.currentScanMode != WIFI_ATTACK_RICK_ROLL)) - //(wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_LIST)) - { - // Need this to set all keys to false - for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++) { - if (pressed && display_obj.key[b].contains(t_x, t_y)) { - display_obj.key[b].press(true); // tell the button it is pressed - } else { - display_obj.key[b].press(false); // tell the button it is NOT pressed + #ifndef MARAUDER_MINI + if ((wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM) && + (wifi_scan_obj.currentScanMode != WIFI_ATTACK_AUTH) && + (wifi_scan_obj.currentScanMode != WIFI_ATTACK_DEAUTH) && + (wifi_scan_obj.currentScanMode != WIFI_ATTACK_MIMIC) && + (wifi_scan_obj.currentScanMode != WIFI_ATTACK_RICK_ROLL)) + //(wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_LIST)) + { + // Need this to set all keys to false + for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++) { + if (pressed && display_obj.key[b].contains(t_x, t_y)) { + display_obj.key[b].press(true); // tell the button it is pressed + } else { + display_obj.key[b].press(false); // tell the button it is NOT pressed + } + } + + // Check if any key has changed state + for (uint8_t b = 0; b < current_menu->list->size(); b++) { + display_obj.tft.setFreeFont(MENU_FONT); + if (display_obj.key[b].justPressed()) { + //display_obj.key[b].drawButton2(current_menu->list->get(b).name, true); // draw invert + //display_obj.key[b].drawButton(ML_DATUM, BUTTON_PADDING, current_menu->list->get(b).name, true); + display_obj.key[b].drawButton(true, current_menu->list->get(b).name); + if (current_menu->list->get(b).name != "Back") + display_obj.tft.drawXBitmap(0, + KEY_Y + b * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2), + menu_icons[current_menu->list->get(b).icon], + ICON_W, + ICON_H, + current_menu->list->get(b).color, + TFT_BLACK); + } + //else if (pressed) + // display_obj.key[b].drawButton(false, current_menu->list->get(b).name); + + // If button was just release, execute the button's function + if ((display_obj.key[b].justReleased()) && (!pressed)) + { + //display_obj.key[b].drawButton2(current_menu->list->get(b).name); // draw normal + //display_obj.key[b].drawButton(ML_DATUM, BUTTON_PADDING, current_menu->list->get(b).name); + display_obj.key[b].drawButton(false, current_menu->list->get(b).name); + current_menu->list->get(b).callable(); + } + // This + else if ((display_obj.key[b].justReleased()) && (pressed)) { + display_obj.key[b].drawButton(false, current_menu->list->get(b).name); + if (current_menu->list->get(b).name != "Back") + display_obj.tft.drawXBitmap(0, + KEY_Y + b * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2), + menu_icons[current_menu->list->get(b).icon], + ICON_W, + ICON_H, + TFT_BLACK, + current_menu->list->get(b).color); + } + + display_obj.tft.setFreeFont(NULL); } } + x = -1; + y = -1; + #endif - // Check if any key has changed state - for (uint8_t b = 0; b < current_menu->list->size(); b++) { - display_obj.tft.setFreeFont(MENU_FONT); - if (display_obj.key[b].justPressed()) { - //display_obj.key[b].drawButton2(current_menu->list->get(b).name, true); // draw invert - //display_obj.key[b].drawButton(ML_DATUM, BUTTON_PADDING, current_menu->list->get(b).name, true); - display_obj.key[b].drawButton(true, current_menu->list->get(b).name); - if (current_menu->list->get(b).name != "Back") - display_obj.tft.drawXBitmap(0, - KEY_Y + b * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2), - menu_icons[current_menu->list->get(b).icon], - ICON_W, - ICON_H, - current_menu->list->get(b).color, - TFT_BLACK); + #ifdef MARAUDER_MINI + if (u_btn.justPressed()){ + if (current_menu->selected > 0) { + current_menu->selected--; + this->buttonSelected(current_menu->selected); + this->buttonNotSelected(current_menu->selected + 1); + Serial.println("Current menu index: " + (String)current_menu->selected); } - //else if (pressed) - // display_obj.key[b].drawButton(false, current_menu->list->get(b).name); - - // If button was just release, execute the button's function - if ((display_obj.key[b].justReleased()) && (!pressed)) - { - //display_obj.key[b].drawButton2(current_menu->list->get(b).name); // draw normal - //display_obj.key[b].drawButton(ML_DATUM, BUTTON_PADDING, current_menu->list->get(b).name); - display_obj.key[b].drawButton(false, current_menu->list->get(b).name); - current_menu->list->get(b).callable(); - } - // This - else if ((display_obj.key[b].justReleased()) && (pressed)) { - display_obj.key[b].drawButton(false, current_menu->list->get(b).name); - if (current_menu->list->get(b).name != "Back") - display_obj.tft.drawXBitmap(0, - KEY_Y + b * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2), - menu_icons[current_menu->list->get(b).icon], - ICON_W, - ICON_H, - TFT_BLACK, - current_menu->list->get(b).color); - } - - display_obj.tft.setFreeFont(NULL); } - } - x = -1; - y = -1; + if (d_btn.justPressed()){ + if (current_menu->selected < current_menu->list->size() - 1) { + current_menu->selected++; + this->buttonSelected(current_menu->selected); + this->buttonNotSelected(current_menu->selected - 1); + Serial.println("Current menu index: " + (String)current_menu->selected); + } + } + if(c_btn.justPressed()){ + Serial.println("CENTER"); + current_menu->list->get(current_menu->selected).callable(); + } + + #endif } #if BATTERY_ANALOG_ON == 1 @@ -1054,6 +1088,11 @@ void MenuFunctions::battery2(bool initial) void MenuFunctions::updateStatusBar() { display_obj.tft.setTextSize(1); + + #ifdef MARAUDER_MINI + display_obj.tft.setFreeFont(NULL); + #endif + uint16_t the_color; // Draw temp info @@ -1072,7 +1111,13 @@ void MenuFunctions::updateStatusBar() if (temp_obj.current_temp != temp_obj.old_temp) { temp_obj.old_temp = temp_obj.current_temp; display_obj.tft.fillRect(0, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR); - display_obj.tft.drawString((String)temp_obj.current_temp + " C", 4, 0, 2); + #ifndef MARAUDER_MINI + display_obj.tft.drawString((String)temp_obj.current_temp + " C", 4, 0, 2); + #endif + + #ifdef MARAUDER_MINI + display_obj.tft.drawString((String)temp_obj.current_temp + " C", 0, 0, 1); + #endif } display_obj.tft.setTextColor(TFT_WHITE, STATUSBAR_COLOR); @@ -1080,7 +1125,13 @@ void MenuFunctions::updateStatusBar() if (wifi_scan_obj.set_channel != wifi_scan_obj.old_channel) { wifi_scan_obj.old_channel = wifi_scan_obj.set_channel; display_obj.tft.fillRect(50, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR); - display_obj.tft.drawString("CH: " + (String)wifi_scan_obj.set_channel, 50, 0, 2); + #ifndef MARAUDER_MINI + display_obj.tft.drawString("CH: " + (String)wifi_scan_obj.set_channel, 50, 0, 2); + #endif + + #ifdef MARAUDER_MINI + display_obj.tft.drawString("CH: " + (String)wifi_scan_obj.set_channel, TFT_WIDTH/4, 0, 1); + #endif } // RAM Stuff @@ -1088,7 +1139,13 @@ void MenuFunctions::updateStatusBar() if (wifi_scan_obj.free_ram != wifi_scan_obj.old_free_ram) { wifi_scan_obj.old_free_ram = wifi_scan_obj.free_ram; display_obj.tft.fillRect(100, 0, 60, STATUS_BAR_WIDTH, STATUSBAR_COLOR); - display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", 100, 0, 2); + #ifndef MARAUDER_MINI + display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", 100, 0, 2); + #endif + + #ifdef MARAUDER_MINI + display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", TFT_WIDTH/1.75, 0, 1); + #endif } // Draw battery info @@ -1100,19 +1157,28 @@ void MenuFunctions::updateStatusBar() else the_color = TFT_RED; - display_obj.tft.drawXBitmap(170, - 0, - menu_icons[STATUS_SD], - 16, - 16, - STATUSBAR_COLOR, - the_color); - //display_obj.tft.print((String)battery_obj.battery_level + "%"); + #ifndef MARAUDER_MINI + display_obj.tft.drawXBitmap(170, + 0, + menu_icons[STATUS_SD], + 16, + 16, + STATUSBAR_COLOR, + the_color); + #endif + + #ifdef MARAUDER_MINI + display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR); + display_obj.tft.drawString("SD", TFT_WIDTH - 12, 0, 1); + #endif } void MenuFunctions::drawStatusBar() { display_obj.tft.setTextSize(1); + #ifdef MARAUDER_MINI + display_obj.tft.setFreeFont(NULL); + #endif display_obj.tft.fillRect(0, 0, 240, STATUS_BAR_WIDTH, STATUSBAR_COLOR); //display_obj.tft.fillRect(0, STATUS_BAR_WIDTH + 1, 240, 1, TFT_DARKGREY); display_obj.tft.setTextColor(TFT_WHITE, STATUSBAR_COLOR); @@ -1135,20 +1201,38 @@ void MenuFunctions::drawStatusBar() display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR); temp_obj.old_temp = temp_obj.current_temp; display_obj.tft.fillRect(0, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR); - display_obj.tft.drawString((String)temp_obj.current_temp + " C", 4, 0, 2); + #ifndef MARAUDER_MINI + display_obj.tft.drawString((String)temp_obj.current_temp + " C", 4, 0, 2); + #endif + + #ifdef MARAUDER_MINI + display_obj.tft.drawString((String)temp_obj.current_temp + " C", 0, 0, 1); + #endif display_obj.tft.setTextColor(TFT_WHITE, STATUSBAR_COLOR); // WiFi Channel Stuff wifi_scan_obj.old_channel = wifi_scan_obj.set_channel; display_obj.tft.fillRect(50, 0, 50, STATUS_BAR_WIDTH, STATUSBAR_COLOR); - display_obj.tft.drawString("CH: " + (String)wifi_scan_obj.set_channel, 50, 0, 2); + #ifndef MARAUDER_MINI + display_obj.tft.drawString("CH: " + (String)wifi_scan_obj.set_channel, 50, 0, 2); + #endif + + #ifdef MARAUDER_MINI + display_obj.tft.drawString("CH: " + (String)wifi_scan_obj.set_channel, TFT_WIDTH/4, 0, 1); + #endif // RAM Stuff wifi_scan_obj.freeRAM(); wifi_scan_obj.old_free_ram = wifi_scan_obj.free_ram; display_obj.tft.fillRect(100, 0, 60, STATUS_BAR_WIDTH, STATUSBAR_COLOR); - display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", 100, 0, 2); + #ifndef MARAUDER_MINI + display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", 100, 0, 2); + #endif + + #ifdef MARAUDER_MINI + display_obj.tft.drawString((String)wifi_scan_obj.free_ram + "B", TFT_WIDTH/1.75, 0, 1); + #endif MenuFunctions::battery2(true); @@ -1159,14 +1243,20 @@ void MenuFunctions::drawStatusBar() else the_color = TFT_RED; - display_obj.tft.drawXBitmap(170, - 0, - menu_icons[STATUS_SD], - 16, - 16, - STATUSBAR_COLOR, - the_color); - //display_obj.tft.print((String)battery_obj.battery_level + "%"); + #ifndef MARAUDER_MINI + display_obj.tft.drawXBitmap(170, + 0, + menu_icons[STATUS_SD], + 16, + 16, + STATUSBAR_COLOR, + the_color); + #endif + + #ifdef MARAUDER_MINI + display_obj.tft.setTextColor(the_color, STATUSBAR_COLOR); + display_obj.tft.drawString("SD", TFT_WIDTH - 12, 0, 1); + #endif } void MenuFunctions::orientDisplay() @@ -1178,20 +1268,17 @@ void MenuFunctions::orientDisplay() display_obj.tft.setCursor(0, 0); - //uint16_t calData[5] = { 275, 3494, 361, 3528, 4 }; // tft.setRotation(0); // Portrait - //uint16_t calData[5] = { 339, 3470, 237, 3438, 2 }; // tft.setRotation(0); // Portrait with DIY TFT + #ifndef MARAUDER_MINI + #ifdef TFT_SHIELD + uint16_t calData[5] = { 275, 3494, 361, 3528, 4 }; // tft.setRotation(0); // Portrait with TFT Shield + Serial.println("Using TFT Shield"); + #else if defined(TFT_DIY) + uint16_t calData[5] = { 339, 3470, 237, 3438, 2 }; // tft.setRotation(0); // Portrait with DIY TFT + Serial.println("Using TFT DIY"); + #endif -#ifdef TFT_SHIELD - uint16_t calData[5] = { 275, 3494, 361, 3528, 4 }; // tft.setRotation(0); // Portrait with TFT Shield - Serial.println("Using TFT Shield"); -#else if defined(TFT_DIY) - uint16_t calData[5] = { 339, 3470, 237, 3438, 2 }; // tft.setRotation(0); // Portrait with DIY TFT - Serial.println("Using TFT DIY"); -#endif - - display_obj.tft.setTouch(calData); - - //display_obj.clearScreen(); + display_obj.tft.setTouch(calData); + #endif changeMenu(current_menu); } @@ -1711,10 +1798,6 @@ void MenuFunctions::showMenuList(Menu * menu, int layer) Serial.print(" "); Serial.print("Node: "); Serial.println(menu->list->get(i).name); - - // If the current menu node points to another menu, list that menu - //if (menu->list->get(i).childMenu != NULL) - // showMenuList(menu->list->get(i).childMenu, layer+1); } Serial.println(); } @@ -1763,36 +1846,42 @@ void MenuFunctions::displayCurrentMenu() display_obj.clearScreen(); display_obj.tft.setTextColor(TFT_LIGHTGREY, TFT_DARKGREY); this->drawStatusBar(); - //display_obj.tft.fillRect(0,0,240,16, TFT_DARKGREY); - //display_obj.tft.drawCentreString(" ESP32 Marauder ",120,0,2); - //Serial.println("Getting size..."); - //char buf[¤t_menu->parentMenu->name.length() + 1] = {}; - //Serial.println("Got size..."); - //current_menu->parentMenu->name.toCharArray(buf, current_menu->parentMenu->name.length() + 1); - //String current_name = ¤t_menu->parentMenu->name; - //Serial.println("gottem"); - //display_obj.tft.drawCentreString(current_menu->name,120,0,2); + if (current_menu->list != NULL) { - display_obj.tft.setFreeFont(MENU_FONT); + #ifndef MARAUDER_MINI + display_obj.tft.setFreeFont(MENU_FONT); + #endif + + #ifdef MARAUDER_MINI + display_obj.tft.setFreeFont(NULL); + display_obj.tft.setTextSize(1); + #endif for (uint8_t i = 0; i < current_menu->list->size(); i++) { - //display_obj.key[i].drawButton2(current_menu->list->get(i).name); - //display_obj.key[i].drawButton(ML_DATUM, BUTTON_PADDING, current_menu->list->get(i).name); - //display_obj.key[i].drawButton(true); - if (!current_menu->list->get(i).selected) - display_obj.key[i].drawButton(false, current_menu->list->get(i).name); - else - display_obj.key[i].drawButton(true, current_menu->list->get(i).name); + #ifndef MARAUDER_MINI + if (!current_menu->list->get(i).selected) + display_obj.key[i].drawButton(false, current_menu->list->get(i).name); + else + display_obj.key[i].drawButton(true, current_menu->list->get(i).name); - if (current_menu->list->get(i).name != "Back") - display_obj.tft.drawXBitmap(0, - KEY_Y + i * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2), - menu_icons[current_menu->list->get(i).icon], - ICON_W, - ICON_H, - TFT_BLACK, - current_menu->list->get(i).color); + if (current_menu->list->get(i).name != "Back") + display_obj.tft.drawXBitmap(0, + KEY_Y + i * (KEY_H + KEY_SPACING_Y) - (ICON_H / 2), + menu_icons[current_menu->list->get(i).icon], + ICON_W, + ICON_H, + TFT_BLACK, + current_menu->list->get(i).color); + + #endif + + #ifdef MARAUDER_MINI + if (current_menu->selected != i) + display_obj.key[i].drawButton(false, current_menu->list->get(i).name); + else + display_obj.key[i].drawButton(true, current_menu->list->get(i).name); + #endif } display_obj.tft.setFreeFont(NULL); } diff --git a/esp32_marauder/MenuFunctions.h b/esp32_marauder/MenuFunctions.h index 94dc054..0641ca0 100644 --- a/esp32_marauder/MenuFunctions.h +++ b/esp32_marauder/MenuFunctions.h @@ -11,7 +11,16 @@ #include "esp_interface.h" #include "a32u4_interface.h" #include "settings.h" +#include "configs.h" +#ifdef MARAUDER_MINI + #include + extern SwitchLib u_btn; + extern SwitchLib d_btn; + extern SwitchLib l_btn; + extern SwitchLib r_btn; + extern SwitchLib c_btn; +#endif extern Display display_obj; extern WiFiScan wifi_scan_obj; @@ -22,19 +31,6 @@ extern EspInterface esp_obj; extern A32u4Interface a32u4_obj; extern Settings settings_obj; -// Keypad start position, key sizes and spacing -#define KEY_X 120 // Centre of key -#define KEY_Y 50 -#define KEY_W 240 // Width and height -#define KEY_H 22 -#define KEY_SPACING_X 0 // X and Y gap -#define KEY_SPACING_Y 1 -#define KEY_TEXTSIZE 1 // Font size multiplier -#define ICON_W 22 -#define ICON_H 22 -#define BUTTON_PADDING 22 -//#define BUTTON_ARRAY_LEN 5 - #define FLASH_BUTTON 0 #if BATTERY_ANALOG_ON == 1 @@ -106,6 +102,7 @@ struct Menu; struct MenuNode { String name; + String command; uint16_t color; int icon; TFT_eSPI_Button* button; @@ -118,7 +115,7 @@ struct Menu { String name; LinkedList* list; Menu * parentMenu; - //uint8_t selected; + uint8_t selected = 0; }; @@ -174,7 +171,7 @@ class MenuFunctions //TFT_eSPI_Button key[BUTTON_ARRAY_LEN]; - void addNodes(Menu* menu, String name, uint16_t color, Menu* child, int place, std::function callable, bool selected = false); + void addNodes(Menu* menu, String name, uint16_t color, Menu* child, int place, std::function callable, bool selected = false, String command = null); void drawStatusBar(); void updateStatusBar(); void battery(bool initial = false); @@ -183,6 +180,8 @@ class MenuFunctions String callSetting(String key); void runBoolSetting(String ley); void displaySetting(String key, Menu* menu, int index); + void buttonSelected(uint8_t b); + void buttonNotSelected(uint8_t b); public: MenuFunctions(); diff --git a/esp32_marauder/SDInterface.h b/esp32_marauder/SDInterface.h index 1bf5ce0..5b8b33d 100644 --- a/esp32_marauder/SDInterface.h +++ b/esp32_marauder/SDInterface.h @@ -4,13 +4,12 @@ #include "SD.h" #include "Buffer.h" #include "Display.h" +#include "configs.h" #include extern Buffer buffer_obj; extern Display display_obj; -#define SD_CS 12 - #ifdef KIT #define SD_DET 4 #endif diff --git a/esp32_marauder/WiFiScan.cpp b/esp32_marauder/WiFiScan.cpp index 2d8ac62..d0e2b19 100644 --- a/esp32_marauder/WiFiScan.cpp +++ b/esp32_marauder/WiFiScan.cpp @@ -431,24 +431,7 @@ void WiFiScan::StopScan(uint8_t scan_mode) else if ((currentScanMode == BT_SCAN_ALL) || (currentScanMode == BT_SCAN_SKIMMERS)) { - //Serial.println("Stopping BLE scan..."); - //pBLEScan->stop(); - //Serial.println("BLE Scan Stopped"); - - - //Serial.println("Clearing BLE Results..."); - //pBLEScan->clearResults(); - /*Serial.println("Deinitializing BT Controller..."); - BLEDevice::deinit(); - //Serial.println("Disable and Deinit BLE..."); - //esp_bt_controller_disable(); - //esp_bt_controller_deinit(); - //Serial.println("Releasing BLE Memory..."); - //esp_bt_controller_mem_release(ESP_BT_MODE_BLE); - //Serial.println("BT Controller Status: " + (String)esp_bt_controller_get_status()); - */ this->shutdownBLE(); - } display_obj.display_buffer->clear(); diff --git a/esp32_marauder/configs.h b/esp32_marauder/configs.h new file mode 100644 index 0000000..2d01d0d --- /dev/null +++ b/esp32_marauder/configs.h @@ -0,0 +1,188 @@ +#ifndef configs_h + + #define MARAUDER_MINI +// #define MARAUDER_V4 + + #define MARAUDER_VERSION "v0.9.6" + + //// BUTTON DEFINITIONS + #ifdef MARAUDER_MINI + #define L_BTN 13 + #define C_BTN 34 + #define U_BTN 36 + #define R_BTN 39 + #define D_BTN 35 + #endif + + #ifdef MARAUDER_V4 + #endif + //// END BUTTON DEFINITIONS + + //// DISPLAY DEFINITIONS + #ifdef MARAUDER_V4 + #define TFT_MISO 19 + #define TFT_MOSI 23 + #define TFT_SCLK 18 + #define TFT_CS 27 + #define TFT_DC 26 + #define TFT_RST 5 + #define TFT_BL 32 + #define TOUCH_CS 21 + #define SD_CS 4 + + #define BANNER_TEXT_SIZE 2 + + #ifndef TFT_WIDTH + #define TFT_WIDTH 240 + #endif + + #ifndef TFT_HEIGHT + #define TFT_HEIGHT 320 + #endif + + #define TFT_SHIELD + + #define SCREEN_WIDTH TFT_WIDTH + #define SCREEN_HEIGHT TFT_HEIGHT + #define HEIGHT_1 TFT_WIDTH + #define WIDTH_1 TFT_HEIGHT + #define STANDARD_FONT_CHAR_LIMIT (TFT_WIDTH/6) // number of characters on a single line with normal font + #define TEXT_HEIGHT 16 // Height of text to be printed and scrolled + #define BOT_FIXED_AREA 0 // Number of lines in bottom fixed area (lines counted from bottom of screen) + #define TOP_FIXED_AREA 48 // Number of lines in top fixed area (lines counted from top of screen) + #define YMAX 320 // Bottom of screen area + #define minimum(a,b) (((a) < (b)) ? (a) : (b)) + //#define MENU_FONT NULL + #define MENU_FONT &FreeMono9pt7b // Winner + //#define MENU_FONT &FreeMonoBold9pt7b + //#define MENU_FONT &FreeSans9pt7b + //#define MENU_FONT &FreeSansBold9pt7b + #define BUTTON_ARRAY_LEN 9 + #define STATUS_BAR_WIDTH 16 + #define LVGL_TICK_PERIOD 6 + + #define FRAME_X 100 + #define FRAME_Y 64 + #define FRAME_W 120 + #define FRAME_H 50 + + // Red zone size + #define REDBUTTON_X FRAME_X + #define REDBUTTON_Y FRAME_Y + #define REDBUTTON_W (FRAME_W/2) + #define REDBUTTON_H FRAME_H + + // Green zone size + #define GREENBUTTON_X (REDBUTTON_X + REDBUTTON_W) + #define GREENBUTTON_Y FRAME_Y + #define GREENBUTTON_W (FRAME_W/2) + #define GREENBUTTON_H FRAME_H + + #define STATUSBAR_COLOR 0x4A49 + + #define KIT_LED_BUILTIN 13 + #endif + + #ifdef MARAUDER_MINI + #define TFT_MISO 19 + #define TFT_MOSI 23 + #define TFT_SCLK 18 + #define TFT_CS 27 + #define TFT_DC 26 + #define TFT_RST 5 + #define TFT_BL 32 + #define TOUCH_CS 21 + #define SD_CS 4 + + #define BANNER_TEXT_SIZE 1 + + #ifndef TFT_WIDTH + #define TFT_WIDTH 128 + #endif + + #ifndef TFT_HEIGHT + #define TFT_HEIGHT 128 + #endif + + #define SCREEN_WIDTH TFT_WIDTH // Originally 240 + #define SCREEN_HEIGHT TFT_HEIGHT // Originally 320 + #define HEIGHT_1 TFT_WIDTH + #define WIDTH_1 TFT_WIDTH + #define STANDARD_FONT_CHAR_LIMIT (TFT_WIDTH/6) // number of characters on a single line with normal font + #define TEXT_HEIGHT (TFT_HEIGHT/10) // Height of text to be printed and scrolled + #define BOT_FIXED_AREA 0 // Number of lines in bottom fixed area (lines counted from bottom of screen) + #define TOP_FIXED_AREA 48 // Number of lines in top fixed area (lines counted from top of screen) + #define YMAX TFT_HEIGHT // Bottom of screen area + #define minimum(a,b) (((a) < (b)) ? (a) : (b)) + //#define MENU_FONT NULL + #define MENU_FONT &FreeMono9pt7b // Winner + //#define MENU_FONT &FreeMonoBold9pt7b + //#define MENU_FONT &FreeSans9pt7b + //#define MENU_FONT &FreeSansBold9pt7b + #define BUTTON_ARRAY_LEN 9 + #define STATUS_BAR_WIDTH (TFT_HEIGHT/16) + #define LVGL_TICK_PERIOD 6 + + #define FRAME_X 100 + #define FRAME_Y 64 + #define FRAME_W 120 + #define FRAME_H 50 + + // Red zone size + #define REDBUTTON_X FRAME_X + #define REDBUTTON_Y FRAME_Y + #define REDBUTTON_W (FRAME_W/2) + #define REDBUTTON_H FRAME_H + + // Green zone size + #define GREENBUTTON_X (REDBUTTON_X + REDBUTTON_W) + #define GREENBUTTON_Y FRAME_Y + #define GREENBUTTON_W (FRAME_W/2) + #define GREENBUTTON_H FRAME_H + + #define STATUSBAR_COLOR 0x4A49 + #endif + //// END DISPLAY DEFINITIONS + + //// MENU DEFINITIONS + #ifdef MARAUDER_V4 + // Keypad start position, key sizes and spacing + #define KEY_X 120 // Centre of key + #define KEY_Y 50 + #define KEY_W 240 // Width and height + #define KEY_H 22 + #define KEY_SPACING_X 0 // X and Y gap + #define KEY_SPACING_Y 1 + #define KEY_TEXTSIZE 1 // Font size multiplier + #define ICON_W 22 + #define ICON_H 22 + #define BUTTON_PADDING 22 + //#define BUTTON_ARRAY_LEN 5 + #endif + + #ifdef MARAUDER_MINI + // Keypad start position, key sizes and spacing + #define KEY_X (TFT_WIDTH/2) // Centre of key + #define KEY_Y (TFT_HEIGHT/4.5) + #define KEY_W TFT_WIDTH // Width and height + #define KEY_H (TFT_HEIGHT/10) + #define KEY_SPACING_X 0 // X and Y gap + #define KEY_SPACING_Y 1 + #define KEY_TEXTSIZE 1 // Font size multiplier + #define ICON_W 22 + #define ICON_H 22 + #define BUTTON_PADDING 10 + #endif + //// END MENU DEFINITIONS + + //// SD DEFINITIONS + #ifdef MARAUDER_V4 + #define SD_CS 12 + #endif + + #ifdef MARAUDER_MINI + #define SD_CS 4 + #endif + //// END SD DEFINITIONS + +#endif diff --git a/esp32_marauder/esp32_marauder.ino b/esp32_marauder/esp32_marauder.ino index 5816ed7..af8d87c 100644 --- a/esp32_marauder/esp32_marauder.ino +++ b/esp32_marauder/esp32_marauder.ino @@ -29,18 +29,16 @@ https://www.online-utility.org/image/convert/to/XBM #include "esp_interface.h" #include "a32u4_interface.h" #include "settings.h" -//#include "icons.h" +#include "configs.h" -/* -#ifdef __cplusplus -extern "C" { +#ifdef MARAUDER_MINI + #include + SwitchLib u_btn = SwitchLib(U_BTN, 1000, true); + SwitchLib d_btn = SwitchLib(D_BTN, 1000, true); + SwitchLib l_btn = SwitchLib(L_BTN, 1000, true); + SwitchLib r_btn = SwitchLib(R_BTN, 1000, true); + SwitchLib c_btn = SwitchLib(C_BTN, 1000, true); #endif -uint8_t temprature_sens_read(); -#ifdef __cplusplus -} -#endif -uint8_t temprature_sens_read(); -*/ Display display_obj; WiFiScan wifi_scan_obj; @@ -59,11 +57,31 @@ Adafruit_NeoPixel strip = Adafruit_NeoPixel(Pixels, PIN, NEO_GRB + NEO_KHZ800); uint32_t currentTime = 0; +void backlightOn() { + #ifdef MARAUDER_MINI + digitalWrite(TFT_BL, LOW); + #endif + + #ifndef MARAUDER_MINI + digitalWrite(TFT_BL, HIGH); + #endif +} + +void backlightOff() { + #ifdef MARAUDER_MINI + digitalWrite(TFT_BL, HIGH); + #endif + + #ifndef MARAUDER_MINI + digitalWrite(TFT_BL, LOW); + #endif +} + void setup() { pinMode(FLASH_BUTTON, INPUT); pinMode(TFT_BL, OUTPUT); - digitalWrite(TFT_BL, LOW); + backlightOff(); #if BATTERY_ANALOG_ON == 1 pinMode(BATTERY_PIN, OUTPUT); pinMode(CHARGING_PIN, INPUT); @@ -84,7 +102,7 @@ void setup() display_obj.RunSetup(); display_obj.tft.setTextColor(TFT_WHITE, TFT_BLACK); - digitalWrite(TFT_BL, LOW); + backlightOff(); // Draw the title screen display_obj.drawJpeg("/marauder3L.jpg", 0 , 0); // 240 x 320 image @@ -92,7 +110,7 @@ void setup() //showCenterText(version_number, 250); display_obj.tft.drawCentreString(display_obj.version_number, 120, 250, 2); - digitalWrite(TFT_BL, HIGH); // Need this + backlightOn(); // Need this delay(2000);