diff --git a/README.md b/README.md index 7a59eeb..0ee42e1 100644 --- a/README.md +++ b/README.md @@ -1,93 +1,19 @@ -# grA_21_Morpion_lumineux_code +# Morpion lumineux + +## SAE 203 + +

+ Quentin T'JAMPENS
+ Giovanni JOSSERAND
+

+### Bibliothèques utilisées -## Getting started - -To make it easy for you to get started with GitLab, here's a list of recommended next steps. - -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! - -## Add your files - -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command: - -``` -cd existing_repo -git remote add origin https://iutbg-gitlab.iutbourg.univ-lyon1.fr/sae_203_2025/grA_21_Morpion_lumineaux/gra_21_morpion_lumineux_code.git -git branch -M main -git push -uf origin main -``` - -## Integrate with your tools - -- [ ] [Set up project integrations](https://iutbg-gitlab.iutbourg.univ-lyon1.fr/sae_203_2025/grA_21_Morpion_lumineaux/gra_21_morpion_lumineux_code/-/settings/integrations) - -## Collaborate with your team - -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/) - -## Test and Deploy - -Use the built-in continuous integration in GitLab. - -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - -*** - -# Editing this README - -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template. - -## Suggestions for a good README - -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. - -## Name -Choose a self-explaining name for your project. - -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. - -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. - -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. - -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. - -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. - -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. - -## Contributing -State if you are open to contributions and what your requirements are for accepting them. - -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. - -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. - -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. - -## License -For open source projects, say how it is licensed. - -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. + \ No newline at end of file diff --git a/gra_21_morpion_lumineux_code.ino b/gra_21_morpion_lumineux_code.ino index 1f35bb1..1bf4e79 100644 --- a/gra_21_morpion_lumineux_code.ino +++ b/gra_21_morpion_lumineux_code.ino @@ -10,21 +10,29 @@ #include // --- Capteur capacitif --- -// Attention : Une SEULE instance globale ! Adafruit_MPR121 cap = Adafruit_MPR121(); uint16_t lasttouched = 0; uint16_t currtouched = 0; void setup() { Serial.begin(115200); + randomSeed(analogRead(0)); + pinMode(A2, INPUT); +<<<<<<< gra_21_morpion_lumineux_code.ino + +======= +>>>>>>> gra_21_morpion_lumineux_code.ino if (!cap.begin(0x5B)) { Serial.println("MPR121 not found, check wiring?"); while (1); } Serial.println("MPR121 found!"); +<<<<<<< gra_21_morpion_lumineux_code.ino +======= +>>>>>>> gra_21_morpion_lumineux_code.ino setupMenu(); } @@ -44,10 +52,13 @@ void loop() { } else { if(!isBtnSet){ setBtn(cap, lasttouched, currtouched); - }else{ - // Passe cap, lasttouched, currtouched par référence ! - localMode(cap, lasttouched, currtouched); + } else{ + if(solo) { + localModeSolo(cap, lasttouched, currtouched); + } + else { + localModeDuo(cap, lasttouched, currtouched); + } + } } - } - } } diff --git a/localMode.cpp b/localMode.cpp new file mode 100644 index 0000000..f1917b9 --- /dev/null +++ b/localMode.cpp @@ -0,0 +1,164 @@ +#include "localMode.h" +#include + +MechKey keys[] = { + {0, A0, false, Adafruit_NeoPixel(1, A0, NEO_GRB + NEO_KHZ800)}, + {1, 25, false, Adafruit_NeoPixel(1, 25, NEO_GRB + NEO_KHZ800)}, + {2, 34, false, Adafruit_NeoPixel(1, 34, NEO_GRB + NEO_KHZ800)}, + {3, 39, false, Adafruit_NeoPixel(1, 39, NEO_GRB + NEO_KHZ800)}, + {4, 36, false, Adafruit_NeoPixel(1, 36, NEO_GRB + NEO_KHZ800)}, + {5, 4, false, Adafruit_NeoPixel(1, 4, NEO_GRB + NEO_KHZ800)}, + {6, 14, false, Adafruit_NeoPixel(1, 14, NEO_GRB + NEO_KHZ800)}, + {7, 33, false, Adafruit_NeoPixel(1, 33, NEO_GRB + NEO_KHZ800)}, + {8, 15, false, Adafruit_NeoPixel(1, 15, NEO_GRB + NEO_KHZ800)}, +}; +const int numKeys = 9; + +int grille[3][3] = { + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0} +}; + +bool btns[9] = { false, false, false, false, false, false, false, false, false }; + +bool joueur1 = true; + +Coord getCo(int key) { + switch(key) { + case 0: return { 0, 0 }; + case 1: return { 1, 0 }; + case 2: return { 2, 0 }; + case 3: return { 0, 1 }; + case 4: return { 1, 1 }; + case 5: return { 2, 1 }; + case 6: return { 0, 2 }; + case 7: return { 1, 2 }; + case 8: return { 2, 2 }; + default: return { -1, -1 }; + } +} + +bool victoire(int grille[3][3], int joueur) { + // Vérification des lignes et colonnes + for (int i = 0; i < 3; ++i) { + if (grille[i][0] == joueur && grille[i][1] == joueur && grille[i][2] == joueur) + return true; + if (grille[0][i] == joueur && grille[1][i] == joueur && grille[2][i] == joueur) + return true; + } + // Vérification des deux diagonales + if (grille[0][0] == joueur && grille[1][1] == joueur && grille[2][2] == joueur) + return true; + if (grille[0][2] == joueur && grille[1][1] == joueur && grille[2][0] == joueur) + return true; + return false; +} + +bool allInit() { + for(int i = 0; i < 9; i++) { + if (!btns[i]) return false; + } + return true; +} + +void afficheGrille() { + Serial.println("=============="); + for(int i = 0; i < 3; i++) { + for(int j = 0; j < 3; j++) { + Serial.print(grille[i][j]); + } + Serial.println(); + } +} + +void reset() { + if(digitalRead(A2) == HIGH) { + Serial.println("Reset"); + + for(int i = 0; i < 3; i++) { + for(int j = 0; j < 3; j++) { + grille[i][j] = 0; + } + } + + joueur1 = true; + + afficheGrille(); + } +} + +void localModeDuo(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched) { + currtouched = cap.touched(); + reset(); + + for (int i = 0; i < numKeys; i++) { + uint8_t t = keys[i].touchID; + + if ((currtouched & _BV(t)) && !(lasttouched & _BV(t))) { + Serial.print("Touch "); Serial.print(t); Serial.println(" pressed"); + btns[i] = true; + + if(allInit()) { + Coord c = getCo(i); + if(grille[c.y][c.x] == 0) { + if(joueur1) { + grille[c.y][c.x] = 1; + afficheGrille(); + if(victoire(grille, 1)) { + Serial.println("Joueur 1 a gagne"); + } + } else { + grille[c.y][c.x] = 2; + afficheGrille(); + if(victoire(grille, 2)) { + Serial.println("Joueur 2 a gagne"); + } + } + joueur1 = !joueur1; + } + } + } + } + lasttouched = currtouched; +} + +void localModeSolo(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched) { + currtouched = cap.touched(); + reset(); + + for (int i = 0; i < numKeys; i++) { + uint8_t t = keys[i].touchID; + keys[i].led.setPixelColor(0, 255); // Bleu + keys[i].led.show(); + + if ((currtouched & _BV(t)) && !(lasttouched & _BV(t))) { + Serial.print("Touch "); Serial.print(t); Serial.println(" pressed"); + btns[i] = true; + + if(allInit()) { + Coord c = getCo(i); + if(grille[c.y][c.x] == 0) { + grille[c.y][c.x] = 1; + afficheGrille(); + if(victoire(grille, 1)) { + Serial.println("Joueur 1 a gagne"); + } + + int x, y; + do { + x = random(0, 3); + y = random(0, 3); + } while(grille[y][x] != 0); + + grille[y][x] = 2; + afficheGrille(); + if(victoire(grille, 2)) { + Serial.println("Joueur 2 a gagne"); + } + } + } + } + } + lasttouched = currtouched; +} diff --git a/localMode.h b/localMode.h index 55ec639..675f210 100644 --- a/localMode.h +++ b/localMode.h @@ -3,16 +3,17 @@ #include #include +#include "pin.h" #ifndef _BV #define _BV(bit) (1 << (bit)) #endif struct MechKey { - uint8_t touchID; // Index sur le MPR121 - uint8_t dataPin; // Broche de l'ESP32 vers NeoPixel - bool state; // État (toggle) - Adafruit_NeoPixel led; // Instance NeoPixel + uint8_t touchID; + uint8_t dataPin; + bool state; + Adafruit_NeoPixel led; }; struct Coord { @@ -20,141 +21,20 @@ struct Coord { int y; }; -uint8_t color_pos = 16; - -// Création tableau global, mais pas de capteurs ici ! -MechKey keys[] = { - {0, A0, false, Adafruit_NeoPixel(1, A0, NEO_GRB + NEO_KHZ800)}, - {1, 25, false, Adafruit_NeoPixel(1, 25, NEO_GRB + NEO_KHZ800)}, - {2, 34, false, Adafruit_NeoPixel(1, 34, NEO_GRB + NEO_KHZ800)}, - {3, 39, false, Adafruit_NeoPixel(1, 39, NEO_GRB + NEO_KHZ800)}, - {4, 36, false, Adafruit_NeoPixel(1, 36, NEO_GRB + NEO_KHZ800)}, - {5, 4, false, Adafruit_NeoPixel(1, 4, NEO_GRB + NEO_KHZ800)}, - {6, 14, false, Adafruit_NeoPixel(1, 14, NEO_GRB + NEO_KHZ800)}, - {7, 33, false, Adafruit_NeoPixel(1, 33, NEO_GRB + NEO_KHZ800)}, - {8, 15, false, Adafruit_NeoPixel(1, 15, NEO_GRB + NEO_KHZ800)}, -}; -const int numKeys = 9; - -int grille[3][3] = { - {0, 0, 0}, - {0, 0, 0}, - {0, 0, 0} -}; - -bool btns[9] = { false, false, false, false, false, false, false, false, false }; - -bool joueur1 = true; +extern uint8_t color_pos; +extern MechKey keys[]; +extern const int numKeys; +extern int grille[3][3]; +extern bool btns[9]; +extern bool joueur1; Coord getCo(int key); bool victoire(int grille[3][3], int joueur); bool allInit(); +void afficheGrille(); +void reset(); -void localMode(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched); +void localModeDuo(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched); +void localModeSolo(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched); -bool isBtnSet = false; - -#endif // LOCALMODE_H - - -void setBtn(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched){ - display.clearDisplay(); - display.setCursor(0, 0); - display.print("Veuillez rester\nappuye sur chaqu'un\ndes boutons pendant\n3 secondes avant de\nles relacher pour\nles initialiser"); - display.display(); - if(allInit()){ - isBtnSet = true; - }else{ - currtouched = cap.touched(); - for (int i = 0; i < numKeys; i++) { - uint8_t t = keys[i].touchID; - keys[i].led.setPixelColor(0, 255); // Bleu - keys[i].led.show(); - if ((currtouched & _BV(t)) && !(lasttouched & _BV(t))) { - Serial.print("Touch "); Serial.print(t); Serial.println(" pressed"); - btns[i] = true; - } - } - lasttouched = currtouched; - } -} - -Coord getCo(int key) { - switch(key) { - case 0: return { 0, 0 }; - case 1: return { 1, 0 }; - case 2: return { 2, 0 }; - case 3: return { 0, 1 }; - case 4: return { 1, 1 }; - case 5: return { 2, 1 }; - case 6: return { 0, 2 }; - case 7: return { 1, 2 }; - case 8: return { 2, 2 }; - default: return { -1, -1 }; - } -} - -bool victoire(int grille[3][3], int joueur) { - // Vérification des lignes et colonnes - for (int i = 0; i < 3; ++i) { - // Ligne - if (grille[i][0] == joueur && grille[i][1] == joueur && grille[i][2] == joueur) - return true; - // Colonne - if (grille[0][i] == joueur && grille[1][i] == joueur && grille[2][i] == joueur) - return true; - } - // Vérification des deux diagonales - if (grille[0][0] == joueur && grille[1][1] == joueur && grille[2][2] == joueur) - return true; - if (grille[0][2] == joueur && grille[1][1] == joueur && grille[2][0] == joueur) - return true; - - // Aucun alignement trouvé - return false; -} - -bool allInit() { - for(int i = 0; i < 9; i++) { - if (!btns[i]) return false; - } - return true; -} - -void localMode(Adafruit_MPR121& cap, uint16_t& lasttouched, uint16_t& currtouched) { - currtouched = cap.touched(); - - for (int i = 0; i < numKeys; i++) { - uint8_t t = keys[i].touchID; - keys[i].led.setPixelColor(0, 255); // Bleu - keys[i].led.show(); - - if ((currtouched & _BV(t)) && !(lasttouched & _BV(t))) { - Serial.print("Touch "); Serial.print(t); Serial.println(" pressed"); - - Coord c = getCo(i); - if(grille[c.y][c.x] == 0) { - if(joueur1) { - grille[c.y][c.x] = 1; - if(victoire(grille, 1)) { - Serial.println("Joueur 1 a gagne"); - } - } else { - grille[c.y][c.x] = 2; - if(victoire(grille, 2)) { - Serial.println("Joueur 2 a gagne"); - } - } - joueur1 = !joueur1; - } - - for(int i = 0; i < 3; i++) { - for(int j = 0; j < 3; j++) { - Serial.print(grille[i][j]); - } - Serial.println(); - } - } - } - lasttouched = currtouched; -} \ No newline at end of file +#endif // LOCALMODE_H \ No newline at end of file diff --git a/menu.cpp b/menu.cpp new file mode 100644 index 0000000..e8293b8 --- /dev/null +++ b/menu.cpp @@ -0,0 +1,130 @@ +#include "menu.h" +#include + +// Variables de configuration du menu +bool local = true; +bool solo = true; +int difficulty = 1; + +uint8_t btnPrevA; +uint8_t btnPrevB; +uint8_t btnA; +uint8_t btnB; + +bool isMod = false; +bool isModJeu = false; +bool isDifficulty = false; +bool isPlay = false; +bool isWebSet = false; + +Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire); + +unsigned long lastDebounceTimeA = 0; +unsigned long lastDebounceTimeB = 0; +const unsigned long debounceDelay = 200; + +// Assure-toi que epd_bitmap_logo soit déclaré ailleurs ou inclus ici +//extern const unsigned char epd_bitmap_logo[]; + +void setupMenu() { + pinMode(BUTTON_A, INPUT_PULLUP); + pinMode(BUTTON_B, INPUT_PULLUP); + + btnPrevA = digitalRead(BUTTON_A); + btnPrevB = digitalRead(BUTTON_B); + + display.begin(0x3C, true); + display.clearDisplay(); + // display.drawBitmap(0, 0, epd_bitmap_logo, 128, 64, SH110X_WHITE); + display.display(); + delay(1000); + display.clearDisplay(); + display.display(); + + display.setRotation(1); + display.setTextColor(SH110X_WHITE); + display.setCursor(0, 0); + display.display(); +} + +void choixMode() { + display.clearDisplay(); + display.setCursor(0, 0); + display.print("Choisissez le mode :\n"); + display.print("[A] Local\n"); + display.print("[B] Web\n"); + display.display(); +} + +void choixModeJeu() { + display.clearDisplay(); + display.setCursor(0, 0); + display.print("Choisissez le type :\n"); + display.print("[A] Solo\n"); + display.print("[B] Duo\n"); + display.display(); +} + +void choixDifficulty() { + display.clearDisplay(); + display.setCursor(0, 0); + display.print("Choisissez la \ndifficulte :\n"); + display.print("[A] Debutant\n"); + display.print("[B] Expert\n"); + display.display(); +} + +void menu() { + if (!isMod) { + choixMode(); + } else if (local && !isModJeu) { + choixModeJeu(); + } else if (local && solo && !isDifficulty) { + choixDifficulty(); + } else { + isPlay = true; + } +} + +void handleButtonA() { + if (!isMod) { + local = true; + isMod = true; + } else if (!isModJeu) { + solo = true; + isModJeu = true; + } else if (solo && !isDifficulty) { + difficulty = 1; + isDifficulty = true; + isPlay = true; + } +} + +void handleButtonB() { + if (!isMod) { + local = false; + isMod = true; + } else if (!isModJeu) { + solo = false; + isModJeu = true; + } else if (solo && !isDifficulty) { + difficulty = 2; + isDifficulty = true; + isPlay = true; + } +} + +void readButton() { + btnA = digitalRead(BUTTON_A); + if (btnA == LOW && btnPrevA == HIGH && (millis() - lastDebounceTimeA > debounceDelay)) { + lastDebounceTimeA = millis(); + handleButtonA(); + } + btnPrevA = btnA; + btnB = digitalRead(BUTTON_B); + if (btnB == LOW && btnPrevB == HIGH && (millis() - lastDebounceTimeB > debounceDelay)) { + lastDebounceTimeB = millis(); + handleButtonB(); + } + btnPrevB = btnB; +} diff --git a/menu.h b/menu.h index a521aa3..e714438 100644 --- a/menu.h +++ b/menu.h @@ -1,151 +1,43 @@ +#ifndef MENU_H +#define MENU_H + #include #include +// Variables de configuration du menu +extern bool local; +extern bool solo; +extern int difficulty; -bool local = true; -bool solo = true; -int difficulty = 1; +extern uint8_t btnPrevA; +extern uint8_t btnPrevB; +extern uint8_t btnA; +extern uint8_t btnB; -uint8_t btnPrevA; -uint8_t btnPrevB; -uint8_t btnA; -uint8_t btnB; - -bool isMod = false; -bool isModJeu = false; -bool isDifficulty = false; -bool isPlay = false; -bool isWebSet = false; +extern bool isMod; +extern bool isModJeu; +extern bool isDifficulty; +extern bool isPlay; +extern bool isWebSet; #define BUTTON_A 15 #define BUTTON_B 32 -Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire); -unsigned long lastDebounceTimeA = 0; -unsigned long lastDebounceTimeB = 0; -const unsigned long debounceDelay = 200; +extern Adafruit_SH1107 display; -void setupMenu() { - pinMode(BUTTON_A, INPUT_PULLUP); - pinMode(BUTTON_B, INPUT_PULLUP); +extern unsigned long lastDebounceTimeA; +extern unsigned long lastDebounceTimeB; +extern const unsigned long debounceDelay; - btnPrevA = digitalRead(BUTTON_A); - btnPrevB = digitalRead(BUTTON_B); +void setupMenu(); +void choixMode(); +void choixModeJeu(); +void choixDifficulty(); +void menu(); - display.begin(0x3C, true); - display.clearDisplay(); - display.drawBitmap(0, 0, epd_bitmap_logo, 128, 64, SH110X_WHITE); - display.display(); - delay(1000); - display.clearDisplay(); - display.display(); +void handleButtonA(); +void handleButtonB(); +void readButton(); - display.setRotation(1); - display.setTextColor(SH110X_WHITE); - display.setCursor(0, 0); - display.display(); -} - - - - - - - - - - - - -void choixMode() { - display.clearDisplay(); - display.setCursor(0, 0); - display.print("Choisissez le mode :\n"); - display.print("[A] Local\n"); - display.print("[B] Web\n"); - display.display(); -} - -void choixModeJeu() { - display.clearDisplay(); - display.setCursor(0, 0); - display.print("Choisissez le type :\n"); - display.print("[A] Solo\n"); - display.print("[B] Duo\n"); - display.display(); -} - -void choixDifficulty() { - display.clearDisplay(); - display.setCursor(0, 0); - display.print("Choisissez la \ndifficulte :\n"); - display.print("[A] Debutant\n"); - display.print("[B] Expert\n"); - display.display(); -} - - -void menu() { - if (!isMod) { - choixMode(); - } else if (local && !isModJeu) { - choixModeJeu(); - } else if (local && solo && !isDifficulty) { - choixDifficulty(); - } else { - isPlay = true; - } -} - - - - - - - - - -void handleButtonA() { - if (!isMod) { - local = true; - isMod = true; - } else if (!isModJeu) { - solo = true; - isModJeu = true; - } else if (solo && !isDifficulty) { - difficulty = 1; - isDifficulty = true; - isPlay = true; - } -} - -void handleButtonB() { - if (!isMod) { - local = false; - isMod = true; - } else if (!isModJeu) { - solo = false; - isModJeu = true; - } else if (solo && !isDifficulty) { - difficulty = 2; - isDifficulty = true; - isPlay = true; - } -} - - -void readButton(){ - btnA = digitalRead(BUTTON_A); - if (btnA == LOW && btnPrevA == HIGH && (millis() - lastDebounceTimeA > debounceDelay)) { - lastDebounceTimeA = millis(); - handleButtonA(); - } - btnPrevA = btnA; - btnB = digitalRead(BUTTON_B); - if (btnB == LOW && btnPrevB == HIGH && (millis() - lastDebounceTimeB > debounceDelay)) { - lastDebounceTimeB = millis(); - handleButtonB(); - } - btnPrevB = btnB; -} \ No newline at end of file +#endif // MENU_H diff --git a/web.cpp b/web.cpp new file mode 100644 index 0000000..c6dfdb8 --- /dev/null +++ b/web.cpp @@ -0,0 +1,330 @@ +#include "web.h" +#include +#include +#include + +extern Adafruit_SH1107 display; + +// Utilisateurs du réseau +const char *ssid = "morpion-SAE"; +const char *password = "12345678"; +NetworkServer server(80); + +void setupWeb() { + Serial.println(); + Serial.println("Configuring access point..."); + if (!WiFi.softAP(ssid, password)) { + log_e("Soft AP creation failed."); + while (1); + } + IPAddress myIP = WiFi.softAPIP(); + Serial.print("AP IP address: "); + Serial.println(myIP); + server.begin(); + + Serial.println("Server started"); + + display.clearDisplay(); + display.setCursor(0, 0); + display.println("Connectez vous a :"); + display.print("Nom : "); + display.println(ssid); + display.print("Mdp : "); + display.println(password); + display.println(); + display.print("Puis accedez a \nl'adresse "); + display.print(myIP); + display.display(); +} + +void webGame(NetworkClient &c){ + c.println(R"rawliteral( + + + + + + + Morpion Duo/Solo + + + +

Morpion

+ +
Joueur 1 (Bleu) à jouer
+
+
+
+
+
+
+
+
+
+
+
+ + + + +)rawliteral"); +} + +void webSolo(NetworkClient &c) { + c.println(""); + c.println(""); + c.println(""); + c.println(""); + c.println(""); + c.println(""); + c.println("
"); + c.println("Pas encore commence !"); + c.println("
"); + c.println(""); + c.println(""); +} + +void loopWeb() { + NetworkClient client = server.accept(); + if (client) { + Serial.println("New Client."); + String currentLine = ""; + while (client.connected()) { + if (client.available()) { + char c = client.read(); + Serial.write(c); + if (c == '\n') { + if (currentLine.length() == 0) { + client.println("HTTP/1.1 200 OK"); + client.println("Content-type:text/html"); + client.println(); + webGame(client); + client.println(); + break; + } else { + currentLine = ""; + } + } else if (c != '\r') { + currentLine += c; + } + } + } + client.stop(); + Serial.println("Client Disconnected."); + } +} diff --git a/web.h b/web.h index 95bf6c2..8d008d8 100644 --- a/web.h +++ b/web.h @@ -1,344 +1,20 @@ +#ifndef WEBSERVER_H +#define WEBSERVER_H + #include #include #include -const char *ssid = "morpion-SAE"; -const char *password = "12345678"; -NetworkServer server(80); -NetworkClient client = server.accept(); +// SSID & mot de passe du réseau WiFi +extern const char *ssid; +extern const char *password; -void setupWeb(){ - Serial.println(); - Serial.println("Configuring access point..."); - if (!WiFi.softAP(ssid, password)) { - log_e("Soft AP creation failed."); - while (1); - } - IPAddress myIP = WiFi.softAPIP(); - Serial.print("AP IP address: "); - Serial.println(myIP); - server.begin(); +// Serveur et client web +extern NetworkServer server; - Serial.println("Server started"); +void setupWeb(); +void loopWeb(); +void webGame(NetworkClient &c); +void webSolo(NetworkClient &c); - display.clearDisplay(); - display.setCursor(0, 0); - display.println("Connectez vous a :"); - display.print("Nom : "); - display.println(ssid); - display.print("Mdp : "); - display.println(password); - display.println(); - display.print("Puis accedez a \nl'adresse "); - display.print(myIP); - display.display(); -} - - - - - -void webGame(NetworkClient &c){ - c.println(R"rawliteral( - - - - - - - Morpion Duo/Solo - - - -

Morpion

- -
Joueur 1 (Bleu) à jouer
-
-
-
-
-
-
-
-
-
-
-
- - - - -)rawliteral"); -} - - - - -void webSolo(NetworkClient &c){ - c.println(""); - c.println(""); - c.println(""); - c.println(""); - c.println(""); - - c.println(""); - c.println("
"); - c.println("Pas encore commence !"); - c.println("
"); - - c.println(""); - c.println(""); -} - - - - -void loopWeb(){ - NetworkClient client = server.accept(); - if (client) { - Serial.println("New Client."); - String currentLine = ""; - while (client.connected()) { - if (client.available()) { // if there's bytes to read from the client, - char c = client.read(); // read a byte, then - Serial.write(c); - if (c == '\n') { // if the byte is a newline character - // if the current line is blank, you got two newline characters in a row. - // that's the end of the client HTTP request, so send a response: - if (currentLine.length() == 0) { - // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) and a content-type so the client knows what's coming, then a blank line: - client.println("HTTP/1.1 200 OK"); - client.println("Content-type:text/html"); - client.println(); - - // the content of the HTTP response follows the header: - webGame(client); - client.println(); - break; - } else { // if you got a newline, then clear currentLine: - currentLine = ""; - } - } else if (c != '\r') { // if you got anything else but a carriage return character, - currentLine += c; // add it to the end of the currentLine - } - } - } - client.stop(); - Serial.println("Client Disconnected."); - } -} \ No newline at end of file +#endif // WEBSERVER_H