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

Dev #232

Merged
merged 11 commits into from
Sep 3, 2024
Binary file added media/connections/cc1101_stick.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/connections/pn532_i2c.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/connections/pn532_spi.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
282 changes: 164 additions & 118 deletions platformio.ini

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/core/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,12 @@ int loopOptions(std::vector<Option>& options, bool bright, bool submenu, String
** Description: Função para manipular o progresso da atualização
** Dependencia: prog_handler =>> 0 - Flash, 1 - LittleFS
***************************************************************************************/
void progressHandler(int progress, size_t total) {
void progressHandler(int progress, size_t total, String message) {
int barWidth = map(progress, 0, total, 0, 200);
if(barWidth <3) {
tft.fillRect(6, 27, WIDTH-12, HEIGHT-33, BGCOLOR);
tft.drawRect(18, HEIGHT - 47, 204, 17, FGCOLOR);
displayRedStripe("Running, Wait", TFT_WHITE, FGCOLOR);
displayRedStripe(message, TFT_WHITE, FGCOLOR);
}
tft.fillRect(20, HEIGHT - 45, barWidth, 13, FGCOLOR);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void listFiles(int index, String fileList[][3]);

void drawWireguardStatus(int x, int y);

void progressHandler(int progress, size_t total);
void progressHandler(int progress, size_t total, String message = "Running, Wait");

int getBattery();

Expand Down
1 change: 1 addition & 0 deletions src/core/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ extern float RfFreq;
extern int RfidModule;

extern String cachedPassword;
extern String wigleBasicToken;

// Screen sleep control variables
extern unsigned long previousMillis;
Expand Down
56 changes: 56 additions & 0 deletions src/core/sd_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "modules/others/audio.h"
#include "modules/rf/rf.h"
#include "modules/ir/TV-B-Gone.h"
#include "modules/wifi/wigle.h"
#include "modules/others/bad_usb.h"
#include "modules/others/qrcode_menu.h"

Expand Down Expand Up @@ -624,6 +625,7 @@ String loopSD(FS &fs, bool filePicker, String allowed_ext) {
clearFileList(fileList);
options = {
{"View File", [=]() { viewFile(fs, filepath); }},
{"File Info", [=]() { fileInfo(fs, filepath); }},
{"Rename", [=]() { renameFile(fs, filepath, filename); }},
{"Copy", [=]() { copyFile(fs, filepath); }},
{"Delete", [=]() { deleteFromSd(fs, filepath); }},
Expand All @@ -642,6 +644,11 @@ String loopSD(FS &fs, bool filePicker, String allowed_ext) {
delay(200);
txSubFile(&fs, filepath);
}});
if(filepath.endsWith(".csv")) options.insert(options.begin(), {"Wigle Upload", [&]() {
delay(200);
Wigle wigle;
wigle.upload(&fs, filepath);
}});
#if defined(USB_as_HID)
if(filepath.endsWith(".txt")) {
options.push_back({"BadUSB Run", [&]() {
Expand Down Expand Up @@ -893,3 +900,52 @@ bool getFsStorage(FS *&fs) {

return true;
}

/*********************************************************************
** Function: fileInfo
** Display file info
**********************************************************************/
void fileInfo(FS fs, String filepath) {
tft.fillScreen(BGCOLOR);
tft.setCursor(0,0);
tft.setTextColor(FGCOLOR, BGCOLOR);
tft.setTextSize(FP);

File file = fs.open(filepath, FILE_READ);
if (!file) return;

int bytesize = file.size();
float filesize = bytesize;
String unit = "B";

time_t modifiedTime = file.getLastWrite();

if (filesize >= 1000000) {
filesize /= 1000000.0;
unit = "MB";
} else if (filesize >= 1000) {
filesize /= 1000.0;
unit = "kB";
}

padprintln("");
tft.drawCentreString("-"+String(file.name()), WIDTH/2, tft.getCursorY(), 1);
padprintln("\n");
padprintln("Path: " + filepath);
padprintln("");
padprintf("Bytes: %d\n", bytesize);
padprintln("");
padprintf("Size: %.02f %s\n", filesize, unit.c_str());
padprintln("");
padprintf("Modified: %s\n", ctime(&modifiedTime));

file.close();
delay(100);

while(1) {
if(checkEscPress() || checkSelPress()) break;
delay(100);
}

return;
}
2 changes: 2 additions & 0 deletions src/core/sd_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ bool checkLittleFsSize();
bool checkLittleFsSizeNM(); //Don't display msg

bool getFsStorage(FS *&fs);

void fileInfo(FS fs, String filepath);
7 changes: 5 additions & 2 deletions src/core/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -739,9 +739,9 @@ void getConfigs() {
if(file) {
// init with default settings
#if ROTATION >1
file.print("[{\"rot\":3,\"dimmerSet\":10,\"bright\":100,\"wui_usr\":\"admin\",\"wui_pwd\":\"bruce\",\"Bruce_FGCOLOR\":43023,\"IrTx\":"+String(LED)+",\"IrRx\":"+String(GROVE_SCL)+",\"RfTx\":"+String(GROVE_SDA)+",\"RfRx\":"+String(GROVE_SCL)+",\"tmz\":3,\"RfModule\":0,\"RfFreq\":433.92,\"RfidModule\":"+String(RfidModule)+",\"wifi\":[{\"ssid\":\"myNetSSID\",\"pwd\":\"myNetPassword\"}],\"devMode\":0}]");
file.print("[{\"rot\":3,\"dimmerSet\":10,\"bright\":100,\"wui_usr\":\"admin\",\"wui_pwd\":\"bruce\",\"Bruce_FGCOLOR\":43023,\"IrTx\":"+String(LED)+",\"IrRx\":"+String(GROVE_SCL)+",\"RfTx\":"+String(GROVE_SDA)+",\"RfRx\":"+String(GROVE_SCL)+",\"tmz\":3,\"RfModule\":0,\"RfFreq\":433.92,\"RfidModule\":"+String(RfidModule)+",\"wifi\":[{\"ssid\":\"myNetSSID\",\"pwd\":\"myNetPassword\"}],\"wigleBasicToken\":\"\",\"devMode\":0}]");
#else
file.print("[{\"rot\":1,\"dimmerSet\":10,\"bright\":100,\"wui_usr\":\"admin\",\"wui_pwd\":\"bruce\",\"Bruce_FGCOLOR\":43023,\"IrTx\":"+String(LED)+",\"IrRx\":"+String(GROVE_SCL)+",\"RfTx\":"+String(GROVE_SDA)+",\"RfRx\":"+String(GROVE_SCL)+",\"tmz\":3,\"RfModule\":0,\"RfFreq\":433.92,\"RfidModule\":"+String(RfidModule)+",\"wifi\":[{\"ssid\":\"myNetSSID\",\"pwd\":\"myNetPassword\"}],\"devMode\":0}]");
file.print("[{\"rot\":1,\"dimmerSet\":10,\"bright\":100,\"wui_usr\":\"admin\",\"wui_pwd\":\"bruce\",\"Bruce_FGCOLOR\":43023,\"IrTx\":"+String(LED)+",\"IrRx\":"+String(GROVE_SCL)+",\"RfTx\":"+String(GROVE_SDA)+",\"RfRx\":"+String(GROVE_SCL)+",\"tmz\":3,\"RfModule\":0,\"RfFreq\":433.92,\"RfidModule\":"+String(RfidModule)+",\"wifi\":[{\"ssid\":\"myNetSSID\",\"pwd\":\"myNetPassword\"}],\"wigleBasicToken\":\"\",\"devMode\":0}]");
#endif
}
file.close();
Expand Down Expand Up @@ -779,6 +779,8 @@ void getConfigs() {

if(!setting.containsKey("wifi")) { count++; log_i("Fail"); }

if(setting.containsKey("wigleBasicToken")) { wigleBasicToken = setting["wigleBasicToken"].as<String>(); } else { count++; log_i("Fail"); }

if(setting.containsKey("devMode")) { devMode = setting["devMode"].as<int>(); } else { count++; log_i("Fail"); }

log_i("Brightness: %d", bright);
Expand Down Expand Up @@ -852,6 +854,7 @@ void saveConfigs() {
WifiObj["pwd"] = "myNetPassword";
}
}
setting["wigleBasicToken"] = wigleBasicToken;
setting["devMode"] = devMode;
// Open file for writing
File file = fs->open(CONFIG_FILE, FILE_WRITE);
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ int RfModule=0; // 0 - single-pinned, 1 - CC1101+SPI
float RfFreq=433.92;
int RfidModule=M5_RFID2_MODULE;
String cachedPassword="";
String wigleBasicToken="";
int dimmerSet;
int bright=100;
int tmz=3;
Expand Down
24 changes: 22 additions & 2 deletions src/modules/rfid/PN532.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
PN532::PN532(bool use_i2c) {
_use_i2c = use_i2c;
if (use_i2c) nfc.set_interface();
else nfc.set_interface(0, GROVE_SDA, GROVE_SCL, 26);
else nfc.set_interface(SPI_SCK_PIN, SPI_MOSI_PIN, SPI_MISO_PIN, SPI_SS_PIN);
}

bool PN532::begin() {
Expand All @@ -38,7 +38,27 @@ int PN532::read() {
}

int PN532::clone() {
return NOT_IMPLEMENTED;
if (!PICC_IsNewCardPresent()) return TAG_NOT_PRESENT;
if (!readDetectedPassiveTargetID()) return FAILURE;

if (_tag_read_uid.sak != uid.sak) return TAG_NOT_MATCH;

uint8_t data[16];
byte bcc = 0;
int i;
for (i = 0; i < uid.size; i++) {
data[i] = uid.uidByte[i];
bcc = bcc ^ uid.uidByte[i];
}
data[i++] = bcc;
data[i++] = uid.sak;
data[i++] = uid.atqaByte[1];
data[i++] = uid.atqaByte[0];
byte tmp = 0;
while (i<16) data[i++] = 0x62+tmp++;

bool success = nfc.mifareclassic_WriteBlock0(data);
return success ? SUCCESS : FAILURE;
}

int PN532::erase() {
Expand Down
63 changes: 48 additions & 15 deletions src/modules/rfid/lib_pn532/Adafruit_I2CDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,20 @@ bool Adafruit_I2CDevice::detected(void) {

// A basic scanner, see if it ACK's
_wire->beginTransmission(_addr);
return (_wire->endTransmission() == 0);
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.print(F("Address 0x"));
DEBUG_SERIAL.print(_addr);
#endif
if (_wire->endTransmission() == 0) {
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.println(F(" Detected"));
#endif
return true;
}
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.println(F(" Not detected"));
#endif
return false;
}

/*!
Expand All @@ -80,6 +93,9 @@ bool Adafruit_I2CDevice::write(const uint8_t *buffer, size_t len, bool stop,
// currently not guaranteed to work if more than 32 bytes!
// we will need to find out if some platforms have larger
// I2C buffer sizes :/
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.println(F("\tI2CDevice could not write such a large buffer"));
#endif
return false;
}

Expand All @@ -88,12 +104,18 @@ bool Adafruit_I2CDevice::write(const uint8_t *buffer, size_t len, bool stop,
// Write the prefix data (usually an address)
if ((prefix_len != 0) && (prefix_buffer != nullptr)) {
if (_wire->write(prefix_buffer, prefix_len) != prefix_len) {
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.println(F("\tI2CDevice failed to write"));
#endif
return false;
}
}

// Write the data itself
if (_wire->write(buffer, len) != len) {
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.println(F("\tI2CDevice failed to write"));
#endif
return false;
}

Expand Down Expand Up @@ -124,8 +146,15 @@ bool Adafruit_I2CDevice::write(const uint8_t *buffer, size_t len, bool stop,
#endif

if (_wire->endTransmission(stop) == 0) {
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.println();
// DEBUG_SERIAL.println("Sent!");
#endif
return true;
} else {
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.println("\tFailed to send!");
#endif
return false;
}
}
Expand Down Expand Up @@ -162,27 +191,31 @@ bool Adafruit_I2CDevice::_read(uint8_t *buffer, size_t len, bool stop) {

if (recv != len) {
// Not enough data available to fulfill our obligation!
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.print(F("\tI2CDevice did not receive enough data: "));
DEBUG_SERIAL.println(recv);
#endif
return false;
}

for (uint16_t i = 0; i < len; i++) {
buffer[i] = _wire->read();
}

// #ifdef DEBUG_SERIAL
// DEBUG_SERIAL.print(F("\tI2CREAD @ 0x"));
// DEBUG_SERIAL.print(_addr, HEX);
// DEBUG_SERIAL.print(F(" :: "));
// for (uint16_t i = 0; i < len; i++) {
// DEBUG_SERIAL.print(F("0x"));
// DEBUG_SERIAL.print(buffer[i], HEX);
// DEBUG_SERIAL.print(F(", "));
// if (len % 32 == 31) {
// DEBUG_SERIAL.println();
// }
// }
// DEBUG_SERIAL.println();
// #endif
#ifdef DEBUG_SERIAL
DEBUG_SERIAL.print(F("\tI2CREAD @ 0x"));
DEBUG_SERIAL.print(_addr, HEX);
DEBUG_SERIAL.print(F(" :: "));
for (uint16_t i = 0; i < len; i++) {
DEBUG_SERIAL.print(F("0x"));
DEBUG_SERIAL.print(buffer[i], HEX);
DEBUG_SERIAL.print(F(", "));
if (len % 32 == 31) {
DEBUG_SERIAL.println();
}
}
DEBUG_SERIAL.println();
#endif

return true;
}
Expand Down
Loading
Loading