Skip to content

Commit

Permalink
voltage of RN8209 is working, power and current not yet
Browse files Browse the repository at this point in the history
  • Loading branch information
openshwprojects committed Dec 7, 2023
1 parent 2439c84 commit 73e9abf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/driver/drv_bl_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ void BL09XX_AppendInformationToHTTPIndexPage(http_request_t *request)
mode = "BL0942SPI";
} else if(DRV_IsRunning("CSE7766")) {
mode = "CSE7766";
} else if(DRV_IsRunning("RN8209")) {
mode = "RN8209";
} else {
mode = "PWR";
}
Expand Down
2 changes: 1 addition & 1 deletion src/driver/drv_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static driver_t g_drivers[] = {
//drvdetail:"title":"TODO",
//drvdetail:"descr":"Bqqqqqqqqqq ",
//drvdetail:"requires":""}
{ "RN8209", RN8209_Init, RN8029_RunEverySecond, NULL, NULL, NULL, NULL, false },
{ "RN8209", RN8209_Init, RN8029_RunEverySecond, BL09XX_AppendInformationToHTTPIndexPage, NULL, NULL, NULL, false },
#endif
#if ENABLE_DRIVER_BL0942
//drvdetail:{"name":"BL0942",
Expand Down
15 changes: 15 additions & 0 deletions src/driver/drv_rn8209.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "../new_pins.h"
#include "drv_bl_shared.h"
#include "drv_uart.h"
#include <math.h>
#include "drv_pwrCal.h"

#define RN8209_RMS_CURRENT_A 0x22
#define RN8209_RMS_CURRENT_A_SIZE 3
Expand Down Expand Up @@ -81,15 +83,25 @@ static bool RN8029_ReadReg(byte reg, int *res) {
}
return 0;
}
#define DEFAULT_VOLTAGE_CAL 8810
#define DEFAULT_CURRENT_CAL 57
#define DEFAULT_POWER_CAL 8810
// startDriver RN8209
void RN8209_Init(void) {
UART_InitUART(4800, 1);
UART_InitReceiveRingBuffer(256);

BL_Shared_Init();
PwrCal_Init(PWR_CAL_DIVIDE, DEFAULT_VOLTAGE_CAL, DEFAULT_CURRENT_CAL,
DEFAULT_POWER_CAL);
}
int g_voltage = 0, g_currentA = 0, g_currentB = 0, g_powerA = 0, g_powerB = 0;
int g_meas = 0;
void RN8029_RunEverySecond(void) {
float final_v;
float final_c;
float final_p;

g_meas++;
g_meas %= 5;
switch (g_meas) {
Expand All @@ -112,6 +124,9 @@ void RN8029_RunEverySecond(void) {

ADDLOG_WARN(LOG_FEATURE_ENERGYMETER,
"V %i, C %i %i, P %i %i\n", g_voltage, g_currentA, g_currentB, g_powerA, g_powerB);

PwrCal_Scale(g_voltage, g_currentA, g_powerA, &final_v, &final_c, &final_p);
BL_ProcessUpdate(final_v, final_c, final_p, NAN, NAN);
}
/*
Send: 36 (command code)
Expand Down

0 comments on commit 73e9abf

Please sign in to comment.