Skip to content

Commit

Permalink
v1.62 Loader / TextGotchi/CTRLGotchi / (wip) Deauthergotchi
Browse files Browse the repository at this point in the history
PRO : added new loader that can change the behaviour of your device
Textgotchi : ESPNOW Chat between netgotchi PROs
CTRLGotchi : Control remotely pins, or via timers
DEAUTHERGOTCHI : WIP -- not complete yet
  • Loading branch information
mxzz committed Oct 14, 2024
1 parent 9ff728a commit 4b4c1ee
Show file tree
Hide file tree
Showing 8 changed files with 638 additions and 59 deletions.
85 changes: 45 additions & 40 deletions netgotchi/buttons.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@ Button2 buttonA;
Button2 buttonB;


void buttonsInit()
{
//change your pins configurations
buttonA.begin(BTN_A);
buttonA.setID(BTN_A);
buttonB.begin(BTN_B);
buttonB.setID(BTN_B);
buttonLeft.begin(BTN_LEFT);
buttonLeft.setID(BTN_LEFT);
buttonRight.begin(BTN_RIGHT);
buttonRight.setID(BTN_RIGHT);
void buttonsInit() {
//change your pins configurations
buttonA.begin(BTN_A);
buttonA.setID(BTN_A);
buttonB.begin(BTN_B);
buttonB.setID(BTN_B);
buttonLeft.begin(BTN_LEFT);
buttonLeft.setID(BTN_LEFT);
buttonRight.begin(BTN_RIGHT);
buttonRight.setID(BTN_RIGHT);

buttonA.setPressedHandler(buttonPressed);
buttonB.setPressedHandler(buttonPressed);
buttonLeft.setPressedHandler(buttonPressed);
buttonRight.setPressedHandler(buttonPressed);
buttonA.setPressedHandler(buttonPressed);
buttonB.setPressedHandler(buttonPressed);
buttonLeft.setPressedHandler(buttonPressed);
buttonRight.setPressedHandler(buttonPressed);
}

void buttonLoops() {
Expand All @@ -33,8 +32,17 @@ void buttonLoops() {
}
}

void resetSettings()
{
void checkOfflineMode() {

if (digitalRead(BTN_A) == LOW) {
delay(50);
if (digitalRead(BTN_A) == LOW) {
enableNetworkMode = false;
}
}
}

void resetSettings() {
displayClearDisplay();
displayPrintln("Flash button pressed. WiFiManager settings...");
wifiManager.resetSettings();
Expand All @@ -44,8 +52,7 @@ void resetSettings()
ESP.restart();
}

void controlsButtonLoop()
{
void controlsButtonLoop() {
buttonA.loop();
buttonB.loop();
buttonLeft.loop();
Expand All @@ -59,32 +66,30 @@ void buttonPressed(Button2 &btn) {
handleButtons(btn.getID());
}

void handleButtons(int btnID)
{
switch (btnID){
case BTN_A:
//A
if(settingMode)settingConfirm();
break;
void handleButtons(int btnID) {
switch (btnID) {
case BTN_A:
//A
if (settingMode) settingConfirm();
break;

case BTN_B:
//B
if(settingMode)settingCancel();
break;
//B
if (settingMode) settingCancel();
break;

case BTN_LEFT:
//RIGHT
nextScreen();
break;
//RIGHT
nextScreen();
break;

case BTN_RIGHT:
//DOWN
settingMode = true;
if(settingMode)
{
selectedSetting++;
if(selectedSetting> settingLength )selectedSetting=0;
}
break;
//DOWN
settingMode = true;
if (settingMode) {
selectedSetting++;
if (selectedSetting > settingLength) selectedSetting = 0;
}
break;
}
}
246 changes: 246 additions & 0 deletions netgotchi/ctrlgotchi.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
#include <espnow.h>

String command[] = {"< ESPNOW RECEIVER >","< ESPNOW SENDER >", "< ON >", "< OFF >" , "< TIME 1min >", "< TIME 15min >", "< TIME 1h >", "< TIME 8h >", };
String ctrlmessage = "";
int commandLength=7;
int ctrlselectedMode = 0;

String ctrlface = "(éwè)";
unsigned long ctrlpreviousMillis = 0;
const long ctrlinterval = 3000; // timer at which to change the face
String ctrlstatus = "__";
bool remote_controlled_status=false;
unsigned long previousMillisctrl = 0;
bool ctrltimerstarted=false;

struct_message ctrlmyData;

Button2 ctrlloaderButtonLeft;
Button2 ctrlloaderButtonRight;
Button2 ctrlloaderButtonA;
Button2 ctrlloaderButtonB;

long ctrltimer = 0;

void ctrlLeftButtonPressed(Button2 &btn) {
ctrlselectedMode--;
if(ctrlselectedMode< 0 )ctrlselectedMode=commandLength-1;
}

void ctrlRightButtonPressed(Button2 &btn) {
ctrlselectedMode++;
if(ctrlselectedMode>=commandLength)ctrlselectedMode=0;
}

void ctrlAButtonPressed(Button2 &btn) {
playTone();
if(ctrlselectedMode == 0)
{
//display.println("Press A to control");
}
if(ctrlselectedMode == 1)
{
//display.println("Press A to send ON");
crtlgotchi_sendMessage("CTRL:TRIGGER");
}
if(ctrlselectedMode == 2)
{
raisePinVoltage();
ctrlstatus="TRG";
}
if(ctrlselectedMode == 3)
{
lowerPinVoltage();
ctrlstatus="LWR";

}
if(ctrlselectedMode == 4)
{
ctrltimer=60 * 1000;
}
if(ctrlselectedMode == 5)
{
ctrltimer=5 *60 * 1000;
}
if(ctrlselectedMode == 6)
{
ctrltimer=60 *60 * 1000;
}
if(ctrlselectedMode == 7)
{
ctrltimer=8*60 *60 * 1000;
}
}
void ctrlBButtonPressed(Button2 &btn) {
playTone();

}


void ctrlgotchi_setup()
{
WiFi.mode(WIFI_STA);

if (esp_now_init() != ERR_OK) {
Serial.println("Error initializing ESP-NOW");
return;
}

esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
esp_now_register_recv_cb(crtlgotchi_OnDataRecv);

displayClearDisplay();

ctrlloaderButtonLeft.begin(BTN_LEFT);
ctrlloaderButtonRight.begin(BTN_RIGHT);
ctrlloaderButtonA.begin(BTN_A);
ctrlloaderButtonB.begin(BTN_B);
ctrlloaderButtonLeft.setPressedHandler(ctrlLeftButtonPressed);
ctrlloaderButtonRight.setPressedHandler(ctrlRightButtonPressed);
ctrlloaderButtonA.setPressedHandler(ctrlAButtonPressed);
ctrlloaderButtonB.setPressedHandler(ctrlBButtonPressed);
}

void ctrlgotchi_loop()
{
crtlgotchi_updateDisplay();
crtlgotchi_loopFace();

ctrlloaderButtonLeft.loop();
ctrlloaderButtonRight.loop();
ctrlloaderButtonA.loop();
ctrlloaderButtonB.loop();

if(ctrltimer > 0 ){
unsigned long currentMillisctrl = millis();
if(!ctrltimerstarted) {
ctrltimerstarted = true;
previousMillisctrl=millis();
}
if (currentMillisctrl - previousMillisctrl >= ctrltimer) {
// Enable pin 0 after the interval
raisePinVoltage();
ctrltimer=0;
ctrlstatus="TRG";
ctrltimerstarted=false;

}
}

if(remote_controlled_status && ctrlselectedMode == 0)
{
raisePinVoltage();
ctrlstatus="TRG";

}
if(!remote_controlled_status && ctrlselectedMode == 0)
{
lowerPinVoltage();
ctrlstatus="LWR";

}
}

void crtlgotchi_loopFace() {
unsigned long currentMillis = millis();
if (currentMillis - ctrlpreviousMillis >= ctrlinterval) {
ctrlpreviousMillis = currentMillis;
crtlgotchi_changeFace();
}
}

void crtlgotchi_changeFace() {
static int index = 0;
// Array of different emoticons
const String ctrlfaces[] = {
" (v^v) ",
" (^-^) ",
"(-_-) ",
"(.__.) ",
" (p_p) ",
" (._.)",
"(,_,) ",
" (o_o) "
};
// Update the face variable
ctrlface = ctrlfaces[index];
// Move to the next ctrlface in the array
index = (index + 1) % (sizeof(ctrlfaces) / sizeof(ctrlfaces[0])); // Loop back to the start when reaching the end
}




void crtlgotchi_sendMessage(const String &msg) {

msg.toCharArray(ctrlmyData.text, sizeof(ctrlmyData.text));

ctrlstatus = esp_now_send(broadcastAddress, (uint8_t *)&ctrlmyData, sizeof(ctrlmyData)) == 0 ? "OK" : "ER";
Serial.println("status:");
Serial.println(ctrlstatus);
}

void crtlgotchi_OnDataRecv(uint8_t *mac, uint8_t *incomingData, uint8_t len) {
display.clearDisplay(); // Clear the display
ctrlmessage = ""; // Reset the received message
memcpy(&ctrlmyData, incomingData, sizeof(ctrlmyData));
ctrlmessage = String(ctrlmyData.text);
if(ctrlmessage=="CTRL:TRIGGER" && ctrlselectedMode == 0)
{
playTone(); // Play tone when a new message is received
remote_controlled_status = !remote_controlled_status;
}
}

void crtlgotchi_updateDisplay() {
display.clearDisplay();
// Display received and sent messages at the top
display.setTextSize(1);
display.setCursor(0, 5);
display.print("CTRLGOTCHI " + ctrlface + "" + ctrlstatus);
display.setCursor(0, 15);
display.print("PIN D0 CONTROL :");
display.println(ctrlmessage);
display.println(" ");
displayPrintln(command[ctrlselectedMode]);
display.println(" ");

if(ctrlselectedMode == 0)
{
display.println("D0 Control enabled ");
}
if(ctrlselectedMode == 1)
{
display.println("Press A to send ON/OFF");
}
if(ctrlselectedMode == 2)
{
display.println("Press A to enable D0");
}
if(ctrlselectedMode == 3)
{
display.println("Press A to disable D0");
}
if(ctrlselectedMode == 4)
{
display.println("D0 timer - 1min");
}
if(ctrlselectedMode == 5)
{
display.println("D0 timer - 15min");
}
if(ctrlselectedMode == 6)
{
display.println("D0 timer - 1h");
}
if(ctrlselectedMode == 7)
{
display.println("D0 timer - 8h");
}

display.display();
}



20 changes: 20 additions & 0 deletions netgotchi/deauthergotchi.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//work in progress!

void deauthergotchi_setup()
{
displayClearDisplay();
delay(500);
display.setTextSize(1);
display.setCursor(0, 5);
display.println("DEAUTHERGOTCHI");
display.println("");
display.println("Work in progress..");
display.println("Restarting...");
display.display();
}

void deauthergotchi_loop()
{
delay(5000);
ESP.restart();
}
Loading

0 comments on commit 4b4c1ee

Please sign in to comment.