From dbacda44b4a792735987c5a87bc4ddca3febce16 Mon Sep 17 00:00:00 2001
From: Sebastian Krzyszkowiak <dos@dosowisko.net>
Date: Tue, 27 Feb 2024 11:44:10 +0100
Subject: [PATCH] stuff

---
 components/flow3r_bsp/flow3r_bsp_captouch.c |  9 +++++----
 components/flow3r_bsp/flow3r_bsp_i2c.c      |  6 +++---
 components/flow3r_bsp/flow3r_bsp_imu.c      | 18 ++++++++++++++++++
 components/flow3r_bsp/flow3r_bsp_spio.c     |  2 +-
 components/st3m/st3m_captouch.c             |  4 ++--
 5 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/components/flow3r_bsp/flow3r_bsp_captouch.c b/components/flow3r_bsp/flow3r_bsp_captouch.c
index 668bc0d349..85d7200fab 100644
--- a/components/flow3r_bsp/flow3r_bsp_captouch.c
+++ b/components/flow3r_bsp/flow3r_bsp_captouch.c
@@ -281,8 +281,9 @@ static void _task(void *data) {
         if (num % 2 == 0) {
             uint32_t val;
             touch_pad_read_raw_data(touch_pin_map[num / 2], &val);
-            pad->raw = val / 4;
-            if (val >= 0xffff * 4) pad->raw = 0xffff;
+            //printf("pad %d %d val %ld\n", num, touch_pin_map[num / 2], val);
+            pad->raw = val / 5;
+            if (val >= 0xffff * 5) pad->raw = 0xffff;
         }
     }
 
@@ -296,8 +297,8 @@ static void _task(void *data) {
         if (num % 2 == 0) {
             uint32_t val;
             touch_pad_read_raw_data(touch_pin_map[num / 2], &val);
-            pad->raw = val / 4;
-            if (val >= 0xffff * 4) pad->raw = 0xffff;
+            pad->raw = val / 5;
+            if (val >= 0xffff * 5) pad->raw = 0xffff;
         }
     }
 
diff --git a/components/flow3r_bsp/flow3r_bsp_i2c.c b/components/flow3r_bsp/flow3r_bsp_i2c.c
index 6af9a9cf30..fe883d4389 100644
--- a/components/flow3r_bsp/flow3r_bsp_i2c.c
+++ b/components/flow3r_bsp/flow3r_bsp_i2c.c
@@ -38,8 +38,8 @@ const flow3r_i2c_addressdef flow3r_i2c_addresses = {
 
 static i2c_config_t i2c_conf = {
     .mode = I2C_MODE_MASTER,
-    .sda_io_num = 2,
-    .scl_io_num = 1,
+    .sda_io_num = 40,
+    .scl_io_num = 39,
     .sda_pullup_en = GPIO_PULLUP_ENABLE,
     .scl_pullup_en = GPIO_PULLUP_ENABLE,
     .master.clk_speed = 400000,
@@ -93,10 +93,10 @@ esp_err_t flow3r_bsp_i2c_write_read_device(
 }
 
 void flow3r_bsp_i2c_scan(flow3r_bsp_i2c_scan_result_t *res) {
-    return;
     if (res != NULL) {
         memset(res, 0, sizeof(flow3r_bsp_i2c_scan_result_t));
     }
+    return;
     ESP_LOGI(TAG, "Scan: starting...");
     for (uint8_t i = 1; i < 127; i++) {
         i2c_cmd_handle_t cmd = i2c_cmd_link_create();
diff --git a/components/flow3r_bsp/flow3r_bsp_imu.c b/components/flow3r_bsp/flow3r_bsp_imu.c
index 1c8311b12f..aac7306db5 100644
--- a/components/flow3r_bsp/flow3r_bsp_imu.c
+++ b/components/flow3r_bsp/flow3r_bsp_imu.c
@@ -1,6 +1,8 @@
 #include "flow3r_bsp_imu.h"
 #include "flow3r_bsp_i2c.h"
 
+#include "driver/temperature_sensor.h"
+
 #include "bmi270.h"
 #include "bmi2_defs.h"
 
@@ -245,6 +247,7 @@ esp_err_t flow3r_bsp_imu_update(flow3r_bsp_imu_t *imu) {
 
 esp_err_t flow3r_bsp_imu_read_acc(flow3r_bsp_imu_t *imu, int *x, int *y,
                                   int *z) {
+    *x = *y = *z = 0;
     return ESP_OK;
     if (_bmi_sens_data.status & BMI2_DRDY_ACC) {
         *x = _bmi_sens_data.acc.x;
@@ -257,6 +260,7 @@ esp_err_t flow3r_bsp_imu_read_acc(flow3r_bsp_imu_t *imu, int *x, int *y,
 
 esp_err_t flow3r_bsp_imu_read_acc_mps(flow3r_bsp_imu_t *imu, float *x, float *y,
                                       float *z) {
+    *x = *y = *z = 0;
     return ESP_OK;
     int ix, iy, iz;
 
@@ -273,6 +277,7 @@ esp_err_t flow3r_bsp_imu_read_acc_mps(flow3r_bsp_imu_t *imu, float *x, float *y,
 
 esp_err_t flow3r_bsp_imu_read_gyro(flow3r_bsp_imu_t *imu, int *x, int *y,
                                    int *z) {
+    *x = *y = *z = 0;
     return ESP_OK;
     if (_bmi_sens_data.status & BMI2_DRDY_GYR) {
         *x = _bmi_sens_data.gyr.x;
@@ -285,6 +290,7 @@ esp_err_t flow3r_bsp_imu_read_gyro(flow3r_bsp_imu_t *imu, int *x, int *y,
 
 esp_err_t flow3r_bsp_imu_read_gyro_dps(flow3r_bsp_imu_t *imu, float *x,
                                        float *y, float *z) {
+    *x = *y = *z = 0;
     return ESP_OK;
     int ix, iy, iz;
 
@@ -301,7 +307,19 @@ esp_err_t flow3r_bsp_imu_read_gyro_dps(flow3r_bsp_imu_t *imu, float *x,
 
 esp_err_t flow3r_bsp_imu_read_pressure(flow3r_bsp_imu_t *imu, float *pressure,
                                        float *temperature) {
+    *pressure = 0;
+
+    static temperature_sensor_handle_t temp_sensor = NULL;
+    if (temp_sensor == NULL) {
+        temperature_sensor_config_t temp_sensor_config = TEMPERATURE_SENSOR_CONFIG_DEFAULT(-10, 80);
+        ESP_ERROR_CHECK(temperature_sensor_install(&temp_sensor_config, &temp_sensor));
+    }
+    ESP_ERROR_CHECK(temperature_sensor_enable(temp_sensor));
+    ESP_ERROR_CHECK(temperature_sensor_get_celsius(temp_sensor, temperature));
+    ESP_ERROR_CHECK(temperature_sensor_disable(temp_sensor));
+
     return ESP_OK;
+
     int8_t rslt = 0;
     struct bmp5_sensor_data sensor_data;
 
diff --git a/components/flow3r_bsp/flow3r_bsp_spio.c b/components/flow3r_bsp/flow3r_bsp_spio.c
index 7a9f3f4b9e..5f912d98c2 100644
--- a/components/flow3r_bsp/flow3r_bsp_spio.c
+++ b/components/flow3r_bsp/flow3r_bsp_spio.c
@@ -243,7 +243,7 @@ static bool _iopin_touch_get_pin(const flow3r_bsp_iopin_t *iopin) {
     uint32_t val;
     touch_pad_read_raw_data(iopin->pin, &val);
     //ESP_LOGE(TAG, "status %lu pin %lu raw %lu", touch_pad_get_status(), iopin->pin, val);
-    return val >= 50000; //touch_pad_get_status() & (1 << iopin->pin);
+    return val >= 60000; //touch_pad_get_status() & (1 << iopin->pin);
 }
 
 static bool _iopin_get_pin(const flow3r_bsp_iopin_t *iopin) {
diff --git a/components/st3m/st3m_captouch.c b/components/st3m/st3m_captouch.c
index de63631784..15d6d186be 100644
--- a/components/st3m/st3m_captouch.c
+++ b/components/st3m/st3m_captouch.c
@@ -86,11 +86,11 @@ static inline void _petal_process(st3m_petal_state_t *petal, uint8_t index) {
     } else {
         petal->pressure = (petal->base.pressure + petal->tip.pressure) / 2;
         int32_t raw = (petal->base.raw + petal->tip.raw) / 2;
-        if (index == 5) raw *= 2;
+        //if (index == 5) raw *= 2;
         petal->pressed = raw > thres;
         int32_t base = petal->base.raw;
         int32_t tip = petal->tip.raw;
-        if (index == 5) {
+        if (index == 5 && 0) {
             distance =
                 petal->pressed ? (tip * 5) / 4 - 40000 : 0;  // bad hack pt2
         } else {
-- 
GitLab