main.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #include "logger.h"
  2. #include <Arduino.h>
  3. #include <WiFi.h>
  4. #include <TinyGPS++.h>
  5. #include <XPowersLib.h>
  6. #include "display.h"
  7. #include "pins.h"
  8. logging::Logger logger;
  9. TinyGPSPlus gps;
  10. HardwareSerial ss(1);
  11. XPowersAXP2101 power;
  12. #define XPOWERS_CHIP_AXP2101
  13. #define PMU_IRQ 35
  14. #define PMU_SDA 21
  15. #define PMU_SCK 22
  16. void setup() {
  17. Serial.begin(115200);
  18. /*
  19. logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "MAIN", "This is a error");
  20. logger.log(logging::LoggerLevel::LOGGER_LEVEL_WARN, "MAIN", "This is a warning");
  21. logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "MAIN", "This is a info");
  22. logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "MAIN", "This is a debug");
  23. */
  24. setup_display();
  25. show_display("PIOTest", "GPS and other stuffs", 3000);
  26. show_display("WiFi", "Scanning around", "Please wait...", 2000);
  27. /* Scan for WiFi networks
  28. * On commence par scanner les réseaux WiFi disponibles
  29. * On attend que le scan soit terminé et on affiche les réseaux trouvés
  30. WiFi.scanNetworks();
  31. int n = WiFi.scanComplete();
  32. if (n == -2) {
  33. WiFi.scanNetworks();
  34. }
  35. while (n == -1) {
  36. delay(100);
  37. n = WiFi.scanComplete();
  38. }
  39. if (n == 0) {
  40. logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "WIFI", "No networks found");
  41. show_display("WiFi", "No networks found", 2000);
  42. } else {
  43. logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "WIFI", "Found %d networks", n);
  44. show_display("WiFi", "Found networks", "Please wait...", 2000);
  45. for (int i = 0; i < n; ++i) {
  46. logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "WIFI", "Network: %s", WiFi.SSID(i).c_str());
  47. show_display("WiFi", WiFi.SSID(i).c_str(), 2000);
  48. }
  49. }
  50. */
  51. /*
  52. * Initialize the PMU
  53. */
  54. bool result = power.begin(Wire, AXP2101_SLAVE_ADDRESS, PMU_SDA, PMU_SCK);
  55. if (result == false) {
  56. logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "PMU", "Failed to initialize PMU");
  57. }
  58. logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "PMU", "PMU initialized");
  59. /* Initialize the GPS
  60. */
  61. logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "GPS", "Initializing GPS");
  62. show_display("GPS", "Initializing GPS", "Please wait...", 2000);
  63. ss.begin(9600, SERIAL_8N1, GPS_TX, GPS_RX);
  64. }
  65. void loop() {
  66. while (ss.available() > 0) {
  67. gps.encode(ss.read());
  68. }
  69. /* Display GPS data
  70. */
  71. logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "GPS", "Latitude: %f, Longitude: %f", "Number of satellites : %d", gps.location.lat(), gps.location.lng(), gps.satellites.value());
  72. show_display("GPS", "Number of satellites: " + String(gps.satellites.value()), "", 2000);
  73. }