Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle merge before changing docs #55

Merged
merged 2 commits into from
Jul 20, 2024
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
165 changes: 84 additions & 81 deletions minigotchi-ESP32/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ Adafruit_SSD1306 *Display::ssd1306_adafruit_display = nullptr;
Adafruit_SSD1305 *Display::ssd1305_adafruit_display = nullptr;
U8G2_SSD1306_128X64_NONAME_F_SW_I2C *Display::ssd1306_ideaspark_display =
nullptr;
U8G2_SH1106_128X64_NONAME_F_SW_I2C *Display::sh1106_adafruit_display =
nullptr;
U8G2_SH1106_128X64_NONAME_F_SW_I2C *Display::sh1106_adafruit_display = nullptr;
TFT_eSPI *Display::tft_display = nullptr;

String Display::storedFace = "";
Expand Down Expand Up @@ -95,7 +94,8 @@ void Display::startScreen() {
ssd1306_ideaspark_display->begin();
delay(100);
} else if (Config::screen == "SH1106") {
sh1106_adafruit_display = new U8G2_SH1106_128X64_NONAME_F_SW_I2C(U8G2_R0, SH1106_SCL, SH1106_SDA, U8X8_PIN_NONE);
sh1106_adafruit_display = new U8G2_SH1106_128X64_NONAME_F_SW_I2C(
U8G2_R0, SH1106_SCL, SH1106_SDA, U8X8_PIN_NONE);
delay(100);
sh1106_adafruit_display->begin();
delay(100);
Expand Down Expand Up @@ -142,9 +142,9 @@ void Display::startScreen() {
ssd1306_ideaspark_display->clearBuffer();
delay(100);
} else if (Config::screen == "SH1106" &&
sh1106_adafruit_display != nullptr) {
sh1106_adafruit_display != nullptr) {
sh1106_adafruit_display->clearBuffer();
delay(100);
delay(100);
} else if (Config::screen == "M5STICKCP" ||
Config::screen == "M5STICKCP2" ||
Config::screen ==
Expand Down Expand Up @@ -338,86 +338,89 @@ void Display::updateDisplay(String face, String text) {
* @param data Text to print
*/
void Display::printU8G2Data(int x, int y, const char *data) {
if (Config::screen == "IDEASPARK_SSD1306") {
auto* screen = static_cast<U8G2_SSD1306_128X64_NONAME_F_SW_I2C*>(ssd1306_ideaspark_display);

int numCharPerLine = screen->getWidth() / screen->getMaxCharWidth();
if (strlen(data) <= numCharPerLine &&
screen->getStrWidth(data) <= screen->getWidth() - screen->getMaxCharWidth()) {
screen->drawStr(x, y, data);
} else {
int lineNum = 0;
char buf[numCharPerLine + 1];
memset(buf, 0, sizeof(buf));
for (int i = 0; i < strlen(data); ++i) {
if (data[i] != '\n') {
buf[strlen(buf)] = data[i];
}
if (data[i] == '\n' || strlen(buf) == numCharPerLine ||
i == strlen(data) - 1 ||
screen->getStrWidth(buf) >= screen->getWidth() - screen->getMaxCharWidth()) {
buf[strlen(buf)] = '\0';
screen->drawStr(
x,
y + (screen->getMaxCharHeight() * lineNum++) + 1,
buf);
memset(buf, 0, sizeof(buf));
}
}
}
} else if (Config::screen == "SH1106") {
auto* screen = static_cast<U8G2_SH1106_128X64_NONAME_F_SW_I2C*>(sh1106_adafruit_display);
if (Config::screen == "IDEASPARK_SSD1306") {
auto *screen = static_cast<U8G2_SSD1306_128X64_NONAME_F_SW_I2C *>(
ssd1306_ideaspark_display);

int numCharPerLine = screen->getWidth() / screen->getMaxCharWidth();
if (strlen(data) <= numCharPerLine &&
screen->getStrWidth(data) <= screen->getWidth() - screen->getMaxCharWidth()) {
screen->drawStr(x, y, data);
} else {
int lineNum = 0;
char buf[numCharPerLine + 1];
memset(buf, 0, sizeof(buf));
for (int i = 0; i < strlen(data); ++i) {
if (data[i] != '\n') {
buf[strlen(buf)] = data[i];
}
if (data[i] == '\n' || strlen(buf) == numCharPerLine ||
i == strlen(data) - 1 ||
screen->getStrWidth(buf) >= screen->getWidth() - screen->getMaxCharWidth()) {
buf[strlen(buf)] = '\0';
screen->drawStr(
x,
y + (screen->getMaxCharHeight() * lineNum++) + 1,
buf);
memset(buf, 0, sizeof(buf));
}
}
int numCharPerLine = screen->getWidth() / screen->getMaxCharWidth();
if (strlen(data) <= numCharPerLine &&
screen->getStrWidth(data) <=
screen->getWidth() - screen->getMaxCharWidth()) {
screen->drawStr(x, y, data);
} else {
int lineNum = 0;
char buf[numCharPerLine + 1];
memset(buf, 0, sizeof(buf));
for (int i = 0; i < strlen(data); ++i) {
if (data[i] != '\n') {
buf[strlen(buf)] = data[i];
}
if (data[i] == '\n' || strlen(buf) == numCharPerLine ||
i == strlen(data) - 1 ||
screen->getStrWidth(buf) >=
screen->getWidth() - screen->getMaxCharWidth()) {
buf[strlen(buf)] = '\0';
screen->drawStr(x, y + (screen->getMaxCharHeight() * lineNum++) + 1,
buf);
memset(buf, 0, sizeof(buf));
}
}
}
} else if (Config::screen == "SH1106") {
auto *screen = static_cast<U8G2_SH1106_128X64_NONAME_F_SW_I2C *>(
sh1106_adafruit_display);

int numCharPerLine = screen->getWidth() / screen->getMaxCharWidth();
if (strlen(data) <= numCharPerLine &&
screen->getStrWidth(data) <=
screen->getWidth() - screen->getMaxCharWidth()) {
screen->drawStr(x, y, data);
} else {
auto* screen = static_cast<U8G2_SSD1306_128X64_NONAME_F_SW_I2C*>(ssd1306_ideaspark_display);
int lineNum = 0;
char buf[numCharPerLine + 1];
memset(buf, 0, sizeof(buf));
for (int i = 0; i < strlen(data); ++i) {
if (data[i] != '\n') {
buf[strlen(buf)] = data[i];
}
if (data[i] == '\n' || strlen(buf) == numCharPerLine ||
i == strlen(data) - 1 ||
screen->getStrWidth(buf) >=
screen->getWidth() - screen->getMaxCharWidth()) {
buf[strlen(buf)] = '\0';
screen->drawStr(x, y + (screen->getMaxCharHeight() * lineNum++) + 1,
buf);
memset(buf, 0, sizeof(buf));
}
}
}
} else {
auto *screen = static_cast<U8G2_SSD1306_128X64_NONAME_F_SW_I2C *>(
ssd1306_ideaspark_display);

int numCharPerLine = screen->getWidth() / screen->getMaxCharWidth();
if (strlen(data) <= numCharPerLine &&
screen->getStrWidth(data) <= screen->getWidth() - screen->getMaxCharWidth()) {
screen->drawStr(x, y, data);
} else {
int lineNum = 0;
char buf[numCharPerLine + 1];
memset(buf, 0, sizeof(buf));
for (int i = 0; i < strlen(data); ++i) {
if (data[i] != '\n') {
buf[strlen(buf)] = data[i];
}
if (data[i] == '\n' || strlen(buf) == numCharPerLine ||
i == strlen(data) - 1 ||
screen->getStrWidth(buf) >= screen->getWidth() - screen->getMaxCharWidth()) {
buf[strlen(buf)] = '\0';
screen->drawStr(
x,
y + (screen->getMaxCharHeight() * lineNum++) + 1,
buf);
memset(buf, 0, sizeof(buf));
}
}
int numCharPerLine = screen->getWidth() / screen->getMaxCharWidth();
if (strlen(data) <= numCharPerLine &&
screen->getStrWidth(data) <=
screen->getWidth() - screen->getMaxCharWidth()) {
screen->drawStr(x, y, data);
} else {
int lineNum = 0;
char buf[numCharPerLine + 1];
memset(buf, 0, sizeof(buf));
for (int i = 0; i < strlen(data); ++i) {
if (data[i] != '\n') {
buf[strlen(buf)] = data[i];
}
if (data[i] == '\n' || strlen(buf) == numCharPerLine ||
i == strlen(data) - 1 ||
screen->getStrWidth(buf) >=
screen->getWidth() - screen->getMaxCharWidth()) {
buf[strlen(buf)] = '\0';
screen->drawStr(x, y + (screen->getMaxCharHeight() * lineNum++) + 1,
buf);
memset(buf, 0, sizeof(buf));
}
}
}
}
}
3 changes: 2 additions & 1 deletion minigotchi-ESP32/pwnagotchi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ void Pwnagotchi::stopCallback() { esp_wifi_set_promiscuous_rx_cb(nullptr); }

/**
* Pwnagotchi Scanning callback
* Source: https://github.com/justcallmekoko/ESP32Marauder/blob/master/esp32_marauder/WiFiScan.cpp#L2439
* Source:
* https://github.com/justcallmekoko/ESP32Marauder/blob/master/esp32_marauder/WiFiScan.cpp#L2439
* @param buf Packet recieved to use as a buffer
* @param len Length of the buffer
*/
Expand Down