Pierre Bourdin hace 3 semanas
padre
commit
b447065062
Se han modificado 10 ficheros con 455 adiciones y 0 borrados
  1. 15 0
      Makefile
  2. 2 0
      compile_commands.json
  3. 39 0
      include/README
  4. 46 0
      lib/README
  5. 42 0
      platformio.ini
  6. 158 0
      src/display.cpp
  7. 15 0
      src/display.h
  8. 95 0
      src/main.cpp
  9. 32 0
      src/pins.h
  10. 11 0
      test/README

+ 15 - 0
Makefile

@@ -0,0 +1,15 @@
+# CREATED BY VIM-PIO
+all:
+	platformio -f -c vim run
+
+upload:
+	platformio -f -c vim run --target upload
+
+clean:
+	platformio -f -c vim run --target clean
+
+program:
+	platformio -f -c vim run --target program
+
+uploadfs:
+	platformio -f -c vim run --target uploadfs

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 2 - 0
compile_commands.json


+ 39 - 0
include/README

@@ -0,0 +1,39 @@
+
+This directory is intended for project header files.
+
+A header file is a file containing C declarations and macro definitions
+to be shared between several project source files. You request the use of a
+header file in your project source file (C, C++, etc) located in `src` folder
+by including it, with the C preprocessing directive `#include'.
+
+```src/main.c
+
+#include "header.h"
+
+int main (void)
+{
+ ...
+}
+```
+
+Including a header file produces the same results as copying the header file
+into each source file that needs it. Such copying would be time-consuming
+and error-prone. With a header file, the related declarations appear
+in only one place. If they need to be changed, they can be changed in one
+place, and programs that include the header file will automatically use the
+new version when next recompiled. The header file eliminates the labor of
+finding and changing all the copies as well as the risk that a failure to
+find one copy will result in inconsistencies within a program.
+
+In C, the usual convention is to give header files names that end with `.h'.
+It is most portable to use only letters, digits, dashes, and underscores in
+header file names, and at most one dot.
+
+Read more about using header files in official GCC documentation:
+
+* Include Syntax
+* Include Operation
+* Once-Only Headers
+* Computed Includes
+
+https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

+ 46 - 0
lib/README

@@ -0,0 +1,46 @@
+
+This directory is intended for project specific (private) libraries.
+PlatformIO will compile them to static libraries and link into executable file.
+
+The source code of each library should be placed in an own separate directory
+("lib/your_library_name/[here are source files]").
+
+For example, see a structure of the following two libraries `Foo` and `Bar`:
+
+|--lib
+|  |
+|  |--Bar
+|  |  |--docs
+|  |  |--examples
+|  |  |--src
+|  |     |- Bar.c
+|  |     |- Bar.h
+|  |  |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
+|  |
+|  |--Foo
+|  |  |- Foo.c
+|  |  |- Foo.h
+|  |
+|  |- README --> THIS FILE
+|
+|- platformio.ini
+|--src
+   |- main.c
+
+and a contents of `src/main.c`:
+```
+#include <Foo.h>
+#include <Bar.h>
+
+int main (void)
+{
+  ...
+}
+
+```
+
+PlatformIO Library Dependency Finder will find automatically dependent
+libraries scanning project source files.
+
+More information about PlatformIO Library Dependency Finder
+- https://docs.platformio.org/page/librarymanager/ldf.html

+ 42 - 0
platformio.ini

@@ -0,0 +1,42 @@
+; PlatformIO Project Configuration File
+;
+;   Build options: build flags, source filter
+;   Upload options: custom upload port, speed and extra flags
+;   Library options: dependencies, extra library storages
+;   Advanced options: extra scripting
+;
+; Please visit documentation for the other options and examples
+; https://docs.platformio.org/page/projectconf.html
+
+[platformio]
+default_envs = ttgo-t-beam-v1
+
+[env]
+platform = espressif32 @ 6.7.0
+framework = arduino
+lib_ldf_mode = deep+
+monitor_speed = 115200
+monitor_filters = esp32_exception_decoder
+lib_deps = 
+	peterus/esp-logger @ 1.0.0
+	adafruit/Adafruit SSD1306
+	adafruit/Adafruit GFX Library
+	mikalhart/TinyGPSPlus
+	lewisxhe/XPowersLib
+
+[env:ttgo-t-beam-AXP2101-v1_2]
+board = ttgo-t-beam
+build_flags = -Werror -Wall -DTTGO_T_Beam_V1_2
+
+[env:ttgo-t-beam-v1]
+board = ttgo-t-beam
+build_flags = -Werror -Wall -DTTGO_T_Beam_V1_0
+
+[env:ttgo-t-beam-v0_7]
+board = ttgo-t-beam
+build_flags = -Werror -Wall -DTTGO_T_Beam_V0_7
+
+[env:uno]
+platform = atmelavr
+board = uno
+framework = arduino

+ 158 - 0
src/display.cpp

@@ -0,0 +1,158 @@
+
+#include <Adafruit_GFX.h>
+#include <Adafruit_SSD1306.h>
+#include <Wire.h>
+#include <logger.h>
+
+#include "display.h"
+#include "pins.h"
+
+extern logging::Logger logger;
+
+Adafruit_SSD1306 display(128, 64, &Wire, OLED_RST);
+
+// cppcheck-suppress unusedFunction
+void setup_display() {
+  pinMode(OLED_RST, OUTPUT);
+  digitalWrite(OLED_RST, LOW);
+  delay(20);
+  digitalWrite(OLED_RST, HIGH);
+
+  Wire.begin(OLED_SDA, OLED_SCL);
+  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) {
+    logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "SSD1306", "allocation failed!");
+    while (true) {
+    }
+  }
+
+  display.clearDisplay();
+  display.setTextColor(WHITE);
+  display.setTextSize(1);
+  display.setCursor(0, 0);
+  display.print("LORA SENDER ");
+  display.ssd1306_command(SSD1306_SETCONTRAST);
+  display.ssd1306_command(1);
+  display.display();
+}
+
+// cppcheck-suppress unusedFunction
+void display_toggle(bool toggle) {
+  if (toggle) {
+    display.ssd1306_command(SSD1306_DISPLAYON);
+  } else {
+    display.ssd1306_command(SSD1306_DISPLAYOFF);
+  }
+}
+
+// cppcheck-suppress unusedFunction
+void show_display(String header, int wait) {
+  display.clearDisplay();
+  display.setTextColor(WHITE);
+  display.setTextSize(2);
+  display.setCursor(0, 0);
+  display.println(header);
+  display.ssd1306_command(SSD1306_SETCONTRAST);
+  display.ssd1306_command(1);
+  display.display();
+  delay(wait);
+}
+
+// cppcheck-suppress unusedFunction
+void show_display(String header, String line1, int wait) {
+  display.clearDisplay();
+  display.setTextColor(WHITE);
+  display.setTextSize(2);
+  display.setCursor(0, 0);
+  display.println(header);
+  display.setTextSize(1);
+  display.setCursor(0, 16);
+  display.println(line1);
+  display.ssd1306_command(SSD1306_SETCONTRAST);
+  display.ssd1306_command(1);
+  display.display();
+  delay(wait);
+}
+
+// cppcheck-suppress unusedFunction
+void show_display(String header, String line1, String line2, int wait) {
+  display.clearDisplay();
+  display.setTextColor(WHITE);
+  display.setTextSize(2);
+  display.setCursor(0, 0);
+  display.println(header);
+  display.setTextSize(1);
+  display.setCursor(0, 16);
+  display.println(line1);
+  display.setCursor(0, 26);
+  display.println(line2);
+  display.ssd1306_command(SSD1306_SETCONTRAST);
+  display.ssd1306_command(1);
+  display.display();
+  delay(wait);
+}
+
+// cppcheck-suppress unusedFunction
+void show_display(String header, String line1, String line2, String line3, int wait) {
+  display.clearDisplay();
+  display.setTextColor(WHITE);
+  display.setTextSize(2);
+  display.setCursor(0, 0);
+  display.println(header);
+  display.setTextSize(1);
+  display.setCursor(0, 16);
+  display.println(line1);
+  display.setCursor(0, 26);
+  display.println(line2);
+  display.setCursor(0, 36);
+  display.println(line3);
+  display.ssd1306_command(SSD1306_SETCONTRAST);
+  display.ssd1306_command(1);
+  display.display();
+  delay(wait);
+}
+
+// cppcheck-suppress unusedFunction
+void show_display(String header, String line1, String line2, String line3, String line4, int wait) {
+  display.clearDisplay();
+  display.setTextColor(WHITE);
+  display.setTextSize(2);
+  display.setCursor(0, 0);
+  display.println(header);
+  display.setTextSize(1);
+  display.setCursor(0, 16);
+  display.println(line1);
+  display.setCursor(0, 26);
+  display.println(line2);
+  display.setCursor(0, 36);
+  display.println(line3);
+  display.setCursor(0, 46);
+  display.println(line4);
+  display.ssd1306_command(SSD1306_SETCONTRAST);
+  display.ssd1306_command(1);
+  display.display();
+  delay(wait);
+}
+
+// cppcheck-suppress unusedFunction
+void show_display(String header, String line1, String line2, String line3, String line4, String line5, int wait) {
+  display.clearDisplay();
+  display.setTextColor(WHITE);
+  display.setTextSize(2);
+  display.setCursor(0, 0);
+  display.println(header);
+  display.setTextSize(1);
+  display.setCursor(0, 16);
+  display.println(line1);
+  display.setCursor(0, 26);
+  display.println(line2);
+  display.setCursor(0, 36);
+  display.println(line3);
+  display.setCursor(0, 46);
+  display.println(line4);
+  display.setCursor(0, 56);
+  display.println(line5);
+  display.ssd1306_command(SSD1306_SETCONTRAST);
+  display.ssd1306_command(1);
+  display.display();
+  delay(wait);
+}

+ 15 - 0
src/display.h

@@ -0,0 +1,15 @@
+
+#ifndef DISPLAY_H_
+#define DISPLAY_H_
+
+void setup_display();
+void display_toggle(bool toggle);
+
+void show_display(String header, int wait = 0);
+void show_display(String header, String line1, int wait = 0);
+void show_display(String header, String line1, String line2, int wait = 0);
+void show_display(String header, String line1, String line2, String line3, int wait = 0);
+void show_display(String header, String line1, String line2, String line3, String line4, int wait = 0);
+void show_display(String header, String line1, String line2, String line3, String line4, String line5, int wait = 0);
+
+#endif

+ 95 - 0
src/main.cpp

@@ -0,0 +1,95 @@
+#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);
+
+
+}

+ 32 - 0
src/pins.h

@@ -0,0 +1,32 @@
+#ifndef PINS_H_
+#define PINS_H_
+
+#undef OLED_SDA
+#undef OLED_SCL
+#undef OLED_RST
+
+#define OLED_SDA 21
+#define OLED_SCL 22
+#define OLED_RST 16
+
+#define BUTTON_PIN 38 // The middle button GPIO on the T-Beam
+
+#ifdef TTGO_T_Beam_V0_7
+#define GPS_RX 15
+#define GPS_TX 12
+#endif
+
+#if defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_2)
+#define GPS_RX 12
+#define GPS_TX 34
+#endif
+
+#define BATTERY_PIN 35
+#define BATTERY_SDA_PIN 21
+#define BATTERY_SCl_PIN 22
+
+
+
+
+
+#endif

+ 11 - 0
test/README

@@ -0,0 +1,11 @@
+
+This directory is intended for PlatformIO Test Runner and project tests.
+
+Unit Testing is a software testing method by which individual units of
+source code, sets of one or more MCU program modules together with associated
+control data, usage procedures, and operating procedures, are tested to
+determine whether they are fit for use. Unit testing finds problems early
+in the development cycle.
+
+More information about PlatformIO Unit Testing:
+- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio