Skip to content

Commit

Permalink
displaySomething function and brightness settings
Browse files Browse the repository at this point in the history
rf.cpp will come in the next commit
  • Loading branch information
bmorcelli committed Dec 11, 2024
1 parent 6493593 commit 7ac6b97
Show file tree
Hide file tree
Showing 19 changed files with 68 additions and 65 deletions.
17 changes: 15 additions & 2 deletions src/core/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ void displaySuccess(String txt, bool waitKeyPress) {
while(waitKeyPress && !checkAnyKeyPress()) delay(100);
}

void displaySomething(String txt, bool waitKeyPress) {
#ifndef HAS_SCREEN
Serial.println("MESSAGE: " + txt);
return;
#endif
// todo: add newlines to txt if too long
displayRedStripe(txt, getComplementaryColor2(bruceConfig.priColor), bruceConfig.priColor);
delay(200);
while(waitKeyPress && !checkAnyKeyPress()) delay(100);
}


void setPadCursor(int16_t padx, int16_t pady) {
for (int y=0; y<pady; y++) tft.println();
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
Expand Down Expand Up @@ -285,8 +297,9 @@ int loopOptions(std::vector<Option>& options, bool bright, bool submenu, String
if(submenu) drawSubmenu(index, options, subText);
else coord=drawOptions(index, options, bruceConfig.priColor, bruceConfig.bgColor);
if(bright){
if(index!=5) setBrightness(String(options[index].label.c_str()).toInt(),false);
else setBrightness(bruceConfig.bright,false);
uint8_t bv = String(options[index].label.c_str()).toInt(); // Grabs the int value from menu option
if(bv>0) setBrightness(bv,false); // If valid, apply brightnes
else setBrightness(bruceConfig.bright,false); // if "Main Menu", bv==0, return brightness to default
}
redraw=false;
delay(REDRAW_DELAY);
Expand Down
10 changes: 5 additions & 5 deletions src/core/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ void setTftDisplay(int x = 0, int y = 0, uint16_t fc = tft.textcolor, int size =

void displayRedStripe(String text, uint16_t fgcolor = TFT_WHITE, uint16_t bgcolor = TFT_RED);

void displayError(String txt, bool waitKeyPress = false); // Faixa vermelha
void displayWarning(String txt, bool waitKeyPress = false);// Faixa amarela
void displayInfo(String txt, bool waitKeyPress = false); // Faixa Azul
void displaySuccess(String txt, bool waitKeyPress = false);// Faixa Verde

void displayError(String txt, bool waitKeyPress = false); // Red Stripe
void displayWarning(String txt, bool waitKeyPress = false); // Yellow Stripe
void displayInfo(String txt, bool waitKeyPress = false); // Blue Stripe
void displaySuccess(String txt, bool waitKeyPress = false); // Green Strupe
void displaySomething(String txt, bool waitKeyPress = false); // UI Colored stripe
void setPadCursor(int16_t padx=1, int16_t pady=0);

void padprintf(int16_t padx, const char *format, ...);
Expand Down
2 changes: 1 addition & 1 deletion src/core/wifi_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ bool wifiConnectMenu(wifi_mode_t mode)
case WIFI_STA: // station mode
int nets;
WiFi.mode(WIFI_MODE_STA);
displayRedStripe("Scanning..", getComplementaryColor2(bruceConfig.priColor), bruceConfig.priColor);
displaySomething("Scanning..");
nets = WiFi.scanNetworks();
options = {};
for (int i = 0; i < nets; i++) {
Expand Down
14 changes: 5 additions & 9 deletions src/modules/ble/bad_ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,23 +284,19 @@ void ble_setup() {
if (!kbChosen_ble) Kble.begin(); // starts the KeyboardLayout_en_US as default if nothing had beed chosen (cancel selection)
Ask_for_restart=1; // arm the flag
first_time=false;
displayRedStripe("Waiting Victim",getComplementaryColor2(bruceConfig.priColor), bruceConfig.priColor);
displaySomething("Waiting Victim");
}
while (!Kble.isConnected() && !checkEscPress());

if(Kble.isConnected()) {
BLEConnected=true;
displayRedStripe("Preparing",getComplementaryColor2(bruceConfig.priColor), bruceConfig.priColor);
displaySomething("Preparing");
delay(1000);
displayWarning(String(BTN_ALIAS) + " to deploy", true);
delay(200);
key_input_ble(*fs, bad_script);

displayRedStripe("Payload Sent",getComplementaryColor2(bruceConfig.priColor), bruceConfig.priColor);
checkSelPress();
while (!checkSelPress()) {
// nothing here, just to hold the screen press Ok of M5.
}
displaySomething("Payload Sent",true);
if(returnToMenu) goto End; // when cancel the run in the middle, go to End to turn off BLE services
// Try to run a new script on the same device

Expand All @@ -321,7 +317,7 @@ void ble_MediaCommands() {

if(!Kble.isConnected()) Kble.begin();

displayRedStripe("Pairing...",getComplementaryColor2(bruceConfig.priColor), bruceConfig.priColor);
displaySomething("Pairing...");

while (!Kble.isConnected() && !checkEscPress());

Expand Down Expand Up @@ -380,7 +376,7 @@ void ble_keyboard() {
if (!kbChosen_ble) Kble.begin(); // starts the KeyboardLayout_en_US as default if nothing had beed chosen (cancel selection)
Ask_for_restart=1;
Reconnect:
displayRedStripe("Pair to start",getComplementaryColor2(bruceConfig.priColor), bruceConfig.priColor);
displaySomething("Pair to start");

while (!Kble.isConnected() && !checkEscPress()); // loop to wait for the connection callback or ESC

Expand Down
2 changes: 1 addition & 1 deletion src/modules/ble/ble_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void ble_scan_setup()

void ble_scan()
{
displayRedStripe("Scanning..", getComplementaryColor2(bruceConfig.priColor), bruceConfig.priColor);
displaySomething("Scanning..");

options = { };
ble_scan_setup();
Expand Down
10 changes: 5 additions & 5 deletions src/modules/ble/ble_spam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,23 +451,23 @@ void aj_adv(int ble_choice){

switch(ble_choice){
case 0: // Applejuice
displayRedStripe("iOS Spam (" + String(count) + ")",getComplementaryColor2(bruceConfig.priColor),bruceConfig.priColor);
displaySomething("iOS Spam (" + String(count) + ")");
executeSpam(Apple);
break;
case 1: // SwiftPair
displayRedStripe("SwiftPair (" + String(count) + ")",getComplementaryColor2(bruceConfig.priColor),bruceConfig.priColor);
displaySomething("SwiftPair (" + String(count) + ")");
executeSpam(Microsoft);
break;
case 2: // Samsung
displayRedStripe("Samsung (" + String(count) + ")",getComplementaryColor2(bruceConfig.priColor),bruceConfig.priColor);
displaySomething("Samsung (" + String(count) + ")");
executeSpam(Samsung);
break;
case 3: // Android
displayRedStripe("Android (" + String(count) + ")",getComplementaryColor2(bruceConfig.priColor),bruceConfig.priColor);
displaySomething("Android (" + String(count) + ")");
executeSpam(Google);
break;
case 4: // Tutti-frutti
displayRedStripe("Spam All (" + String(count) + ")",getComplementaryColor2(bruceConfig.priColor),bruceConfig.priColor);
displaySomething("Spam All (" + String(count) + ")");
if(mael == 0) executeSpam(Google);
if(mael == 1) executeSpam(Samsung);
if(mael == 2) executeSpam(Microsoft);
Expand Down
15 changes: 6 additions & 9 deletions src/modules/fm/fm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ uint16_t fm_scan() {
min_noise = radio.currNoiseLevel;

tft.fillScreen(bruceConfig.bgColor);
displayRedStripe("Scanning...", getComplementaryColor2(bruceConfig.priColor), bruceConfig.priColor);
displaySomething("Scanning...");
for (f=8750; f<10800; f+=10) {
Serial.print("Measuring "); Serial.print(f); Serial.print("...");
radio.readTuneMeasure(f);
Expand All @@ -51,7 +51,7 @@ uint16_t fm_scan() {

sprintf(display_freq, "Found %d MHz", freq_candidate);
tft.fillScreen(bruceConfig.bgColor);
displayRedStripe(display_freq, getComplementaryColor2(bruceConfig.priColor), bruceConfig.priColor);
displaySomething(display_freq);
while(!checkEscPress() && !checkSelPress()) {
delay(100);
}
Expand All @@ -64,7 +64,7 @@ void fm_options_frq(uint16_t f_min, bool reserved) {
char f_str[5];
uint16_t f_max;
// Choose between scan for best freq or select freq
displayRedStripe("Choose frequency", getComplementaryColor2(bruceConfig.priColor), bruceConfig.priColor);
displaySomething("Choose frequency");
delay(1000);

// Handle min / max frequency
Expand Down Expand Up @@ -96,7 +96,7 @@ void fm_options_digit(uint16_t f_min, bool reserved) {
char f_str[5];
uint16_t f_max;
// Choose between scan for best freq or select freq
displayRedStripe("Choose digit", getComplementaryColor2(bruceConfig.priColor), bruceConfig.priColor);
displaySomething("Choose digit");
delay(1000);

// Handle min / max frequency
Expand Down Expand Up @@ -133,7 +133,7 @@ void fm_options_digit(uint16_t f_min, bool reserved) {
void fm_options(uint16_t f_min, uint16_t f_max, bool reserved) {
char f_str[5];
// Choose between scan for best freq or select freq
displayRedStripe("Choose tens", getComplementaryColor2(bruceConfig.priColor), bruceConfig.priColor);
displaySomething("Choose tens");
delay(1000);

options = { };
Expand Down Expand Up @@ -229,10 +229,7 @@ bool fm_begin() {
if (!radio.begin()) { // begin with address 0x63 (CS high default)
tft.fillScreen(bruceConfig.bgColor);
Serial.println("Cannot find radio");
displayRedStripe("Cannot find radio", getComplementaryColor2(bruceConfig.priColor), bruceConfig.priColor);
while(!checkEscPress() && !checkSelPress()) {
delay(100);
}
displaySomething("Cannot find radio",true);
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/gps/gps_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ bool GPSTracker::begin_gps() {
end();
return false;
}
displayRedStripe("Waiting GPS: " + String(count)+ "s", getComplementaryColor2(bruceConfig.priColor), bruceConfig.priColor);
displaySomething("Waiting GPS: " + String(count)+ "s");
count++;
delay(1000);
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/gps/wardriving.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ bool Wardriving::begin_gps() {
end();
return false;
}
displayRedStripe("Waiting GPS: " + String(count)+ "s", getComplementaryColor2(bruceConfig.priColor), bruceConfig.priColor);
displaySomething("Waiting GPS: " + String(count)+ "s");
count++;
delay(1000);
}
Expand Down
6 changes: 3 additions & 3 deletions src/modules/ir/TV-B-Gone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void StartTvBGone() {
if (checkSelPress()) // Pause TV-B-Gone
{
while (checkSelPress()) yield();
displayRedStripe("Paused", getComplementaryColor2(bruceConfig.priColor), bruceConfig.bgColor);
displaySomething("Paused");

while (!checkSelPress()){ // If Presses Select again, continues
if(checkEscPress()) {
Expand All @@ -181,15 +181,15 @@ void StartTvBGone() {
yield();
}
if (endingEarly) break; // Cancels TV-B-Gone
displayRedStripe("Running, Wait", getComplementaryColor2(bruceConfig.priColor), bruceConfig.priColor);
displaySomething("Running, Wait");
}

} //end of POWER code for loop


if (endingEarly==false)
{
displayRedStripe("All codes sent!", getComplementaryColor2(bruceConfig.priColor), bruceConfig.priColor);
displaySomething("All codes sent!");
//pause for ~1.3 sec, then flash the visible LED 8 times to indicate that we're done
delay_ten_us(MAX_WAIT_TIME); // wait 655.350ms
delay_ten_us(MAX_WAIT_TIME); // wait 655.350ms
Expand Down
20 changes: 10 additions & 10 deletions src/modules/ir/custom_ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ bool txIrFile(FS *fs, String filepath) {
if (checkSelPress()) // Pause TV-B-Gone
{
while (checkSelPress()) yield();
displayRedStripe("Paused", getComplementaryColor2(bruceConfig.priColor), bruceConfig.bgColor);
displaySomething("Paused");

while (!checkSelPress()){ // If Presses Select again, continues
if(checkEscPress()) {
Expand All @@ -211,7 +211,7 @@ bool txIrFile(FS *fs, String filepath) {
yield();
}
if (endingEarly) break; // Cancels custom IR Spam
displayRedStripe("Running, Wait", getComplementaryColor2(bruceConfig.priColor), bruceConfig.priColor);
displaySomething("Running, Wait");
}
} // end while file has lines to process
databaseFile.close();
Expand Down Expand Up @@ -350,7 +350,7 @@ void otherIRcodes() {
void sendNECCommand(String address, String command) {
IRsend irsend(bruceConfig.irTx); // Set the GPIO to be used to sending the message.
irsend.begin();
displayRedStripe("Sending..",getComplementaryColor2(bruceConfig.priColor),bruceConfig.priColor);
displaySomething("Sending..");
uint8_t first_zero_byte_pos = address.indexOf("00", 2);
if(first_zero_byte_pos!=-1) address = address.substring(0, first_zero_byte_pos);
first_zero_byte_pos = command.indexOf("00", 2);
Expand All @@ -367,7 +367,7 @@ void sendNECCommand(String address, String command) {
void sendRC5Command(String address, String command) {
IRsend irsend(bruceConfig.irTx,true); // Set the GPIO to be used to sending the message.
irsend.begin();
displayRedStripe("Sending..",getComplementaryColor2(bruceConfig.priColor),bruceConfig.priColor);
displaySomething("Sending..");
uint8_t addressValue = strtoul(address.substring(0,2).c_str(), nullptr, 16);
uint8_t commandValue = strtoul(command.substring(0,2).c_str(), nullptr, 16);
uint16_t data = irsend.encodeRC5(addressValue, commandValue);
Expand All @@ -379,7 +379,7 @@ void sendRC5Command(String address, String command) {
void sendRC6Command(String address, String command) {
IRsend irsend(bruceConfig.irTx,true); // Set the GPIO to be used to sending the message.
irsend.begin();
displayRedStripe("Sending..",getComplementaryColor2(bruceConfig.priColor),bruceConfig.priColor);
displaySomething("Sending..");
uint32_t addressValue = strtoul(address.c_str(), nullptr, 16);
uint32_t commandValue = strtoul(command.c_str(), nullptr, 16);
uint64_t data = irsend.encodeRC6(addressValue, commandValue);
Expand All @@ -391,7 +391,7 @@ void sendRC6Command(String address, String command) {
void sendSamsungCommand(String address, String command) {
IRsend irsend(bruceConfig.irTx); // Set the GPIO to be used to sending the message.
irsend.begin();
displayRedStripe("Sending..",getComplementaryColor2(bruceConfig.priColor),bruceConfig.priColor);
displaySomething("Sending..");
//uint64_t data = ((uint64_t)strtoul(address.c_str(), nullptr, 16) << 32) | strtoul(command.c_str(), nullptr, 16);
uint32_t addressValue = strtoul(address.c_str(), nullptr, 16);
uint32_t commandValue = strtoul(command.c_str(), nullptr, 16);
Expand All @@ -406,7 +406,7 @@ void sendSamsungCommand(String address, String command) {
void sendSonyCommand(String address, String command) {
IRsend irsend(bruceConfig.irTx); // Set the GPIO to be used to sending the message.
irsend.begin();
displayRedStripe("Sending..",getComplementaryColor2(bruceConfig.priColor),bruceConfig.priColor);
displaySomething("Sending..");
uint16_t commandValue = strtoul(command.substring(0,2).c_str(), nullptr, 16);
uint16_t addressValue = strtoul(address.substring(0,2).c_str(), nullptr, 16);
uint16_t addressValue2 = strtoul(address.substring(3,6).c_str(), nullptr, 16);
Expand All @@ -422,7 +422,7 @@ void sendSonyCommand(String address, String command) {
void sendPanasonicCommand(String address, String command) {
IRsend irsend(bruceConfig.irTx); // Set the GPIO to be used to sending the message.
irsend.begin();
displayRedStripe("Sending..",getComplementaryColor2(bruceConfig.priColor),bruceConfig.priColor);
displaySomething("Sending..");
uint8_t first_zero_byte_pos = address.indexOf("00", 2);
if(first_zero_byte_pos!=-1) address = address.substring(0, first_zero_byte_pos);
// needs to invert endianess
Expand Down Expand Up @@ -455,7 +455,7 @@ bool sendDecodedCommand(String protocol, String value, String bits) {
IRsend irsend(bruceConfig.irTx); // Set the GPIO to be used to sending the message.
irsend.begin();
bool success = false;
displayRedStripe("Sending..",getComplementaryColor2(bruceConfig.priColor),bruceConfig.priColor);
displaySomething("Sending..");

if(hasACState(type)) {
// need to send the state (still passed from value)
Expand Down Expand Up @@ -488,7 +488,7 @@ bool sendDecodedCommand(String protocol, String value, String bits) {
void sendRawCommand(uint16_t frequency, String rawData) {
IRsend irsend(bruceConfig.irTx); // Set the GPIO to be used to sending the message.
irsend.begin();
displayRedStripe("Sending..",getComplementaryColor2(bruceConfig.priColor),bruceConfig.priColor);
displaySomething("Sending..");
uint16_t dataBuffer[SAFE_STACK_BUFFER_SIZE/2]; // MEMO: stack overflow with full buffer size
uint16_t count = 0;

Expand Down
11 changes: 4 additions & 7 deletions src/modules/others/bad_usb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ void usb_setup() {
mySerial.write(0x00);
while(mySerial.available()<=0) {
if(mySerial.available()<=0) {
displayRedStripe("CH9329 -> USB",getComplementaryColor2(bruceConfig.priColor),bruceConfig.priColor);
displaySomething("CH9329 -> USB");
delay(200);
mySerial.write(0x00);
} else break;
Expand All @@ -309,19 +309,16 @@ void usb_setup() {
}
#endif

displayRedStripe("Preparing",getComplementaryColor2(bruceConfig.priColor), bruceConfig.priColor); // Time to Computer or device recognize the USB HID
displaySomething("Preparing"); // Time to Computer or device recognize the USB HID
delay(2000);
first_time=false;
}
displayWarning(String(BTN_ALIAS) + " to deploy", true);
delay(200);
key_input(*fs, bad_script);

displayRedStripe("Payload Sent",getComplementaryColor2(bruceConfig.priColor), bruceConfig.priColor);
checkSelPress();
while (!checkSelPress()) {
// nothing here, just to hold the screen press Ok of M5.
}
displaySomething("Payload Sent",true);

if(returnToMenu) return;
// Try to run a new script on the same device
goto NewScript;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/pwnagotchi/spam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ void send_pwnagotchi_beacon_main() {

// Check if file was loaded
if (num_faces == 0 or num_names == 0) {
displayRedStripe("No config file", getComplementaryColor2(bruceConfig.priColor), bruceConfig.priColor);
displaySomething("No config file");
delay(1000);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/wifi/ap_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void fillInfo(ScrollableTextArea& area){

const auto mac = MAC(ap_info.bssid);

displayRedStripe("Gathering...",getComplementaryColor2(bruceConfig.priColor),bruceConfig.priColor);
displaySomething("Gathering...");

// in promiscius mode also Rx/Tx can be gathered
// organized in the most to least usable
Expand Down
2 changes: 1 addition & 1 deletion src/modules/wifi/clients.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ void telnet_loop() {

Serial.println("Connected to TELNET server");
tft.setTextColor(TFT_GREEN, bruceConfig.bgColor);
displayRedStripe("Connected to TELNET server", getComplementaryColor2(bruceConfig.priColor), TFT_DARKGREEN );
displaySomething("Connected to TELNET server");
tft.setTextColor(bruceConfig.priColor, bruceConfig.bgColor);
delay(2000);
tft.fillScreen(bruceConfig.bgColor);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/wifi/evil_portal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ bool EvilPortal::setup() {

void EvilPortal::beginAP() {
drawMainBorderWithTitle("EVIL PORTAL");
displayRedStripe("Starting...", getComplementaryColor2(bruceConfig.priColor), bruceConfig.priColor);
displaySomething("Starting...");

WiFi.mode(WIFI_MODE_AP);
WiFi.softAPConfig(apGateway, apGateway, IPAddress(255, 255, 255, 0));
Expand Down
Loading

0 comments on commit 7ac6b97

Please sign in to comment.