Ready for test
This commit is contained in:
@@ -31,11 +31,11 @@
|
||||
// #define srvAddr "192.168.1.190:3000"
|
||||
#define srvAddr "wahwa.com"
|
||||
|
||||
#define ENCODER_PIN_A GPIO_NUM_23 // d5
|
||||
#define ENCODER_PIN_A GPIO_NUM_21 // d3
|
||||
#define ENCODER_PIN_B GPIO_NUM_16 // d6
|
||||
|
||||
#define InputEnc_PIN_A GPIO_NUM_1 // d1
|
||||
#define InputEnc_PIN_B GPIO_NUM_2 // d2
|
||||
#define InputEnc_PIN_A GPIO_NUM_0 // d0
|
||||
#define InputEnc_PIN_B GPIO_NUM_1 // d1
|
||||
|
||||
#define servoPin GPIO_NUM_20
|
||||
#define servoLEDCChannel LEDC_CHANNEL_0
|
||||
|
||||
@@ -1,21 +1,34 @@
|
||||
#ifndef BM_EVENTS_H
|
||||
#define BM_EVENTS_H
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
// Event Types
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Shared with max17048.c (C) — only C-compatible types here
|
||||
typedef enum {
|
||||
EVENT_CLEAR_CALIB,
|
||||
EVENT_SAVE_POS,
|
||||
EVENT_REQUEST_POS
|
||||
EVENT_CLEAR_CALIB,
|
||||
EVENT_SAVE_POS,
|
||||
EVENT_REQUEST_POS,
|
||||
EVENT_BATTERY_CRITICAL, // stop servo, save pos, alert server, deep sleep
|
||||
EVENT_BATTERY_WARNING, // alert server (no shutdown)
|
||||
EVENT_REPORT_SOC, // periodic SOC sync to server
|
||||
} main_event_type_t;
|
||||
|
||||
void mainEventLoop();
|
||||
|
||||
extern QueueHandle_t main_event_queue;
|
||||
extern TaskHandle_t wakeTaskHandle;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
void mainEventLoop();
|
||||
void wakeTimer(void* pvParameters);
|
||||
#endif
|
||||
|
||||
extern TaskHandle_t wakeTaskHandle;
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -1,38 +1,68 @@
|
||||
#ifndef MAX_17_H
|
||||
#define MAX_17_H
|
||||
|
||||
#define MAX17048_ADDR 0x36
|
||||
#define MAX17048_REG_VCELL 0x02 // Voltage
|
||||
#define MAX17048_REG_SOC 0x04 // State of Charge (%)
|
||||
#define MAX17048_REG_MODE 0x06
|
||||
#define MAX17048_REG_VERSION 0x08
|
||||
#define MAX17048_REG_CONFIG 0x0C
|
||||
#define MAX17048_REG_CMD 0xFE // Command (Reset)
|
||||
#define MAX17048_REG_STATUS 0x1A
|
||||
#define MAX17048_REG_VALRT 0x14
|
||||
#define MAX17048_REG_VRST_ID 0x18
|
||||
#define MAX17048_ADDR 0x36
|
||||
#define MAX17048_REG_VCELL 0x02
|
||||
#define MAX17048_REG_SOC 0x04
|
||||
#define MAX17048_REG_MODE 0x06
|
||||
#define MAX17048_REG_VERSION 0x08
|
||||
#define MAX17048_REG_CONFIG 0x0C
|
||||
#define MAX17048_REG_VALRT 0x14
|
||||
#define MAX17048_REG_VRST_ID 0x18
|
||||
#define MAX17048_REG_STATUS 0x1A
|
||||
#define MAX17048_REG_CMD 0xFE
|
||||
|
||||
// Commands
|
||||
#define MAX17048_CMD_POR 0x5400 // Power On Reset command
|
||||
#define MAX17048_CMD_QSTRT 0x4000 // Quick Start command
|
||||
#define MAX17048_CMD_POR 0x5400
|
||||
#define MAX17048_CMD_QSTRT 0x4000
|
||||
|
||||
// NOTE: maxALRT (GPIO_NUM_2) conflicts with InputEnc_PIN_B in defines.h.
|
||||
// Assign maxALRT to a free GPIO before enabling the interrupt.
|
||||
#define maxALRT GPIO_NUM_2
|
||||
|
||||
// STATUS register MSB (addr 0x1A) bit masks
|
||||
// [7:X] [6:EnVR] [5:SC] [4:HD] [3:VR] [2:VL] [1:VH] [0:RI]
|
||||
#define SCbit (1 << 5) // SOC changed by 1%
|
||||
#define HDbit (1 << 4) // SOC crossed low threshold (CONFIG.ATHD)
|
||||
#define VRbit (1 << 3) // voltage reset alert
|
||||
#define VLbit (1 << 2) // VCELL below VALRT.MIN
|
||||
#define VHbit (1 << 1) // VCELL above VALRT.MAX
|
||||
#define RIbit (1 << 0) // reset indicator (device just powered on)
|
||||
|
||||
// SOC thresholds for user-facing push notifications / shutdown logic
|
||||
#define SOC_WARN_20 20 // emit warning push at this level
|
||||
#define SOC_WARN_10 10 // emit critical push at this level
|
||||
#define SOC_CRITICAL_VL 5 // treat undervoltage as critical only below this SOC
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "driver/i2c.h"
|
||||
|
||||
// Alert type carried from bms_checker_task to mainEventLoop via bms_pending_alert
|
||||
typedef enum {
|
||||
BATT_ALERT_OVERVOLTAGE, // VH: charging fault / damaged battery
|
||||
BATT_ALERT_CRITICAL_LOW, // HD, or VL + SOC < SOC_CRITICAL_VL
|
||||
BATT_ALERT_LOW_VOLTAGE_WARNING, // VL with SOC >= SOC_CRITICAL_VL (transient dip)
|
||||
BATT_ALERT_SOC_LOW_20, // SOC just crossed 20% downward
|
||||
BATT_ALERT_SOC_LOW_10, // SOC just crossed 10% downward
|
||||
} batt_alert_type_t;
|
||||
|
||||
extern uint8_t established_soc;
|
||||
extern volatile batt_alert_type_t bms_pending_alert;
|
||||
|
||||
esp_err_t max17048_init();
|
||||
uint8_t bms_get_soc();
|
||||
uint8_t bms_get_soc();
|
||||
esp_err_t bms_set_alert_bound_voltages(float min, float max);
|
||||
esp_err_t bms_set_reset_voltage(float vreset);
|
||||
esp_err_t bms_clear_status();
|
||||
void bms_checker_task(void *pvParameters);
|
||||
|
||||
#define bms_set_alsc() max17048_friendly_write_reg(MAX17048_REG_CONFIG, 0, 1<<6, 0, 1<<6)
|
||||
#define bms_set_alsc() max17048_friendly_write_reg(MAX17048_REG_CONFIG, 0, 1<<6, 0, 1<<6)
|
||||
#define bms_clear_status() max17048_write_reg(MAX17048_REG_STATUS, 0, 0)
|
||||
#define bms_clear_alrt() max17048_friendly_write_reg(MAX17048_REG_CONFIG, 0, 0, 0, 1<<5)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user