added supercap charge delay
This commit is contained in:
parent
d7d0ea1a93
commit
3ff1af2c04
|
@ -14,12 +14,21 @@
|
|||
#define RX_CONC (3 + 0x9a - 0x80)
|
||||
|
||||
static struct lp8_t sensor;
|
||||
unsigned long delay_started = 0;
|
||||
bool delay_running = false;
|
||||
|
||||
bool init_module() {
|
||||
Serial1.begin(9600, SERIAL_8N2); //init Serial comm to lp8 sensor
|
||||
//init comms
|
||||
Serial1.begin(9600, SERIAL_8N2); //init Serial comm to lp8 sensor, 8data bits 2 stop bits, no parity
|
||||
Wire.begin(); //init arduino i2c
|
||||
|
||||
sensor.first_measurement_done = false;
|
||||
reset_module();
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool reset_module() {
|
||||
sensor.first_measurement_done = false; //no state writeback
|
||||
sensor.calibration_run = false;
|
||||
sensor.pressure = 10124;
|
||||
|
||||
|
@ -29,6 +38,11 @@ bool init_module() {
|
|||
|
||||
//set proper pins as outputs
|
||||
tca_set_port(0xee);
|
||||
//charge the cap
|
||||
tca_set_port(0xe8);
|
||||
//non blocking 15second delay to charge the cap
|
||||
delay_started = millis();
|
||||
delay_running = true;
|
||||
|
||||
sensor.state = LP8_STATE_INITIALIZE;
|
||||
return(true);
|
||||
|
@ -45,7 +59,7 @@ static void measure(){
|
|||
{
|
||||
//DIAG
|
||||
Serial.println(sensor.state);
|
||||
init_module();
|
||||
reset_module();
|
||||
goto start;
|
||||
}
|
||||
case LP8_STATE_READY:
|
||||
|
@ -63,8 +77,18 @@ static void measure(){
|
|||
{
|
||||
//DIAG
|
||||
Serial.println(sensor.state);
|
||||
sensor.state = LP8_STATE_PRECHARGE;
|
||||
|
||||
//wait 15s to ensure cap is sufficiently charged
|
||||
if(delay_running && ((millis() - delay_started) >= 15000)) {
|
||||
delay_running = false;
|
||||
sensor.state = LP8_STATE_PRECHARGE;
|
||||
}
|
||||
else if(!delay_running) {
|
||||
sensor.state = LP8_STATE_PRECHARGE;
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
|
||||
goto start;
|
||||
}
|
||||
case LP8_STATE_PRECHARGE:
|
||||
|
@ -278,8 +302,11 @@ static void measure(){
|
|||
|
||||
}
|
||||
|
||||
int16_t get_concentration() {
|
||||
int16_t get_concentration(uint16_t pressure = 10124) {
|
||||
|
||||
sensor.pressure = pressure;
|
||||
measure();
|
||||
|
||||
if(sensor.valid){
|
||||
return(sensor.concentration);
|
||||
}
|
||||
|
|
|
@ -51,8 +51,9 @@ struct lp8_t {
|
|||
};
|
||||
|
||||
bool init_module();
|
||||
bool reset_module();
|
||||
uint8_t get_ready_state();
|
||||
uint16_t calculate_crc16(uint8_t *buffer, uint8_t length);
|
||||
bool tca_set_port(uint8_t port);
|
||||
bool tca_set_direction(uint8_t dir);
|
||||
int16_t get_concentration();
|
||||
int16_t get_concentration(uint16_t pressure = 10124);
|
||||
|
|
Loading…
Reference in New Issue