Explorar el Código

Clean up files that are not needed for new proj.

Thomas Chef hace 3 años
padre
commit
11fbed1547
Se han modificado 19 ficheros con 111 adiciones y 1083 borrados
  1. 6 4
      main/CMakeLists.txt
  2. 5 18
      main/config.h
  3. 0 141
      main/displayAndSend.c
  4. 0 105
      main/fonts.c
  5. 0 21
      main/fonts.h
  6. 0 44
      main/led_test_inout.c
  7. 3 14
      main/main.c
  8. 0 141
      main/pcnt_functions.c
  9. 0 9
      main/pcnt_functions.h
  10. 94 0
      main/send.c
  11. 3 3
      main/displayAndSend.h
  12. 0 120
      main/serial.c
  13. 0 21
      main/serial.h
  14. 0 184
      main/ssd1306.c
  15. 0 90
      main/ssd1306.h
  16. 0 50
      main/ssd1306_driver.c
  17. 0 26
      main/ssd1306_driver.h
  18. 0 79
      main/uart.c
  19. 0 13
      main/uart.h

+ 6 - 4
main/CMakeLists.txt

@@ -1,7 +1,9 @@
-idf_component_register(SRCS "ssd1306_driver.c" "fonts.c" "ssd1306.c"
+idf_component_register(SRCS
 "http_client.c" "mqtt.c" "wifi.c"
-"main.c" "led_test_inout.c"
-"pcnt_functions.c" "wifi.c" "mqtt.c" "uart.c" "serial.c"
-"displayAndSend.c"
+"main.c"
+"wifi.c" "mqtt.c"
+"send.c"
+
+
 
                     INCLUDE_DIRS "")

+ 5 - 18
main/config.h

@@ -8,24 +8,11 @@
 #define PULSES_PER_KWH      1000
 
 // These defines configures which code to generate (to save download time during development)
-#define CCFG_GEN_PULSE      // For testing purposes only (LED-Pulse 14Hz)
-#define CCFG_PCNT           // pcnt-code that counts pulses
-#define WIFI_ENABLED
-#define MQTT_ENABLED
-#define SERIAL_ENABLED
-#define ENABLE_SSD1306
-
-// Pulse
-#define PCNT_INPUT_SIG_IO   GPIO_NUM_23  // Pulse Input GPIO
-#define LEDC_OUTPUT_IO      GPIO_NUM_22   // Output GPIO of a sample 1 Hz pulse generator
-
-// I2C OLED Disp
-#define I2C_SDA_PIN         GPIO_NUM_5
-#define I2C_CLK_PIN         GPIO_NUM_4
-
-// UART
-#define UART_TX_PIN         GPIO_NUM_17
-#define UART_RX_PIN         GPIO_NUM_16
+//#define WIFI_ENABLED
+//#define MQTT_ENABLED
+//#define ENABLE_SEND
+
+
 
 
 #endif

+ 0 - 141
main/displayAndSend.c

@@ -1,141 +0,0 @@
-#include "displayAndSend.h"
-#include "ssd1306.h"
-#include "ssd1306_driver.h"
-#include "mqtt.h"
-#include "esp_log.h"
-#include <stdio.h>
-#include <string.h>
-#include "freertos/FreeRTOS.h"
-#include "freertos/task.h"
-#include "freertos/queue.h"
-
-#ifdef ENABLE_SSD1306
-
-#define QUEUE_SIZE 3
-
-static QueueHandle_t dataQueue = NULL;
-static bool queueReady = false;
-
-void displayAndSendTask(void *pvParameters) {
-
-    uint8_t aliveCnt = 0;
-    DisplayData data;
-    char txt[50];
-
-    ESP_LOGI("DISPnSND", "displayAndSendTask starting. Core:%d",xPortGetCoreID());
-
-    i2c_master_init();
-    oled_ssd1306_init();
-
-    vTaskDelay(100 / portTICK_PERIOD_MS);
-    SSD1306_SetPosition(4,18);
-    SSD1306_DrawVertLine(29,0,128);
-    SSD1306_Puts("Home Energy Meter", &Font_7x10,SSD1306_COLOR_WHITE);
-    SSD1306_SetPosition(4,31);
-    SSD1306_Puts(SW_VERSION, &Font_7x10,SSD1306_COLOR_WHITE);
-    SSD1306_UpdateScreen();
-    vTaskDelay(3000 / portTICK_PERIOD_MS);
-
-    SSD1306_Clear();
-    SSD1306_SetPosition(0,0);
-    SSD1306_Puts("Internal:", &Font_7x10,SSD1306_COLOR_WHITE);
-    SSD1306_SetPosition(0,11);
-    SSD1306_Puts("Heater:", &Font_7x10,SSD1306_COLOR_WHITE);
-    SSD1306_SetPosition(0,22);
-    SSD1306_Puts("ADC Vpp:", &Font_7x10,SSD1306_COLOR_WHITE);
-    SSD1306_SetPosition(0,33);
-    SSD1306_Puts("kWh:", &Font_7x10,SSD1306_COLOR_WHITE);
-    SSD1306_UpdateScreen();
-    
-    SSD1306_SetPosition(0,50);
-    sprintf(txt,"HoEnMeter %s",SW_VERSION);
-    SSD1306_Puts(txt, &Font_7x10,SSD1306_COLOR_WHITE);
-
-    // Create the data input queue, now that all is setup
-    dataQueue = xQueueCreate( QUEUE_SIZE, sizeof( DisplayData ) );
-    if(dataQueue == NULL) {
-        ESP_LOGE("DISPnSND","Error creating the queue");
-    }
-    ESP_LOGI("DISPnSND", "Data input queue ready.");
-    queueReady = true;
-
-    while( 1 ) {
-
-        if( xQueueReceive(dataQueue,&data, 1000 / portTICK_PERIOD_MS) == pdTRUE ) {
-
-            switch( data.type ) {
-                case type_VPP: sprintf(txt,"   %d",data.iData);
-                          SSD1306_SetPosition(127-(strlen(txt)*8),22);
-                          SSD1306_Puts(txt, &Font_7x10,SSD1306_COLOR_WHITE);
-                          SSD1306_UpdateScreen();
-                          sprintf(txt,"%d",data.iData);
-                          sendMQTTMessage("homeEnergyMeter/waterHeater/totalEnergy", txt);
-                          aliveCnt++;
-                          break;
-                case type_TempA:
-                          sprintf(txt,"   %.1f\044C",data.dData);
-                          SSD1306_SetPosition(127-(strlen(txt)*8),0);
-                          SSD1306_Puts(txt, &Font_7x10,SSD1306_COLOR_WHITE);
-                          SSD1306_UpdateScreen();
-                          sprintf(txt,"%.2f",data.dData);
-                          sendMQTTMessage("homeEnergyMeter/internal/temp", txt);
-                          break;
-                case type_TempB:
-                          sprintf(txt,"   %.1f\044C",data.dData);
-                          SSD1306_SetPosition(127-(strlen(txt)*8),11);
-                          SSD1306_Puts(txt, &Font_7x10,SSD1306_COLOR_WHITE);
-                          SSD1306_UpdateScreen();
-                          sprintf(txt,"%.2f",data.dData);
-                          sendMQTTMessage("homeEnergyMeter/waterHeater/temp", txt);
-                          break;
-                case type_kWh:
-                          sprintf(txt,"   %.2f",data.dData);
-                          SSD1306_SetPosition(127-(strlen(txt)*8),33);
-                          SSD1306_Puts(txt, &Font_7x10,SSD1306_COLOR_WHITE);
-                          SSD1306_UpdateScreen();
-                          sprintf(txt,"%.5f",data.dData);
-                          sendMQTTMessage("homeEnergyMeter/electricityMeter/kWh", txt);
-                          sprintf(txt,"%d",data.iData);
-                          sendMQTTMessage("homeEnergyMeter/electricityMeter/pulses", txt);
-                          break;
-                default:
-                          break;
-            }
-        }
-        else {
-            sprintf(txt,"%u",aliveCnt);
-            if( aliveCnt == 10 ) aliveCnt=0;
-            SSD1306_SetPosition(127-(strlen(txt)*8),50);
-            SSD1306_Puts(txt, &Font_7x10,SSD1306_COLOR_WHITE);
-            SSD1306_UpdateScreen();
-        }
-    }
-
-    vTaskDelete(NULL);
-}
-
-void addDataToQueue(int data_type, double dData_in, int iData_in) {
-
-    DisplayData d;
-
-    d.type = data_type;
-    d.dData = dData_in;
-    d.iData = iData_in;
-
-    if( queueReady == true && dataQueue != NULL  ) {
-        if( xQueueSend(dataQueue, &d, 0) != pdPASS ) {
-            ESP_LOGE("DISPnSND","Queue full");
-        }
-    }
-    else {
-        ESP_LOGE("DISPnSND","Queue not ready.");
-    }
-}
-
-
-void initDisplayAndSend() {
-
-    xTaskCreate(displayAndSendTask, "MQTT-Task", 1024*10, NULL, 2, NULL);
-}
-
-#endif

+ 0 - 105
main/fonts.c

@@ -1,105 +0,0 @@
-#include "fonts.h"
-
-const uint16_t Font_data_7x10 [] = {
-0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,  // sp
-0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x1000, 0x0000, 0x0000,  // !
-0x2800, 0x2800, 0x2800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,  // "
-0x2400, 0x2400, 0x7C00, 0x2400, 0x4800, 0x7C00, 0x4800, 0x4800, 0x0000, 0x0000,  // #
-0x0C00, 0x1200, 0x1200, 0x0C00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,  // Deg C
-0x2000, 0x5400, 0x5800, 0x3000, 0x2800, 0x5400, 0x1400, 0x0800, 0x0000, 0x0000,  // %
-0x1000, 0x2800, 0x2800, 0x1000, 0x3400, 0x4800, 0x4800, 0x3400, 0x0000, 0x0000,  // &
-0x1000, 0x1000, 0x1000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,  // '
-0x0800, 0x1000, 0x2000, 0x2000, 0x2000, 0x2000, 0x2000, 0x2000, 0x1000, 0x0800,  // (
-0x2000, 0x1000, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x1000, 0x2000,  // )
-0x1000, 0x3800, 0x1000, 0x2800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,  // *
-0x0000, 0x0000, 0x1000, 0x1000, 0x7C00, 0x1000, 0x1000, 0x0000, 0x0000, 0x0000,  // +
-0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1000, 0x1000, 0x1000,  // ,
-0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3800, 0x0000, 0x0000, 0x0000, 0x0000,  // -
-0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1000, 0x0000, 0x0000,  // .
-0x0800, 0x0800, 0x1000, 0x1000, 0x1000, 0x1000, 0x2000, 0x2000, 0x0000, 0x0000,  // /
-0x3800, 0x4400, 0x4400, 0x5400, 0x4400, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000,  // 0
-0x1000, 0x3000, 0x5000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000,  // 1
-0x3800, 0x4400, 0x4400, 0x0400, 0x0800, 0x1000, 0x2000, 0x7C00, 0x0000, 0x0000,  // 2
-0x3800, 0x4400, 0x0400, 0x1800, 0x0400, 0x0400, 0x4400, 0x3800, 0x0000, 0x0000,  // 3
-0x0800, 0x1800, 0x2800, 0x2800, 0x4800, 0x7C00, 0x0800, 0x0800, 0x0000, 0x0000,  // 4
-0x7C00, 0x4000, 0x4000, 0x7800, 0x0400, 0x0400, 0x4400, 0x3800, 0x0000, 0x0000,  // 5
-0x3800, 0x4400, 0x4000, 0x7800, 0x4400, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000,  // 6
-0x7C00, 0x0400, 0x0800, 0x1000, 0x1000, 0x2000, 0x2000, 0x2000, 0x0000, 0x0000,  // 7
-0x3800, 0x4400, 0x4400, 0x3800, 0x4400, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000,  // 8
-0x3800, 0x4400, 0x4400, 0x4400, 0x3C00, 0x0400, 0x4400, 0x3800, 0x0000, 0x0000,  // 9
-0x0000, 0x0000, 0x1000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1000, 0x0000, 0x0000,  // :
-0x0000, 0x0000, 0x0000, 0x1000, 0x0000, 0x0000, 0x0000, 0x1000, 0x1000, 0x1000,  // ;
-0x0000, 0x0000, 0x0C00, 0x3000, 0x4000, 0x3000, 0x0C00, 0x0000, 0x0000, 0x0000,  // <
-0x0000, 0x0000, 0x0000, 0x7C00, 0x0000, 0x7C00, 0x0000, 0x0000, 0x0000, 0x0000,  // =
-0x0000, 0x0000, 0x6000, 0x1800, 0x0400, 0x1800, 0x6000, 0x0000, 0x0000, 0x0000,  // >
-0x3800, 0x4400, 0x0400, 0x0800, 0x1000, 0x1000, 0x0000, 0x1000, 0x0000, 0x0000,  // ?
-0x3800, 0x4400, 0x4C00, 0x5400, 0x5C00, 0x4000, 0x4000, 0x3800, 0x0000, 0x0000,  // @
-0x1000, 0x2800, 0x2800, 0x2800, 0x2800, 0x7C00, 0x4400, 0x4400, 0x0000, 0x0000,  // A
-0x7800, 0x4400, 0x4400, 0x7800, 0x4400, 0x4400, 0x4400, 0x7800, 0x0000, 0x0000,  // B
-0x3800, 0x4400, 0x4000, 0x4000, 0x4000, 0x4000, 0x4400, 0x3800, 0x0000, 0x0000,  // C
-0x7000, 0x4800, 0x4400, 0x4400, 0x4400, 0x4400, 0x4800, 0x7000, 0x0000, 0x0000,  // D
-0x7C00, 0x4000, 0x4000, 0x7C00, 0x4000, 0x4000, 0x4000, 0x7C00, 0x0000, 0x0000,  // E
-0x7C00, 0x4000, 0x4000, 0x7800, 0x4000, 0x4000, 0x4000, 0x4000, 0x0000, 0x0000,  // F
-0x3800, 0x4400, 0x4000, 0x4000, 0x5C00, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000,  // G
-0x4400, 0x4400, 0x4400, 0x7C00, 0x4400, 0x4400, 0x4400, 0x4400, 0x0000, 0x0000,  // H
-0x3800, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x3800, 0x0000, 0x0000,  // I
-0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x4400, 0x3800, 0x0000, 0x0000,  // J
-0x4400, 0x4800, 0x5000, 0x6000, 0x5000, 0x4800, 0x4800, 0x4400, 0x0000, 0x0000,  // K
-0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x7C00, 0x0000, 0x0000,  // L
-0x4400, 0x6C00, 0x6C00, 0x5400, 0x4400, 0x4400, 0x4400, 0x4400, 0x0000, 0x0000,  // M
-0x4400, 0x6400, 0x6400, 0x5400, 0x5400, 0x4C00, 0x4C00, 0x4400, 0x0000, 0x0000,  // N
-0x3800, 0x4400, 0x4400, 0x4400, 0x4400, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000,  // O
-0x7800, 0x4400, 0x4400, 0x4400, 0x7800, 0x4000, 0x4000, 0x4000, 0x0000, 0x0000,  // P
-0x3800, 0x4400, 0x4400, 0x4400, 0x4400, 0x4400, 0x5400, 0x3800, 0x0400, 0x0000,  // Q
-0x7800, 0x4400, 0x4400, 0x4400, 0x7800, 0x4800, 0x4800, 0x4400, 0x0000, 0x0000,  // R
-0x3800, 0x4400, 0x4000, 0x3000, 0x0800, 0x0400, 0x4400, 0x3800, 0x0000, 0x0000,  // S
-0x7C00, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000,  // T
-0x4400, 0x4400, 0x4400, 0x4400, 0x4400, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000,  // U
-0x4400, 0x4400, 0x4400, 0x2800, 0x2800, 0x2800, 0x1000, 0x1000, 0x0000, 0x0000,  // V
-0x4400, 0x4400, 0x5400, 0x5400, 0x5400, 0x6C00, 0x2800, 0x2800, 0x0000, 0x0000,  // W
-0x4400, 0x2800, 0x2800, 0x1000, 0x1000, 0x2800, 0x2800, 0x4400, 0x0000, 0x0000,  // X
-0x4400, 0x4400, 0x2800, 0x2800, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000,  // Y
-0x7C00, 0x0400, 0x0800, 0x1000, 0x1000, 0x2000, 0x4000, 0x7C00, 0x0000, 0x0000,  // Z
-0x1800, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1800,  // [
-0x2000, 0x2000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0800, 0x0800, 0x0000, 0x0000,  /* \ */
-0x3000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x3000,  // ]
-0x1000, 0x2800, 0x2800, 0x4400, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,  // ^
-0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFE00,  // _
-0x2000, 0x1000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,  // `
-0x0000, 0x0000, 0x3800, 0x4400, 0x3C00, 0x4400, 0x4C00, 0x3400, 0x0000, 0x0000,  // a
-0x4000, 0x4000, 0x5800, 0x6400, 0x4400, 0x4400, 0x6400, 0x5800, 0x0000, 0x0000,  // b
-0x0000, 0x0000, 0x3800, 0x4400, 0x4000, 0x4000, 0x4400, 0x3800, 0x0000, 0x0000,  // c
-0x0400, 0x0400, 0x3400, 0x4C00, 0x4400, 0x4400, 0x4C00, 0x3400, 0x0000, 0x0000,  // d
-0x0000, 0x0000, 0x3800, 0x4400, 0x7C00, 0x4000, 0x4400, 0x3800, 0x0000, 0x0000,  // e
-0x0C00, 0x1000, 0x7C00, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000,  // f
-0x0000, 0x0000, 0x3400, 0x4C00, 0x4400, 0x4400, 0x4C00, 0x3400, 0x0400, 0x7800,  // g
-0x4000, 0x4000, 0x5800, 0x6400, 0x4400, 0x4400, 0x4400, 0x4400, 0x0000, 0x0000,  // h
-0x1000, 0x0000, 0x7000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000,  // i
-0x1000, 0x0000, 0x7000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0xE000,  // j
-0x4000, 0x4000, 0x4800, 0x5000, 0x6000, 0x5000, 0x4800, 0x4400, 0x0000, 0x0000,  // k
-0x7000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000,  // l
-0x0000, 0x0000, 0x7800, 0x5400, 0x5400, 0x5400, 0x5400, 0x5400, 0x0000, 0x0000,  // m
-0x0000, 0x0000, 0x5800, 0x6400, 0x4400, 0x4400, 0x4400, 0x4400, 0x0000, 0x0000,  // n
-0x0000, 0x0000, 0x3800, 0x4400, 0x4400, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000,  // o
-0x0000, 0x0000, 0x5800, 0x6400, 0x4400, 0x4400, 0x6400, 0x5800, 0x4000, 0x4000,  // p
-0x0000, 0x0000, 0x3400, 0x4C00, 0x4400, 0x4400, 0x4C00, 0x3400, 0x0400, 0x0400,  // q
-0x0000, 0x0000, 0x5800, 0x6400, 0x4000, 0x4000, 0x4000, 0x4000, 0x0000, 0x0000,  // r
-0x0000, 0x0000, 0x3800, 0x4400, 0x3000, 0x0800, 0x4400, 0x3800, 0x0000, 0x0000,  // s
-0x2000, 0x2000, 0x7800, 0x2000, 0x2000, 0x2000, 0x2000, 0x1800, 0x0000, 0x0000,  // t
-0x0000, 0x0000, 0x4400, 0x4400, 0x4400, 0x4400, 0x4C00, 0x3400, 0x0000, 0x0000,  // u
-0x0000, 0x0000, 0x4400, 0x4400, 0x2800, 0x2800, 0x2800, 0x1000, 0x0000, 0x0000,  // v
-0x0000, 0x0000, 0x5400, 0x5400, 0x5400, 0x6C00, 0x2800, 0x2800, 0x0000, 0x0000,  // w
-0x0000, 0x0000, 0x4400, 0x2800, 0x1000, 0x1000, 0x2800, 0x4400, 0x0000, 0x0000,  // x
-0x0000, 0x0000, 0x4400, 0x4400, 0x2800, 0x2800, 0x1000, 0x1000, 0x1000, 0x6000,  // y
-0x0000, 0x0000, 0x7C00, 0x0800, 0x1000, 0x2000, 0x4000, 0x7C00, 0x0000, 0x0000,  // z
-0x1800, 0x1000, 0x1000, 0x1000, 0x2000, 0x2000, 0x1000, 0x1000, 0x1000, 0x1800,  // {
-0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000,  // |
-0x3000, 0x1000, 0x1000, 0x1000, 0x0800, 0x0800, 0x1000, 0x1000, 0x1000, 0x3000,  // }
-0x0000, 0x0000, 0x0000, 0x7400, 0x4C00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,  // ~
-};
-
-FontDef_t Font_7x10 = {
-	7,
-	10,
-	Font_data_7x10
-};

+ 0 - 21
main/fonts.h

@@ -1,21 +0,0 @@
-#ifndef __FONTS_H__
-#define __FONTS_H__
-
-#include "stdint.h"
-
-
-typedef struct {
-	uint8_t FontWidth;    /*!< Font width in pixels */
-	uint8_t FontHeight;   /*!< Font height in pixels */
-	const uint16_t *data; /*!< Pointer to data font data array */
-} FontDef_t;
-
-typedef struct {
-	uint16_t Length;      /*!< String length in units of pixels */
-	uint16_t Height;      /*!< String height in units of pixels */
-} FONTS_SIZE_t;
-
-FontDef_t Font_7x10;
-
-
-#endif

+ 0 - 44
main/led_test_inout.c

@@ -1,44 +0,0 @@
-#include "freertos/FreeRTOS.h"
-#include "freertos/task.h"
-#include "freertos/queue.h"
-#include "driver/ledc.h"
-#include "driver/pcnt.h"
-#include "esp_attr.h"
-#include "esp_log.h"
-
-#include "config.h"
-
-#ifdef CCFG_GEN_PULSE
-
-/* Configure LED PWM Controller
- * to output sample pulses at 1 Hz with duty of about 10%
- */
-void ledc_init(void)
-{
-    // Prepare and then apply the LEDC PWM timer configuration
-    ledc_timer_config_t ledc_timer;
-    ledc_timer.speed_mode       = LEDC_LOW_SPEED_MODE;
-    ledc_timer.timer_num        = LEDC_TIMER_0;
-    ledc_timer.duty_resolution  = LEDC_TIMER_13_BIT;
-    ledc_timer.freq_hz          = 100;   // Should be 2 for some kind of max kWh
-    ledc_timer.clk_cfg          = LEDC_AUTO_CLK;
-    ledc_timer_config(&ledc_timer);
-
-    // Prepare and then apply the LEDC PWM channel configuration
-    ledc_channel_config_t ledc_channel;
-    ledc_channel.speed_mode = LEDC_LOW_SPEED_MODE;
-    ledc_channel.channel    = LEDC_CHANNEL_0;
-    ledc_channel.timer_sel  = LEDC_TIMER_0;
-    ledc_channel.intr_type  = LEDC_INTR_DISABLE;
-    ledc_channel.gpio_num   = LEDC_OUTPUT_IO;
-    ledc_channel.duty       = 0; // set duty at about 10%
-    ledc_channel.hpoint     = 0;
-    ledc_channel_config(&ledc_channel);
-
-    // Set duty to 5%
-    ESP_ERROR_CHECK(ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 409)); // Set duty to 5%. ((2 ** 13) - 1) * 50% = 409
-    // Update duty to apply the new value
-    ESP_ERROR_CHECK(ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0));
-}
-
-#endif

+ 3 - 14
main/main.c

@@ -3,9 +3,7 @@
 #include "esp_log.h"
 #include "config.h"
 #include "wifi.h"
-#include "serial.h"
-#include "displayAndSend.h"
-#include "pcnt_functions.h"
+#include "send.h"
 #include "mqtt.h"
 
 
@@ -26,20 +24,11 @@ void app_main(void)
     mqtt_init();
 #endif
 
-#ifdef CCFG_PCNT
-    initPCNT();
-#endif
-
-#ifdef CCFG_GEN_PULSE
-    ledc_init();
-#endif
 
-#ifdef SERIAL_ENABLED
-    initSerial();
+#ifdef ENABLE_SEND
+    initSend();
 #endif
 
-    initDisplayAndSend();
-
     vTaskDelete(NULL);
 }
 

+ 0 - 141
main/pcnt_functions.c

@@ -1,141 +0,0 @@
-#include "freertos/FreeRTOS.h"
-#include "freertos/task.h"
-#include "freertos/queue.h"
-#include "driver/ledc.h"
-#include "driver/pcnt.h"
-#include "esp_attr.h"
-#include "esp_log.h"
-#include "config.h"
-#include "pcnt_functions.h"
-#include "displayAndSend.h"
-
-#include "soc/dport_reg.h"
-
-#ifdef CCFG_PCNT
-
-/** Electric meter:
- * 10000 impulses per kWh
- * Some normal max number could be 120 kWh/24h = 5 kWh/hour = 50000 pulses/hour = 833 pulses/min = 14 pulses/sec
- * 
- * Counter is 16 bit signed = Max 32768 pulses = Will NOT work for one hour !!!!!
- * So we need some other way of counting higher numbers that will last for one h
- * Probably we need to use interrupts !
- */
-
-
-// Example-code: https://github.com/espressif/esp-idf/blob/master/examples/peripherals/pcnt/pulse_count_event/main/pcnt_event_example_main.c
-
-typedef struct {
-    double kWh;
-    uint32_t pulses32K;
-    uint32_t pulses;
-} pulseData_t;
-
-// Counts interrupts that occus every 32K Pulses
-// The counter register is 16 bit signed so we count to 32K before doing an interrupt
-// This equals to 32kWH consumed energy (at 1000 pulses per kWh)
-static uint32_t Counter_32K_Pulses = 0;
-
-static const int pcntUnit = PCNT_UNIT_0;
-
-static void pCntMonitorTask(void *pvParameters);
-
-static pulseData_t getkWh() {
-
-    pulseData_t pd = {0.0,0,0};
-
-    pcnt_intr_disable(pcntUnit);
-    volatile int32_t count = DPORT_REG_READ(0x3FF57060);
-    volatile uint32_t bigCounter = Counter_32K_Pulses;
-    pcnt_intr_enable(pcntUnit);
-
-    pd.kWh = ((double)bigCounter*32)+((double)count / PULSES_PER_KWH);
-    pd.pulses32K = bigCounter;
-    pd.pulses = (uint32_t)count;
-
-    return pd;
-}
-
-static void IRAM_ATTR pcnt_example_intr_handler(void *arg)
-{
-    Counter_32K_Pulses++;
-}
-
-
-
-void init_pcnt_unit()
-{
-    /* Prepare configuration for the PCNT unit */
-    pcnt_config_t pcnt_config = {
-        // Set PCNT input signal and control GPIOs
-        .pulse_gpio_num = PCNT_INPUT_SIG_IO,
-        .ctrl_gpio_num = PCNT_PIN_NOT_USED,
-        .channel = PCNT_CHANNEL_0,
-        .unit = pcntUnit,
-        // What to do on the positive / negative edge of pulse input?
-        .pos_mode = PCNT_COUNT_INC,   // Count up on the positive edge
-        .neg_mode = PCNT_COUNT_DIS,   // Keep the counter value on the negative edge
-        // What to do when control input is low or high?
-        .lctrl_mode = PCNT_MODE_REVERSE, // Reverse counting direction if low
-        .hctrl_mode = PCNT_MODE_KEEP,    // Keep the primary counter mode if high
-        // Set the maximum and minimum limit values to watch
-        .counter_h_lim = 32000,
-        .counter_l_lim = 0,
-    };
-    /* Initialize PCNT unit */
-    pcnt_unit_config(&pcnt_config);
-
-    // How to read a periphial-register:
-    //uint32_t c = p_pcnt_obj->hal.dev.hw.conf_unit[unit];
-    //printf("Reg: %08x\n",(uint32_t)DPORT_REG_READ(0x3FF57000));
-
-    //The length of ignored pulses is provided in APB_CLK clock cycles by calling pcnt_set_filter_value().
-    //The current filter setting may be checked with pcnt_get_filter_value().
-    //The APB_CLK clock is running at 80 MHz.
-
-    /* Configure and enable the input filter */
-    pcnt_set_filter_value(pcntUnit, 1023); // APB_CLK=80MHz * 1023 is filtered out = 0,0127875mS (????)
-    pcnt_filter_enable(pcntUnit);
-
-    /* Enable int on high count limit */
-    pcnt_event_enable(pcntUnit, PCNT_EVT_H_LIM);
-
-    /* Initialize PCNT's counter */
-    pcnt_counter_pause(pcntUnit);
-    pcnt_counter_clear(pcntUnit);
-
-    /* Install interrupt service and add isr callback handler */
-    pcnt_isr_service_install(0);
-    pcnt_isr_handler_add(pcntUnit, pcnt_example_intr_handler, (void *)pcntUnit);
-
-    /* Everything is set up, now go to counting */
-    pcnt_counter_resume(pcntUnit);
-}
-
-static void pCntMonitorTask(void *pvParameters) {
-
-    ESP_LOGI("PCNT", "pCntMonitorTask starting. Core:%d",xPortGetCoreID());
-
-    vTaskDelay(5000 / portTICK_PERIOD_MS); // Wait for display to get started
-
-    while( 1 ) {
-
-        pulseData_t pd = getkWh();
-
-        addDataToQueue(type_kWh, pd.kWh, pd.pulses );
-        vTaskDelay(60000 / portTICK_PERIOD_MS);
-    }
-
-}
-
-void initPCNT() {
-
-    ESP_LOGI("PCNT", "initPCNT");
-
-    init_pcnt_unit();
-
-    xTaskCreate(pCntMonitorTask, "pCntMonitorTask", 1024*10, NULL, 2, NULL);
-}
-
-
-#endif

+ 0 - 9
main/pcnt_functions.h

@@ -1,9 +0,0 @@
-#ifndef __PCNT_H__
-#define __PCNT_H__
-
-
-void ledc_init(void); // In led_test_input module
-void initPCNT();
-
-
-#endif

+ 94 - 0
main/send.c

@@ -0,0 +1,94 @@
+#include "send.h"
+#include "mqtt.h"
+#include "esp_log.h"
+#include <stdio.h>
+#include <string.h>
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+#include "freertos/queue.h"
+#include "config.h"
+
+#ifdef ENABLE_SEND
+
+#define QUEUE_SIZE 3
+
+static QueueHandle_t dataQueue = NULL;
+static bool queueReady = false;
+
+void sendTask(void *pvParameters) {
+
+    uint8_t aliveCnt = 0;
+    DisplayData data;
+    char txt[50];
+
+    ESP_LOGI("DISPnSND", "SendTask starting. Core:%d",xPortGetCoreID());
+
+
+
+    // Create the data input queue, now that all is setup
+    dataQueue = xQueueCreate( QUEUE_SIZE, sizeof( DisplayData ) );
+    if(dataQueue == NULL) {
+        ESP_LOGE("DISPnSND","Error creating the queue");
+    }
+    ESP_LOGI("DISPnSND", "Data input queue ready.");
+    queueReady = true;
+
+    while( 1 ) {
+
+        if( xQueueReceive(dataQueue,&data, 1000 / portTICK_PERIOD_MS) == pdTRUE ) {
+
+            switch( data.type ) {
+                case type_VPP: sprintf(txt,"   %d",data.iData);
+                          sprintf(txt,"%d",data.iData);
+                          sendMQTTMessage("homeEnergyMeter/waterHeater/totalEnergy", txt);
+                          aliveCnt++;
+                          break;
+                case type_TempA:
+                          sprintf(txt,"%.2f",data.dData);
+                          sendMQTTMessage("homeEnergyMeter/internal/temp", txt);
+                          break;
+                case type_TempB:
+                          sprintf(txt,"%.2f",data.dData);
+                          sendMQTTMessage("homeEnergyMeter/waterHeater/temp", txt);
+                          break;
+                case type_kWh:
+                          sprintf(txt,"%.5f",data.dData);
+                          sendMQTTMessage("homeEnergyMeter/electricityMeter/kWh", txt);
+                          sprintf(txt,"%d",data.iData);
+                          sendMQTTMessage("homeEnergyMeter/electricityMeter/pulses", txt);
+                          break;
+                default:
+                          break;
+            }
+        }
+
+    }
+
+    vTaskDelete(NULL);
+}
+
+void addDataToQueue(int data_type, double dData_in, int iData_in) {
+
+    DisplayData d;
+
+    d.type = data_type;
+    d.dData = dData_in;
+    d.iData = iData_in;
+
+    if( queueReady == true && dataQueue != NULL  ) {
+        if( xQueueSend(dataQueue, &d, 0) != pdPASS ) {
+            ESP_LOGE("DISPnSND","Queue full");
+        }
+    }
+    else {
+        ESP_LOGE("DISPnSND","Queue not ready.");
+    }
+}
+
+void initSend() {
+    xTaskCreate(sendTask, "Send-Task", 1024*10, NULL, 2, NULL);
+}
+
+
+#endif
+

+ 3 - 3
main/displayAndSend.h

@@ -1,5 +1,5 @@
-#ifndef __DISPANDSEND_H__
-#define __DISPANDSEND_H__
+#ifndef __SEND_H__
+#define __SEND_H__
 
 
 
@@ -19,7 +19,7 @@ typedef struct{
 } DisplayData;
 
 
-void initDisplayAndSend();
+void initSend();
 void addDataToQueue(int data_type, double dData_in, int iData_in);
 
 

+ 0 - 120
main/serial.c

@@ -1,120 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include "freertos/FreeRTOS.h"
-#include "freertos/task.h"
-#include "freertos/queue.h"
-#include "freertos/task.h"
-#include "esp_log.h"
-#include "serial.h"
-#include "uart.h"
-#include "config.h"
-#include "displayAndSend.h"
-//#include "supervision.h"
-
-//#include "http_client.h"
-#include "wifi.h"
-
-#ifdef SERIAL_ENABLED
-
-// Global defines
-int serialRxCounter = 0;
-
-void serialRxTask(void *pvParameters)
-{
-    const bool LOG_PRINT=false;
-
-	int mode = -1;			// Force a reset
-	int reset = 1;
-
-	unsigned char value[200];
-	unsigned char *valP;
-
-	ESP_LOGI("SERIAL", "serialRxTask starting. Core:%d",xPortGetCoreID());
-
-    while(1)
-    {
-		while( serialAvailable() ) {
-    
- 			const unsigned char c = serialRead();
-
- 			//printf("%c",c);
-
-			if( mode == 0 && c == '{' ) {
-				if(LOG_PRINT)  printf("Rx start ");
-				mode = 1;
-			}
-			else if( mode == 1 ) {
-				
-				if( c == '}' ) {	// Check for end of value
-					*(valP) = '\0';
-					reset = 1;
-                    if(LOG_PRINT) printf("\nData:%s\n",value);
-                    char type[10];
-                    char id[21];
-                    char data[10];
-                    const int no = sscanf((const char *)value,"%9[^,],%20[^,],%9s",type,id,data);
-                    if(LOG_PRINT) printf("No:%d\n",no);
-                    if( no == 3 ) {
-						if(LOG_PRINT) printf("-%s-    -%s-    -%s-\n",type,id,data);
-						if( strcmp(type,"VPP") == 0 ) {
-							int vpp = 0;
-							const int no = sscanf(data,"%d",&vpp);
-							if( no == 1 ) {
-								ESP_LOGI("SERIAL", "VPP: %d   %.4fmV",vpp,vpp*(3300.0f / 4095.0f));
-								addDataToQueue(type_VPP,0.0,vpp);
-							}
-						}
-						else if( strcmp(type,"OWT") == 0 ) {
-							float t = 0.0f;
-							const int no = sscanf(data,"%f",&t);
-							
-							if( no == 1 ) {
-								if( strcmp(id,"28412E7B0D00002A") == 0 ) {
-									addDataToQueue(type_TempA,t,0);
-								}
-								else if( strcmp(id,"28FF22DA551603C3") == 0 ) {
-									addDataToQueue(type_TempB,t,0);
-								}
-								else {
-									ESP_LOGE("SERIAL","Unknown OW-ID:%s",id);
-								}
-								//char js[50];
-								//sprintf(js,"{\"id\":\"%s\",\"temp\":%s}",id,data);
-								//ESP_LOGI("SERIAL", "%s",js);
-							}
-						}
-					}
-					else {
-						ESP_LOGE("SERIAL", "ERROR 2");
-					}
-				}
-				else if( c < ',' || c > 'Z') {
-					ESP_LOGE("SERIAL", "ERROR 3");
-					reset = 1;
-				}
-				else {
-					*(valP++) = c;
-				}
-			}
-
-			if( reset == 1 ) {
-				serialRxCounter++;
-				valP = value;
-				value[0]='\0';
-				mode = 0;	
-				reset = 0;
-			}
-		}
-		vTaskDelay(100 / portTICK_PERIOD_MS);
-    }
-
-	vTaskDelete(NULL);
-}
-
-void initSerial() {
-
-	initUart();
-	xTaskCreate(serialRxTask, "Serial_RX_Task", 10000, NULL, 10, NULL);
-}
-
-#endif

+ 0 - 21
main/serial.h

@@ -1,21 +0,0 @@
-#ifndef __SERIAL__
-#define __SERIAL__
-
-extern int serialRxCounter;
-
-typedef struct {
-	char *dataStr;
-	int balanceDiff;
-	int balance;
-	int errorMode;
-	float temperature;
-    bool periodicUpdate;
-	int rssi;
-	int wifiChannel;
-} sensor_data;
-
-void initSerial();
-void serialRxTask(void *pvParameters);
-
-
-#endif

+ 0 - 184
main/ssd1306.c

@@ -1,184 +0,0 @@
-#include "ssd1306.h"
-#include "ssd1306_driver.h"
-#include "esp_log.h"
-#include "stdlib.h"
-#include "string.h"
-#include "config.h"
-#include "fonts.h"
-
-#ifdef ENABLE_SSD1306
-
-static uint8_t SSD1306_Buffer[SSD1306_WIDTH * SSD1306_HEIGHT / 8];
-
-typedef struct {
-	uint16_t CurrentX;
-	uint16_t CurrentY;
-	uint8_t Inverted;
-	uint8_t Initialized;
-} SSD1306_t;
-
-/* Private variable */
-static SSD1306_t SSD1306;
-
-void SSD1306_SetPosition(const int x, const int y) {
-    SSD1306.CurrentX = x;
-    SSD1306.CurrentY = y;
-}
-
-void SSD1306_Clear() {
-    memset(SSD1306_Buffer,0,SSD1306_WIDTH * SSD1306_HEIGHT / 8);
-}
-
-void SSD1306_DrawPixel(uint16_t x, uint16_t y, SSD1306_COLOR_t color) {
-	if (
-		x >= SSD1306_WIDTH ||
-		y >= SSD1306_HEIGHT
-	) {
-		return;
-	}
-	if (color == SSD1306_COLOR_WHITE) {
-		SSD1306_Buffer[x + (y / 8) * SSD1306_WIDTH] |= 1 << (y % 8);
-	} else {
-		SSD1306_Buffer[x + (y / 8) * SSD1306_WIDTH] &= ~(1 << (y % 8));
-	}
-}
-
-char SSD1306_Putc(char ch, const FontDef_t* Font, SSD1306_COLOR_t color) {
-	uint32_t i, b, j;
-	
-	/* Check available space in LCD */
-	if (
-		SSD1306_WIDTH <= (SSD1306.CurrentX + Font->FontWidth) ||
-		SSD1306_HEIGHT <= (SSD1306.CurrentY + Font->FontHeight)
-	) {
-		/* Error */
-		return 0;
-	}
-	
-	/* Go through font */
-	for (i = 0; i < Font->FontHeight; i++) {
-		b = Font->data[(ch - 32) * Font->FontHeight + i];
-		for (j = 0; j < Font->FontWidth; j++) {
-			if ((b << j) & 0x8000) {
-				SSD1306_DrawPixel(SSD1306.CurrentX + j, (SSD1306.CurrentY + i), (SSD1306_COLOR_t) color);
-			} else {
-				SSD1306_DrawPixel(SSD1306.CurrentX + j, (SSD1306.CurrentY + i), (SSD1306_COLOR_t)!color);
-			}
-		}
-	}
-	
-	/* Increase pointer */
-	SSD1306.CurrentX += Font->FontWidth;
-	
-	/* Return character written */
-	return ch;
-}
-
-char SSD1306_Puts(char* str, FontDef_t* Font, SSD1306_COLOR_t color) {
-	/* Write characters */
-	while (*str) {
-		/* Write character by character */
-		if (SSD1306_Putc(*str, Font, color) != *str) {
-			/* Return error */
-			return *str;
-		}
-		
-		/* Increase string pointer */
-		str++;
-	}
-	
-	/* Everything OK, zero should be returned */
-	return *str;
-}
-
-void SSD1306_DrawVertLine(const uint8_t y, const uint8_t x1, const uint8_t x2) {
-    for(uint8_t x=x1; x<x2; x++) SSD1306_DrawPixel(x,y,SSD1306_COLOR_WHITE);
-}
-
-void SSD1306_UpdateScreen(void) {
-	uint8_t m;
-	
-	for (m = 0; m < 8; m++) {
-        uint8_t configMsg[] = {
-            PAGE_START_ADDR+m,        // set page range:
-            0x00,                      //   y / 8
-            0x10,                      //   y / 8
-        };
-        i2c_tx_cmd(configMsg, sizeof configMsg);
-        i2c_tx_data(&SSD1306_Buffer[SSD1306_WIDTH * m], SSD1306_WIDTH);
-	}
-}
-
-
-esp_err_t oled_ssd1306_init() {
-
-    i2c_cmd_handle_t cmd = i2c_cmd_link_create();
-    i2c_master_start(cmd);
-
-    i2c_master_write_byte(cmd, (SSD1306_OLED_ADDR << 1) | WRITE_BIT, ACK_CHECK_EN);
-
-    // Initialization (page 64)
-    // The next bytes are commands
-    i2c_master_write_byte(cmd, COMMAND_MODE, ACK_CHECK_EN);
-
-    // Mux Ratio
-    i2c_master_write_byte(cmd, MULTIPLEX_RATIO, ACK_CHECK_EN);
-    i2c_master_write_byte(cmd, 0x3F, ACK_CHECK_EN);
-
-    // Set display offset
-    i2c_master_write_byte(cmd, DISPLAY_OFFSET, ACK_CHECK_EN);
-    i2c_master_write_byte(cmd, 0x00, ACK_CHECK_EN);
-
-    // Set display line start
-    i2c_master_write_byte(cmd, DISPLAY_LINE_START, ACK_CHECK_EN);
-    i2c_master_write_byte(cmd, 0x00, ACK_CHECK_EN);
-
-    // Set Segment re-map
-    i2c_master_write_byte(cmd, SEGMENT_REMAP, ACK_CHECK_EN);
-
-    // Set COM output scan dir
-    i2c_master_write_byte(cmd, COM_OUTPUT_SCAN_DIR, ACK_CHECK_EN);
-    i2c_master_write_byte(cmd, 0x00, ACK_CHECK_EN);
-
-    // Set COM pins hardware config
-    i2c_master_write_byte(cmd, COM_PINS_HARDWARE_CONFIG, ACK_CHECK_EN);
-    i2c_master_write_byte(cmd, 0x12, ACK_CHECK_EN);
-
-    // Set contrast Control
-    i2c_master_write_byte(cmd, CONTRAST_CONTROL, ACK_CHECK_EN);
-    i2c_master_write_byte(cmd, 0x7F, ACK_CHECK_EN);
-
-    i2c_master_write_byte(cmd, DEACTIVATE_SCROLL, ACK_CHECK_EN);
-
-    // Disable entire display ON
-    i2c_master_write_byte(cmd, DISABLE_ENTIRE_DISPLAY, ACK_CHECK_EN);
-
-    // Set normal display
-    i2c_master_write_byte(cmd, NORMAL_DISPLAY, ACK_CHECK_EN);
-
-    // Set OSC frequency
-    i2c_master_write_byte(cmd, DISPLAY_CLK_RATIO, ACK_CHECK_EN);
-    i2c_master_write_byte(cmd, 0x80, ACK_CHECK_EN);
-
-    // Enable charge pump regulator
-    i2c_master_write_byte(cmd, CHARGE_PUMP_SET, ACK_CHECK_EN);
-    i2c_master_write_byte(cmd, 0x14, ACK_CHECK_EN);
-
-    // Display on
-    i2c_master_write_byte(cmd, DISPLAY_ON, ACK_CHECK_EN);
-
-    // Stop bit
-    i2c_master_stop(cmd);
-
-    esp_err_t ret = i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 1000 / portTICK_RATE_MS);
-    i2c_cmd_link_delete(cmd);
-
-    SSD1306.CurrentX = 0;
-	SSD1306.CurrentY = 0;
-	
-	SSD1306.Initialized = 1;
-
-    return ret;
-}
-
-#endif

+ 0 - 90
main/ssd1306.h

@@ -1,90 +0,0 @@
-#ifndef __SSD1306_H__
-#define __SSD1306_H__
-
-#include <driver/spi_master.h>
-#include "fonts.h"
-
-
-#define READ_BIT   I2C_MASTER_READ              /*!< I2C master read */
-
-#define ACK_CHECK_DIS  0x0                      /*!< I2C master will not check ack from slave */
-#define ACK_VAL    0x0                          /*!< I2C ack value */
-#define NACK_VAL   0x1                          /*!< I2C nack value */
-
-// Fundamental Command (page 28)
-#define DISPLAY_LINE_START 0x40
-#define CONTRAST_CONTROL 0x81
-#define DISABLE_ENTIRE_DISPLAY 0xA4
-#define DISPLAY_ON_REG02 0xA5
-#define NORMAL_DISPLAY 0xA6
-#define DISPLAY_INVERSE  0xA7
-#define DISPLAY_RESET 0xAE
-#define DISPLAY_ON 0xAF
-
-// Addressing Setting (page 30)
-#define MEM_ADDR_MODE 0x20
-#define LOWER_COL_START_ADDR 0x00
-#define HIGHER_COL_START_ADDR 0x10
-#define PAGE_START_ADDR 0xB0
-
-// Hardware Config (page 31)
-#define DISPLAY_START_LINE 0x40
-#define SEGMENT_REMAP 0xA0
-#define SEGMENT_REMAP_FLIP 0xA1
-#define MULTIPLEX_RATIO 0xA8
-#define COM_OUTPUT_SCAN_DIR 0xC0
-#define DISPLAY_OFFSET 0xD3
-#define COM_PINS_HARDWARE_CONFIG 0xDA
-
-// Timing & Driving Scheme (page 32)
-#define DISPLAY_CLK_RATIO 0xD5
-#define PRE_CHARGE_PER 0xD9
-#define VCOMH_DESELECT_LEVEL 0xDB
-#define NOOPERATION 0xE3
-
-// Charge Pump (page 60)
-#define CHARGE_PUMP_SET 0x8D
-
-// Scrolling
-#define DEACTIVATE_SCROLL 0x2E
-#define ACTIVATE_SCROLL 0x2F
-#define VERTICAL_AND_RIGHT_HOR_SCROLL 0x29
-#define DUMMY_BYTE 0x00
-#define SIX_FRAMES_PER_SEC 0x00
-#define VERTICAL_OFFSET_ONE 0x01
-
-typedef enum {
-	SSD1306_COLOR_BLACK = 0x00, /*!< Black color, no pixel */
-	SSD1306_COLOR_WHITE = 0x01  /*!< Pixel is set. Color depends on LCD */
-} SSD1306_COLOR_t;
-
-
-
-#define SSD1306_WIDTH            128
-#define SSD1306_HEIGHT           64
-
-
-esp_err_t oled_ssd1306_init();
-void SSD1306_Clear();
-void SSD1306_DrawVertLine(const uint8_t y, const uint8_t x1, const uint8_t x2);
-char SSD1306_Putc(char ch, const FontDef_t* Font, SSD1306_COLOR_t color);
-char SSD1306_Puts(char* str, FontDef_t* Font, SSD1306_COLOR_t color);
-void SSD1306_SetPosition(const int x, const int y);
-void SSD1306_UpdateScreen(void);
-
-
-/**
- * @brief  Calculates string length and height in units of pixels depending on string and font used
- * @param  *str: String to be checked for length and height
- * @param  *SizeStruct: Pointer to empty @ref FONTS_SIZE_t structure where informations will be saved
- * @param  *Font: Pointer to @ref FontDef_t font used for calculations
- * @retval Pointer to string used for length and height
- */
-char* FONTS_GetStringSize(char* str, FONTS_SIZE_t* SizeStruct, FontDef_t* Font);
-
-
-
-
-
-
-#endif

+ 0 - 50
main/ssd1306_driver.c

@@ -1,50 +0,0 @@
-#include "ssd1306_driver.h"
-
-#include "driver/i2c.h"
-
-#ifdef ENABLE_SSD1306
-
-esp_err_t i2c_tx_cmd(uint8_t *data, const uint8_t length) {
-    i2c_cmd_handle_t handle = i2c_cmd_link_create();
-    i2c_master_start(handle);
-    i2c_master_write_byte(handle, (SSD1306_OLED_ADDR << 1) | WRITE_BIT, ACK_CHECK_EN);
-    i2c_master_write_byte(handle, COMMAND_MODE, ACK_CHECK_EN);
-    i2c_master_write(handle, data, length, ACK_CHECK_EN);
-    i2c_master_stop(handle);
-    esp_err_t retVal = i2c_master_cmd_begin(I2C_MASTER_NUM, handle, 1000 / portTICK_RATE_MS);
-    i2c_cmd_link_delete(handle);
-    return retVal;
-}
-
-esp_err_t i2c_tx_data(uint8_t *data, const uint8_t length) {
-    i2c_cmd_handle_t handle = i2c_cmd_link_create();
-    i2c_master_start(handle);
-    i2c_master_write_byte(handle, (SSD1306_OLED_ADDR << 1) | WRITE_BIT, ACK_CHECK_EN);
-    i2c_master_write_byte(handle, DATA_MODE, ACK_CHECK_EN);
-    i2c_master_write(handle, data, length, ACK_CHECK_EN);
-    i2c_master_stop(handle);
-    esp_err_t retVal = i2c_master_cmd_begin(I2C_MASTER_NUM, handle, 1000 / portTICK_RATE_MS);
-    i2c_cmd_link_delete(handle);
-    return retVal;
-}
-
-void i2c_master_init() {
-
-    int i2c_master_port = I2C_MASTER_NUM;
-    i2c_config_t conf;
-
-    conf.mode = I2C_MODE_MASTER;
-    conf.sda_io_num = I2C_SDA_PIN;               // Data pin
-    conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
-    conf.scl_io_num = I2C_CLK_PIN;               // Clock pin
-    conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
-    conf.master.clk_speed = 100000;
-    i2c_param_config(i2c_master_port, &conf);
-    i2c_driver_install(i2c_master_port,
-                        conf.mode,
-                        I2C_MASTER_RX_BUF_DISABLE,
-                        I2C_MASTER_TX_BUF_DISABLE,
-                        0);
-}
-
-#endif

+ 0 - 26
main/ssd1306_driver.h

@@ -1,26 +0,0 @@
-#ifndef __SSD1306_DRIVER_H__
-#define __SSD1306_DRIVER_H__
-
-#include "driver/i2c.h"
-#include "config.h"
-
-#define SSD1306_OLED_ADDR  0x3C                 /*!< slave address for ssd1306 oled display */
-#define WRITE_BIT  I2C_MASTER_WRITE             /*!< I2C master write */
-#define ACK_CHECK_EN   0x1                      /*!< I2C master will check ack from slave*/
-#define COMMAND_MODE 0x00
-#define SINGLE_COMMAND_MODE 0x80
-#define DATA_MODE 0x40
-#define I2C_MASTER_NUM    I2C_NUM_1             /*!< I2C port number for master dev */
-#define I2C_MASTER_TX_BUF_DISABLE   0           /*!< I2C master do not need buffer */
-#define I2C_MASTER_RX_BUF_DISABLE   0           /*!< I2C master do not need buffer */
-
-
-void i2c_master_init();
-
-esp_err_t i2c_tx_cmd(uint8_t *data, const uint8_t length);
-esp_err_t i2c_tx_data(uint8_t *data, const uint8_t length);
-
-
-
-
-#endif

+ 0 - 79
main/uart.c

@@ -1,79 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include "freertos/FreeRTOS.h"
-#include "freertos/task.h"
-#include "freertos/queue.h"
-#include "driver/uart.h"
-#include "esp_log.h"
-#include "config.h"
-
-#include "uart.h"
-
-#ifdef SERIAL_ENABLED
-
-/************************************************************************************************
- * On the ESP-WROOM-32 Card, the UART2-Pins are avaialable.
- * TXD: GPIO17
- * RXD: GPIO16
- * https://www.espressif.com/sites/default/files/documentation/esp32-wroom-32_datasheet_en.pdf
- * http://esp32.net/images/MH-ET-LIVE/ESP32-DevKit/MH-ET-LIVE_ESP32-DevKit_DiagramPinout.png
- * https://i.imgur.com/ctokhuk.jpg (Schematic of the MH-ET-LIVE)
- * 
- ************************************************************************************************/
-#define UART_NUMBER UART_NUM_2
-
-void initUart() {
-    
-    uart_config_t uart_config = {
-        .baud_rate = 19200,
-        .data_bits = UART_DATA_8_BITS,
-        .parity = UART_PARITY_DISABLE,
-        .stop_bits = UART_STOP_BITS_1,
-        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
-    };
-    ESP_ERROR_CHECK(uart_param_config(UART_NUMBER, &uart_config));
-
-    ESP_ERROR_CHECK(uart_set_pin(UART_NUMBER, UART_TX_PIN, UART_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
-
-    const int uart_buffer_size = (1024 * 2);
-    QueueHandle_t uart_queue;
-    ESP_ERROR_CHECK(uart_driver_install(UART_NUMBER, uart_buffer_size, uart_buffer_size, 10, &uart_queue, 0));
-
-
-}
-
-
-
-unsigned char serialRead(void) {
-    unsigned char data;
-    const int length = uart_read_bytes(UART_NUMBER, (uint8_t*)&data, 1, 0);
-    if( length > 0 )
-        return data;
-    else
-        return '\0';
-}
-
-int serialAvailable() {
-    size_t size;
-    uart_get_buffered_data_len(UART_NUMBER, &size);
-    return (size == 0)? 0 : 1;
-}
-
-void writeUARTData(const char *str) {
-    uart_tx_chars(UART_NUMBER, (const char*)str, strlen(str));
-}
-
-void readData() {
-    uint8_t data[2048];
-    int length = 0;
-    printf("readData()a\n");
-    ESP_ERROR_CHECK(uart_get_buffered_data_len(UART_NUMBER, (size_t*)&length));
-    printf("readData()b  %d\n",length);
-    length = uart_read_bytes(UART_NUMBER, data, length, 100);
-    printf("readData()c  %d\n",length);
-    data[length] = '\0';
-
-    printf("Read:%d :%s\n",length,(char *)data);
-}
-
-#endif

+ 0 - 13
main/uart.h

@@ -1,13 +0,0 @@
-#ifndef __UART_H__
-#define __UART_H__
-
-void initUart();
-
-void writeUARTData(const char *str);
-void readData();
-
-int serialAvailable();
-
-unsigned char serialRead(void);
-
-#endif