|
@@ -38,6 +38,7 @@ typedef enum _mode_led {
|
|
|
displayP,
|
|
|
displayCI,
|
|
|
displayCP,
|
|
|
+ displaySh,
|
|
|
displayT
|
|
|
} mode_led_t;
|
|
|
|
|
@@ -76,6 +77,7 @@ const static button_t Button[BUTTON_NUM] = {
|
|
|
|
|
|
/* Private variables ---------------------------------------------------------*/
|
|
|
static uint16_t Voltage;
|
|
|
+static int16_t ShuntV;
|
|
|
static uint16_t Current;
|
|
|
static uint32_t Power;
|
|
|
static uint32_t CapacityAH = 0;
|
|
@@ -100,6 +102,7 @@ static void showI(uint8_t pos);
|
|
|
static void showP(uint8_t pos);
|
|
|
static void showCI(uint8_t pos);
|
|
|
static void showCP(uint8_t pos);
|
|
|
+static void showSH(uint8_t pos);
|
|
|
static void showT(uint8_t pos);
|
|
|
|
|
|
static void showLabelU(uint8_t pos);
|
|
@@ -107,6 +110,7 @@ static void showLabelI(uint8_t pos);
|
|
|
static void showLabelP(uint8_t pos);
|
|
|
static void showLabelAH(uint8_t pos);
|
|
|
static void showLabelWH(uint8_t pos);
|
|
|
+static void showLabelSH(uint8_t pos);
|
|
|
static void showLabelT(uint8_t pos);
|
|
|
|
|
|
static void displayMode(mode_led_t * disp, event_t event, uint8_t pos);
|
|
@@ -115,17 +119,20 @@ static void blankLine(uint8_t pos);
|
|
|
|
|
|
/* RTOS function prototypes -----------------------------------------------*/
|
|
|
static void readINAValues(void);
|
|
|
+static void calculateValues(void);
|
|
|
static void showTopLineU(void);
|
|
|
static void showTopLineI(void);
|
|
|
static void showTopLineP(void);
|
|
|
static void showTopLineAH(void);
|
|
|
static void showTopLineWH(void);
|
|
|
+static void showTopLineSH(void);
|
|
|
static void showTopLineT(void);
|
|
|
static void showBotLineU(void);
|
|
|
static void showBotLineI(void);
|
|
|
static void showBotLineP(void);
|
|
|
static void showBotLineAH(void);
|
|
|
static void showBotLineWH(void);
|
|
|
+static void showBotLineSH(void);
|
|
|
static void showBotLineT(void);
|
|
|
|
|
|
static void blankTopLine(void);
|
|
@@ -160,7 +167,8 @@ void main(void)
|
|
|
|
|
|
/* ROTS tasks */
|
|
|
RTOS_SetTask(btnScan, 0, BTN_SCAN_PERIOD);
|
|
|
- RTOS_SetTask(readINAValues, 70, 250);
|
|
|
+ RTOS_SetTask(readINAValues, 69, 250);
|
|
|
+ RTOS_SetTask(calculateValues, 70, 1000);
|
|
|
RTOS_SetTask(showTopLineU, 71, 250);
|
|
|
RTOS_SetTask(showBotLineI, 72, 250);
|
|
|
|
|
@@ -323,9 +331,20 @@ static void displayMode(mode_led_t * disp, event_t event, uint8_t pos) {
|
|
|
case displayCP:
|
|
|
if (pos == 0) {
|
|
|
RTOS_DeleteTask(showTopLineWH);
|
|
|
- RTOS_SetTask(showTopLineT, 1000, 250);
|
|
|
+ RTOS_SetTask(showTopLineSH, 1000, 250);
|
|
|
} else {
|
|
|
RTOS_DeleteTask(showBotLineWH);
|
|
|
+ RTOS_SetTask(showBotLineSH, 1000, 250);
|
|
|
+ }
|
|
|
+ showLabelSH(pos);
|
|
|
+ *disp = displaySh;
|
|
|
+ break;
|
|
|
+ case displaySh:
|
|
|
+ if (pos == 0) {
|
|
|
+ RTOS_DeleteTask(showTopLineSH);
|
|
|
+ RTOS_SetTask(showTopLineT, 1000, 250);
|
|
|
+ } else {
|
|
|
+ RTOS_DeleteTask(showBotLineSH);
|
|
|
RTOS_SetTask(showBotLineT, 1000, 250);
|
|
|
}
|
|
|
showLabelT(pos);
|
|
@@ -408,10 +427,36 @@ static void btn2Long(void) {
|
|
|
/** Get values from INA219 and store to local variables. */
|
|
|
static void readINAValues(void) {
|
|
|
Voltage = readBusVoltage();
|
|
|
+ ShuntV = readShuntVoltage();
|
|
|
Current = readBusCurrent();
|
|
|
Power = readBusPower();
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Calculate Time, Capacitance AH and WH.
|
|
|
+ */
|
|
|
+static void calculateValues(void) {
|
|
|
+ if (Current != 0) {
|
|
|
+
|
|
|
+ // millivolt * milliamper = microwatt, convert it to milliwatt
|
|
|
+ //Power = ((uint32_t)(v * c) + 500) / 1000;
|
|
|
+
|
|
|
+ CapacityAH += Current;
|
|
|
+ CapacityWH += Power;
|
|
|
+
|
|
|
+ Timer.ss ++;
|
|
|
+ if (Timer.ss > 59) {
|
|
|
+ Timer.ss = 0;
|
|
|
+ Timer.mm ++;
|
|
|
+ if (Timer.mm > 59) {
|
|
|
+ Timer.mm = 0;
|
|
|
+ Timer.hh ++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* âûâîä èíôû íà âåðõíåì èíäèêàòîðå
|
|
|
*/
|
|
@@ -435,6 +480,10 @@ static void showTopLineWH(void) {
|
|
|
showCP(0);
|
|
|
}
|
|
|
|
|
|
+static void showTopLineSH(void) {
|
|
|
+ showSH(0);
|
|
|
+}
|
|
|
+
|
|
|
static void showTopLineT(void) {
|
|
|
showT(0);
|
|
|
}
|
|
@@ -466,6 +515,10 @@ static void showBotLineWH(void) {
|
|
|
showCP(4);
|
|
|
}
|
|
|
|
|
|
+static void showBotLineSH(void) {
|
|
|
+ showSH(4);
|
|
|
+}
|
|
|
+
|
|
|
static void showBotLineT(void) {
|
|
|
showT(4);
|
|
|
}
|
|
@@ -483,10 +536,6 @@ static void blankBotLine(void) {
|
|
|
static void showValue(uint32_t val, uint8_t pos) {
|
|
|
uint8_t tmp;
|
|
|
|
|
|
- if (pos != 0) {
|
|
|
- pos = 4;
|
|
|
- }
|
|
|
-
|
|
|
if (val >= 100000) { // 000.0
|
|
|
tmp = (uint8_t)(val / 100000);
|
|
|
val %= 100000;
|
|
@@ -563,7 +612,6 @@ void blankLine(uint8_t pos) {
|
|
|
* any other for bottom.
|
|
|
*/
|
|
|
static void showU(uint8_t pos) {
|
|
|
- //showValue(slowBuf.Voltage[slowBuf.idx], pos);
|
|
|
showValue(Voltage, pos);
|
|
|
}
|
|
|
|
|
@@ -573,7 +621,6 @@ static void showU(uint8_t pos) {
|
|
|
* any other for bottom.
|
|
|
*/
|
|
|
static void showI(uint8_t pos) {
|
|
|
- //showValue(slowBuf.Current[slowBuf.idx], pos);
|
|
|
showValue(Current, pos);
|
|
|
}
|
|
|
|
|
@@ -604,13 +651,31 @@ static void showCP(uint8_t pos) {
|
|
|
showValue(((CapacityWH + 1800) / 3600), pos);
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Output shunt voltage values to given indicator
|
|
|
+ * param: starting position -- 0 for top
|
|
|
+ * any other for bottom.
|
|
|
+ * LSB = 10 uV, may be negative!!!
|
|
|
+ */
|
|
|
+static void showSH(uint8_t pos) {
|
|
|
+ uint16_t val;
|
|
|
+
|
|
|
+ if (ShuntV < 0) {
|
|
|
+ val = - ShuntV;
|
|
|
+ } else {
|
|
|
+ val = ShuntV;
|
|
|
+ }
|
|
|
+
|
|
|
+ showValue(val, pos);
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Output time values to given indicator
|
|
|
* param: starting position -- 0 for top
|
|
|
* any other for bottom.
|
|
|
*/
|
|
|
static void showT(uint8_t pos) {
|
|
|
- static uint8_t halfsek = 0;
|
|
|
+ static uint8_t old_sek = 0;
|
|
|
uint8_t tmp;
|
|
|
|
|
|
if (Timer.hh > 0) {
|
|
@@ -618,7 +683,7 @@ static void showT(uint8_t pos) {
|
|
|
MAX7219_WriteData(digitPosition[pos], digitValue[tmp]);
|
|
|
pos ++;
|
|
|
tmp = Timer.hh % 10;
|
|
|
- if (halfsek == 0) {
|
|
|
+ if (old_sek == Timer.ss) {
|
|
|
MAX7219_WriteData(digitPosition[pos], digitValue[tmp]);
|
|
|
} else {
|
|
|
MAX7219_WriteData(digitPosition[pos], (digitValue[tmp] | Sym_Dot));
|
|
@@ -643,11 +708,7 @@ static void showT(uint8_t pos) {
|
|
|
MAX7219_WriteData(digitPosition[pos], digitValue[tmp]);
|
|
|
}
|
|
|
|
|
|
- if (halfsek == 0) {
|
|
|
- halfsek = 1;
|
|
|
- } else {
|
|
|
- halfsek = 0;
|
|
|
- }
|
|
|
+ old_sek = Timer.ss;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -703,6 +764,16 @@ static void showLabelWH(uint8_t pos) {
|
|
|
MAX7219_WriteData(digitPosition[pos], Sym_Minus);
|
|
|
}
|
|
|
|
|
|
+static void showLabelSH(uint8_t pos) {
|
|
|
+ MAX7219_WriteData(digitPosition[pos], Sym_Minus);
|
|
|
+ pos ++;
|
|
|
+ MAX7219_WriteData(digitPosition[pos], Sym_5);
|
|
|
+ pos ++;
|
|
|
+ MAX7219_WriteData(digitPosition[pos], Sym_h);
|
|
|
+ pos ++;
|
|
|
+ MAX7219_WriteData(digitPosition[pos], Sym_Minus);
|
|
|
+}
|
|
|
+
|
|
|
static void showLabelT(uint8_t pos) {
|
|
|
MAX7219_WriteData(digitPosition[pos], Sym_Minus);
|
|
|
pos ++;
|