1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #include "logger.h"
- #include <Arduino.h>
- #include <WiFi.h>
- #include <TinyGPS++.h>
- #include <XPowersLib.h>
- #include "display.h"
- #include "pins.h"
- logging::Logger logger;
- TinyGPSPlus gps;
- HardwareSerial ss(1);
- XPowersAXP2101 power;
- #define XPOWERS_CHIP_AXP2101
- #define PMU_IRQ 35
- #define PMU_SDA 21
- #define PMU_SCK 22
- void setup() {
- Serial.begin(115200);
- /*
- logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "MAIN", "This is a error");
- logger.log(logging::LoggerLevel::LOGGER_LEVEL_WARN, "MAIN", "This is a warning");
- logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "MAIN", "This is a info");
- logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "MAIN", "This is a debug");
- */
- setup_display();
- show_display("PIOTest", "GPS and other stuffs", 3000);
- show_display("WiFi", "Scanning around", "Please wait...", 2000);
- /* Scan for WiFi networks
- * On commence par scanner les réseaux WiFi disponibles
- * On attend que le scan soit terminé et on affiche les réseaux trouvés
- WiFi.scanNetworks();
- int n = WiFi.scanComplete();
- if (n == -2) {
- WiFi.scanNetworks();
- }
- while (n == -1) {
- delay(100);
- n = WiFi.scanComplete();
- }
- if (n == 0) {
- logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "WIFI", "No networks found");
- show_display("WiFi", "No networks found", 2000);
- } else {
- logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "WIFI", "Found %d networks", n);
- show_display("WiFi", "Found networks", "Please wait...", 2000);
- for (int i = 0; i < n; ++i) {
- logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "WIFI", "Network: %s", WiFi.SSID(i).c_str());
- show_display("WiFi", WiFi.SSID(i).c_str(), 2000);
- }
- }
- */
- /*
- * Initialize the PMU
- */
- bool result = power.begin(Wire, AXP2101_SLAVE_ADDRESS, PMU_SDA, PMU_SCK);
- if (result == false) {
- logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "PMU", "Failed to initialize PMU");
- }
- logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "PMU", "PMU initialized");
- /* Initialize the GPS
- */
- logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "GPS", "Initializing GPS");
- show_display("GPS", "Initializing GPS", "Please wait...", 2000);
- ss.begin(9600, SERIAL_8N1, GPS_TX, GPS_RX);
- }
- void loop() {
- while (ss.available() > 0) {
- gps.encode(ss.read());
- }
-
- /* Display GPS data
- */
- 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());
- show_display("GPS", "Number of satellites: " + String(gps.satellites.value()), "", 2000);
- }
|