Cleaning of code.
This commit is contained in:
@@ -8,7 +8,6 @@ _Objects Obj;
|
|||||||
|
|
||||||
#include "extend32to64.h"
|
#include "extend32to64.h"
|
||||||
extend32to64 longTime;
|
extend32to64 longTime;
|
||||||
volatile uint64_t irqTime = 0;
|
|
||||||
|
|
||||||
HardwareSerial Serial1(PA10, PA9);
|
HardwareSerial Serial1(PA10, PA9);
|
||||||
|
|
||||||
@@ -44,7 +43,7 @@ void ads1014_reset(ADS1014 *ads) {
|
|||||||
|
|
||||||
#include <queue>
|
#include <queue>
|
||||||
class OhmicSensing {
|
class OhmicSensing {
|
||||||
public:
|
public:
|
||||||
void handle(uint8_t voltageState, float inVoltage, float limitVoltage,
|
void handle(uint8_t voltageState, float inVoltage, float limitVoltage,
|
||||||
float voltageDropLimit, uint32_t setupTime, uint8_t enabled,
|
float voltageDropLimit, uint32_t setupTime, uint8_t enabled,
|
||||||
uint8_t &sensed);
|
uint8_t &sensed);
|
||||||
@@ -66,9 +65,6 @@ public:
|
|||||||
OhmicSensing Ohm1;
|
OhmicSensing Ohm1;
|
||||||
OhmicSensing Ohm2;
|
OhmicSensing Ohm2;
|
||||||
|
|
||||||
// DEBUG
|
|
||||||
volatile int saveALEvent;
|
|
||||||
|
|
||||||
void handleVoltageReader(float scale_in, float offset, float &outVoltage,
|
void handleVoltageReader(float scale_in, float offset, float &outVoltage,
|
||||||
int32_t &outRaw, float &oldVoltage, float &oldRaw,
|
int32_t &outRaw, float &oldVoltage, float &oldRaw,
|
||||||
uint8_t devType, int8_t &old_devType,
|
uint8_t devType, int8_t &old_devType,
|
||||||
@@ -87,7 +83,6 @@ void lowpassFilter(float &oldLowPassGain,
|
|||||||
#define bitflip(byte, nbit) ((byte) ^= (1 << (nbit)))
|
#define bitflip(byte, nbit) ((byte) ^= (1 << (nbit)))
|
||||||
#define bitcheck(byte, nbit) ((byte) & (1 << (nbit)))
|
#define bitcheck(byte, nbit) ((byte) & (1 << (nbit)))
|
||||||
|
|
||||||
volatile uint16_t ALEventIRQ; // ALEvent that caused the interrupt
|
|
||||||
extern "C" uint32_t ESC_SYNC0cycletime(void);
|
extern "C" uint32_t ESC_SYNC0cycletime(void);
|
||||||
|
|
||||||
void cb_set_outputs(void) // Get Master outputs, slave inputs, first operation
|
void cb_set_outputs(void) // Get Master outputs, slave inputs, first operation
|
||||||
@@ -149,10 +144,7 @@ void cb_get_inputs(void) // Set Master inputs, slave outputs, last operation
|
|||||||
Obj.In_Unit2.EnableOhmicSensing, Obj.Out_Unit2.OhmicSensingSensed);
|
Obj.In_Unit2.EnableOhmicSensing, Obj.Out_Unit2.OhmicSensingSensed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESC_interrupt_enable(uint32_t mask);
|
|
||||||
void ESC_interrupt_disable(uint32_t mask);
|
|
||||||
uint16_t dc_checker(void);
|
uint16_t dc_checker(void);
|
||||||
void sync0Handler(void);
|
|
||||||
|
|
||||||
static esc_cfg_t config = {
|
static esc_cfg_t config = {
|
||||||
.user_arg = NULL,
|
.user_arg = NULL,
|
||||||
@@ -173,8 +165,6 @@ static esc_cfg_t config = {
|
|||||||
.esc_check_dc_handler = dc_checker,
|
.esc_check_dc_handler = dc_checker,
|
||||||
};
|
};
|
||||||
|
|
||||||
volatile byte serveIRQ = 0;
|
|
||||||
|
|
||||||
void setup(void) {
|
void setup(void) {
|
||||||
Serial1.begin(115200);
|
Serial1.begin(115200);
|
||||||
|
|
||||||
@@ -275,8 +265,7 @@ void handleVoltageReader(float scale_in, float offset, float &outVoltage,
|
|||||||
MyMCP3221 *&mcp, uint8_t I2C_address,
|
MyMCP3221 *&mcp, uint8_t I2C_address,
|
||||||
uint32_t &I2C_restarts) {
|
uint32_t &I2C_restarts) {
|
||||||
float scale = scale_in;
|
float scale = scale_in;
|
||||||
if (scale == 0.0)
|
if (scale == 0.0) scale = 1.0;
|
||||||
scale = 1.0;
|
|
||||||
int stat = 1, data0;
|
int stat = 1, data0;
|
||||||
|
|
||||||
switch (devType) {
|
switch (devType) {
|
||||||
@@ -350,8 +339,7 @@ void handleVoltageReader(float scale_in, float offset, float &outVoltage,
|
|||||||
Wire2.begin();
|
Wire2.begin();
|
||||||
Wire2.setClock(I2C_BUS_SPEED);
|
Wire2.setClock(I2C_BUS_SPEED);
|
||||||
I2C_restarts++;
|
I2C_restarts++;
|
||||||
if (devType == ADS1014_TYPE && ads != nullptr)
|
if (devType == ADS1014_TYPE && ads != nullptr) ads1014_reset(ads);
|
||||||
ads1014_reset(ads);
|
|
||||||
// mcp3221 has no reset, reset the I2C bus is the best we can do
|
// mcp3221 has no reset, reset the I2C bus is the best we can do
|
||||||
}
|
}
|
||||||
readStat = stat;
|
readStat = stat;
|
||||||
@@ -394,8 +382,7 @@ void OhmicSensing::handle(uint8_t voltageState, float inVoltage,
|
|||||||
if (ohmicState == OHMIC_IDLE && inVoltage > limitVoltage) {
|
if (ohmicState == OHMIC_IDLE && inVoltage > limitVoltage) {
|
||||||
ohmicState = OHMIC_SETUP;
|
ohmicState = OHMIC_SETUP;
|
||||||
startTime = longTime.extendTime(micros());
|
startTime = longTime.extendTime(micros());
|
||||||
while (!voltages.empty())
|
while (!voltages.empty()) voltages.pop(); // Remove history
|
||||||
voltages.pop(); // Remove history
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ohmicState == OHMIC_SETUP) {
|
if (ohmicState == OHMIC_SETUP) {
|
||||||
@@ -413,8 +400,7 @@ void OhmicSensing::handle(uint8_t voltageState, float inVoltage,
|
|||||||
dTime = longTime.extendTime(micros()) - startTime;
|
dTime = longTime.extendTime(micros()) - startTime;
|
||||||
Obj.Out_Unit2.RawData = dTime;
|
Obj.Out_Unit2.RawData = dTime;
|
||||||
voltages.push(inVoltage);
|
voltages.push(inVoltage);
|
||||||
while (voltages.size() > N_VOLTAGES)
|
while (voltages.size() > N_VOLTAGES) voltages.pop(); // Only N_VOLTAGES
|
||||||
voltages.pop(); // Only N_VOLTAGES
|
|
||||||
if (dTime > 30000000) { // Go to IDLE after 30 seconds
|
if (dTime > 30000000) { // Go to IDLE after 30 seconds
|
||||||
ohmicState = OHMIC_IDLE;
|
ohmicState = OHMIC_IDLE;
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user