Added separate cmd file
This commit is contained in:
parent
db0e457450
commit
30afcdd8b7
6 changed files with 411 additions and 322 deletions
|
|
@ -84,10 +84,6 @@ update the voltMeterConstant variable in pP_config.h with the correct value
|
||||||
|
|
||||||
------------------------------------------------------------*/
|
------------------------------------------------------------*/
|
||||||
|
|
||||||
/* Debug output verbose mode will continuously output sensor readings
|
|
||||||
rather than waiting for user input */
|
|
||||||
#define VERBOSE true
|
|
||||||
|
|
||||||
// Headers, variables, and functions
|
// Headers, variables, and functions
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
|
|
|
||||||
119
firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_cmd.h
Normal file
119
firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_cmd.h
Normal file
|
|
@ -0,0 +1,119 @@
|
||||||
|
#ifndef PP_CMD_H
|
||||||
|
#define PP_CMD_H
|
||||||
|
|
||||||
|
#include "pP_config.h"
|
||||||
|
#include "pP_function.h"
|
||||||
|
#include "EEPROM.h"
|
||||||
|
|
||||||
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
|
void updateGainFactor(int value)
|
||||||
|
{
|
||||||
|
if (value >= 0)
|
||||||
|
{
|
||||||
|
GAIN_FACTOR = value;
|
||||||
|
adjustGain();
|
||||||
|
EEPROM.put(GAIN_FACTOR_ADDRESS, GAIN_FACTOR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
|
void updateVFol(int value)
|
||||||
|
{
|
||||||
|
if (value >= 0)
|
||||||
|
{
|
||||||
|
followerThrs = value;
|
||||||
|
adjustFollow();
|
||||||
|
EEPROM.put(FOLLOWER_THRESHOLD_ADDRESS, followerThrs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
|
void updateVComp(int value)
|
||||||
|
{
|
||||||
|
if (value >= 0)
|
||||||
|
{
|
||||||
|
compThrs = value;
|
||||||
|
adjustComp();
|
||||||
|
EEPROM.put(COMP_THRESHOLD_ADDRESS, compThrs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
|
void updateLoopDuration(int value)
|
||||||
|
{
|
||||||
|
if (value >= 0)
|
||||||
|
{
|
||||||
|
LOOP_DUR = value;
|
||||||
|
EEPROM.put(LOOP_DUR_ADDRESS, LOOP_DUR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
|
void updateTrigDuration(int value)
|
||||||
|
{
|
||||||
|
if (value >= 0)
|
||||||
|
{
|
||||||
|
TRG_DUR = value;
|
||||||
|
EEPROM.put(TRG_DUR_ADDRESS, TRG_DUR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
|
void updateHysteresis(int value)
|
||||||
|
{
|
||||||
|
if (value >= 0)
|
||||||
|
{
|
||||||
|
Hyst = value;
|
||||||
|
EEPROM.put(HYST_ADDRESS, Hyst);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
|
void updateLogic(int value)
|
||||||
|
{
|
||||||
|
if (value >= 0)
|
||||||
|
{
|
||||||
|
LOGIC = value;
|
||||||
|
EEPROM.put(LOGIC_ADDRESS, LOGIC);
|
||||||
|
pulse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
|
void updatePzDet(int value)
|
||||||
|
{
|
||||||
|
if (value >= 0)
|
||||||
|
{
|
||||||
|
PZDET = value;
|
||||||
|
EEPROM.put(PZDET_ADDRESS, PZDET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
|
void updateConstant(long value)
|
||||||
|
{
|
||||||
|
if (value >= 0)
|
||||||
|
{
|
||||||
|
voltMeterConstant = value;
|
||||||
|
EEPROM.put(VM_CONST_ADDRESS, voltMeterConstant);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
|
void updateDebug(int value)
|
||||||
|
{
|
||||||
|
if (value > 0)
|
||||||
|
{
|
||||||
|
Debug = 1;
|
||||||
|
}
|
||||||
|
else if (value == 0)
|
||||||
|
{
|
||||||
|
Debug = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //PP_CMD_H
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#include "pP_config.h"
|
#include "pP_config.h"
|
||||||
|
#include "pP_function.h"
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
|
|
||||||
int GAIN_FACTOR = GAIN_FACTOR_DEFAULT; // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x
|
int GAIN_FACTOR = GAIN_FACTOR_DEFAULT; // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x
|
||||||
|
|
@ -12,3 +13,111 @@ int PZDET = PZDET_DEFAULT; // Enable/disable piezo connection detection
|
||||||
int Debug = 0;
|
int Debug = 0;
|
||||||
long voltMeterConstant = VM_CONST_DEFAULT;
|
long voltMeterConstant = VM_CONST_DEFAULT;
|
||||||
uint8_t pP_i2c_address = 0xa0;
|
uint8_t pP_i2c_address = 0xa0;
|
||||||
|
|
||||||
|
/*------------------------------------------------*/
|
||||||
|
void eraseEEPROM() {
|
||||||
|
|
||||||
|
setDefaultConfig();
|
||||||
|
|
||||||
|
EEPROM.put(GAIN_FACTOR_ADDRESS, GAIN_FACTOR);
|
||||||
|
EEPROM.put(FOLLOWER_THRESHOLD_ADDRESS, followerThrs);
|
||||||
|
EEPROM.put(COMP_THRESHOLD_ADDRESS, compThrs);
|
||||||
|
EEPROM.put(LOOP_DUR_ADDRESS, LOOP_DUR);
|
||||||
|
EEPROM.put(TRG_DUR_ADDRESS, TRG_DUR);
|
||||||
|
EEPROM.put(HYST_ADDRESS, Hyst);
|
||||||
|
EEPROM.put(PZDET_ADDRESS, PZDET);
|
||||||
|
EEPROM.put(LOGIC_ADDRESS, LOGIC);
|
||||||
|
EEPROM.put(VM_CONST_ADDRESS, voltMeterConstant);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore config from EEPROM, otherwise erase config and write to EEPROM
|
||||||
|
void restoreConfig() {
|
||||||
|
int temp;
|
||||||
|
|
||||||
|
bool erase = false;
|
||||||
|
|
||||||
|
EEPROM.get(GAIN_FACTOR_ADDRESS, temp);
|
||||||
|
if (temp < 0 || temp > 4) {
|
||||||
|
erase = true;
|
||||||
|
} else {
|
||||||
|
GAIN_FACTOR = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
EEPROM.get(FOLLOWER_THRESHOLD_ADDRESS, temp);
|
||||||
|
if (temp < 0 || temp > 5000) {
|
||||||
|
erase = true;
|
||||||
|
} else {
|
||||||
|
followerThrs = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
EEPROM.get(COMP_THRESHOLD_ADDRESS, temp);
|
||||||
|
if (temp < 0 || temp > 5000) {
|
||||||
|
erase = true;
|
||||||
|
} else {
|
||||||
|
compThrs = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
EEPROM.get(LOOP_DUR_ADDRESS, temp);
|
||||||
|
if (temp < 0 && temp > 1000) {
|
||||||
|
erase = true;
|
||||||
|
} else {
|
||||||
|
LOOP_DUR = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
EEPROM.get(TRG_DUR_ADDRESS, temp);
|
||||||
|
if (temp < 0 || temp > 1000) {
|
||||||
|
erase = true;
|
||||||
|
} else {
|
||||||
|
TRG_DUR = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
EEPROM.get(HYST_ADDRESS, temp);
|
||||||
|
if (temp < 0 || temp > 1000) {
|
||||||
|
erase = true;
|
||||||
|
} else {
|
||||||
|
Hyst = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
EEPROM.get(PZDET_ADDRESS, temp);
|
||||||
|
if (temp < 0 || temp > 1) {
|
||||||
|
erase = true;
|
||||||
|
} else {
|
||||||
|
PZDET = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
EEPROM.get(LOGIC_ADDRESS, temp);
|
||||||
|
if (temp < 0 || temp > 1) {
|
||||||
|
erase = true;
|
||||||
|
} else {
|
||||||
|
LOGIC = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
long longTemp;
|
||||||
|
EEPROM.get(VM_CONST_ADDRESS, longTemp);
|
||||||
|
if (longTemp < 1000000L || longTemp > 1200000L) {
|
||||||
|
erase = true;
|
||||||
|
} else {
|
||||||
|
voltMeterConstant = longTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (erase) {
|
||||||
|
eraseEEPROM();
|
||||||
|
}
|
||||||
|
|
||||||
|
adjustFollow();
|
||||||
|
adjustComp();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDefaultConfig() {
|
||||||
|
GAIN_FACTOR = GAIN_FACTOR_DEFAULT;
|
||||||
|
followerThrs = FOLLOWER_THRESHOLD_DEFAULT;
|
||||||
|
compThrs = COMP_THRESHOLD_DEFAULT;
|
||||||
|
LOOP_DUR = LOOP_DUR_DEFAULT;
|
||||||
|
TRG_DUR = TRG_DUR_DEFAULT;
|
||||||
|
Hyst = HYST_DEFAULT;
|
||||||
|
PZDET = PZDET_DEFAULT;
|
||||||
|
LOGIC = LOGIC_DEFAULT;
|
||||||
|
voltMeterConstant = VM_CONST_DEFAULT;
|
||||||
|
adjustFollow();
|
||||||
|
adjustComp();
|
||||||
|
}
|
||||||
|
|
@ -6,17 +6,29 @@
|
||||||
//#pragma once
|
//#pragma once
|
||||||
//#include "pP_function.h"
|
//#include "pP_function.h"
|
||||||
|
|
||||||
void digitalWriteFast(uint8_t pin, uint8_t x) {
|
#ifndef PP_FUNCTION_H
|
||||||
if (pin / 8) { // pin >= 8
|
#define PP_FUNCTION_H
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "pP_volatile.h"
|
||||||
|
#include "pP_pins.h"
|
||||||
|
#include "stdint.h"
|
||||||
|
|
||||||
|
void digitalWriteFast(uint8_t pin, uint8_t x)
|
||||||
|
{
|
||||||
|
if (pin / 8)
|
||||||
|
{ // pin >= 8
|
||||||
PORTB ^= (-x ^ PORTB) & (1 << (pin % 8));
|
PORTB ^= (-x ^ PORTB) & (1 << (pin % 8));
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
PORTD ^= (-x ^ PORTD) & (1 << (pin % 8));
|
PORTD ^= (-x ^ PORTD) & (1 << (pin % 8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int inline analogReadFast(byte ADCpin)
|
int inline analogReadFast(byte ADCpin)
|
||||||
{ byte ADCSRAoriginal = ADCSRA;
|
{
|
||||||
|
byte ADCSRAoriginal = ADCSRA;
|
||||||
ADCSRA = (ADCSRA & B11111000) | 4;
|
ADCSRA = (ADCSRA & B11111000) | 4;
|
||||||
int adc = analogRead(ADCpin);
|
int adc = analogRead(ADCpin);
|
||||||
ADCSRA = ADCSRAoriginal;
|
ADCSRA = ADCSRAoriginal;
|
||||||
|
|
@ -25,13 +37,15 @@ int inline analogReadFast(byte ADCpin)
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void doubleFlash() {
|
void doubleFlash()
|
||||||
|
{
|
||||||
BlinkCount = 4;
|
BlinkCount = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void pulse() {
|
void pulse()
|
||||||
|
{
|
||||||
digitalWriteFast(TRG_OUT, LOGIC);
|
digitalWriteFast(TRG_OUT, LOGIC);
|
||||||
sensorHReading = 1;
|
sensorHReading = 1;
|
||||||
delay(TRG_DUR);
|
delay(TRG_DUR);
|
||||||
|
|
@ -42,7 +56,8 @@ void pulse() {
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
long readVcc() {
|
long readVcc()
|
||||||
|
{
|
||||||
// Read 1.1V reference against AVcc
|
// Read 1.1V reference against AVcc
|
||||||
|
|
||||||
// Atmega's Secret Voltmeter setup:
|
// Atmega's Secret Voltmeter setup:
|
||||||
|
|
@ -60,7 +75,8 @@ long readVcc() {
|
||||||
delay(2); // Wait for vref to settle
|
delay(2); // Wait for vref to settle
|
||||||
|
|
||||||
ADCSRA |= _BV(ADSC); // Start conversion
|
ADCSRA |= _BV(ADSC); // Start conversion
|
||||||
while (bit_is_set(ADCSRA,ADSC)); // measuring
|
while (bit_is_set(ADCSRA, ADSC))
|
||||||
|
; // measuring
|
||||||
|
|
||||||
uint8_t low = ADCL; // must read ADCL first - it then locks ADCH
|
uint8_t low = ADCL; // must read ADCL first - it then locks ADCH
|
||||||
uint8_t high = ADCH; // unlocks both
|
uint8_t high = ADCH; // unlocks both
|
||||||
|
|
@ -88,7 +104,8 @@ If the scale_constant calculated is different from the default 1125300,
|
||||||
update the voltMeterConstant variable in pP_config.h with the correct value
|
update the voltMeterConstant variable in pP_config.h with the correct value
|
||||||
--------------------------------------------------*/
|
--------------------------------------------------*/
|
||||||
|
|
||||||
void readVin() {
|
void readVin()
|
||||||
|
{
|
||||||
VOld = Vin;
|
VOld = Vin;
|
||||||
Vin = readVcc();
|
Vin = readVcc();
|
||||||
followerLong = followerThrs * 1023L;
|
followerLong = followerThrs * 1023L;
|
||||||
|
|
@ -101,7 +118,8 @@ update the voltMeterConstant variable in pP_config.h with the correct value
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void adjustFollow() {
|
void adjustFollow()
|
||||||
|
{
|
||||||
/* Compares diffs of threshold vs read value
|
/* Compares diffs of threshold vs read value
|
||||||
if positive, adjusts the follower to within
|
if positive, adjusts the follower to within
|
||||||
the range set above*/
|
the range set above*/
|
||||||
|
|
@ -116,7 +134,8 @@ update the voltMeterConstant variable in pP_config.h with the correct value
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void adjustComp() {
|
void adjustComp()
|
||||||
|
{
|
||||||
compLong = compThrs * 1023L;
|
compLong = compThrs * 1023L;
|
||||||
compInt = (long long)compLong / Vin;
|
compInt = (long long)compLong / Vin;
|
||||||
compInt = (int)compInt;
|
compInt = (int)compInt;
|
||||||
|
|
@ -125,16 +144,19 @@ void adjustComp() {
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void calibrateAlert() {
|
void calibrateAlert()
|
||||||
|
{
|
||||||
VLast = VOld - Vin;
|
VLast = VOld - Vin;
|
||||||
if (VLast > Hyst || VLast < -Hyst ) {
|
if (VLast > Hyst || VLast < -Hyst)
|
||||||
|
{
|
||||||
ERR_STATE = 1;
|
ERR_STATE = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void adjustGain() {
|
void adjustGain()
|
||||||
|
{
|
||||||
switch (GAIN_FACTOR)
|
switch (GAIN_FACTOR)
|
||||||
{
|
{
|
||||||
case 4:
|
case 4:
|
||||||
|
|
@ -184,118 +206,14 @@ void adjustGain() {
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void pzConCheck () {
|
void pzConCheck()
|
||||||
|
{
|
||||||
PZ_STATE = digitalRead(PZDET_PIN);
|
PZ_STATE = digitalRead(PZDET_PIN);
|
||||||
if (PZ_STATE == PZDET) {
|
if (PZ_STATE == PZDET)
|
||||||
|
{
|
||||||
//digitalWriteFast(TRG_OUT, LOGIC);
|
//digitalWriteFast(TRG_OUT, LOGIC);
|
||||||
ERR_STATE = 1;
|
ERR_STATE = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
#endif //PP_FUNCTION_H
|
||||||
void eraseEEPROM() {
|
|
||||||
|
|
||||||
setDefaultConfig();
|
|
||||||
|
|
||||||
EEPROM.put(GAIN_FACTOR_ADDRESS, GAIN_FACTOR);
|
|
||||||
EEPROM.put(FOLLOWER_THRESHOLD_ADDRESS, followerThrs);
|
|
||||||
EEPROM.put(COMP_THRESHOLD_ADDRESS, compThrs);
|
|
||||||
EEPROM.put(LOOP_DUR_ADDRESS, LOOP_DUR);
|
|
||||||
EEPROM.put(TRG_DUR_ADDRESS, TRG_DUR);
|
|
||||||
EEPROM.put(HYST_ADDRESS, Hyst);
|
|
||||||
EEPROM.put(PZDET_ADDRESS, PZDET);
|
|
||||||
EEPROM.put(LOGIC_ADDRESS, LOGIC);
|
|
||||||
EEPROM.put(VM_CONST_ADDRESS, voltMeterConstant);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restore config from EEPROM, otherwise erase config and write to EEPROM
|
|
||||||
void restoreConfig() {
|
|
||||||
int temp;
|
|
||||||
|
|
||||||
bool erase = false;
|
|
||||||
|
|
||||||
EEPROM.get(GAIN_FACTOR_ADDRESS, temp);
|
|
||||||
if (temp < 0 || temp > 4) {
|
|
||||||
erase = true;
|
|
||||||
} else {
|
|
||||||
GAIN_FACTOR = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
EEPROM.get(FOLLOWER_THRESHOLD_ADDRESS, temp);
|
|
||||||
if (temp < 0 || temp > 5000) {
|
|
||||||
erase = true;
|
|
||||||
} else {
|
|
||||||
followerThrs = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
EEPROM.get(COMP_THRESHOLD_ADDRESS, temp);
|
|
||||||
if (temp < 0 || temp > 5000) {
|
|
||||||
erase = true;
|
|
||||||
} else {
|
|
||||||
compThrs = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
EEPROM.get(LOOP_DUR_ADDRESS, temp);
|
|
||||||
if (temp < 0 && temp > 1000) {
|
|
||||||
erase = true;
|
|
||||||
} else {
|
|
||||||
LOOP_DUR = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
EEPROM.get(TRG_DUR_ADDRESS, temp);
|
|
||||||
if (temp < 0 || temp > 1000) {
|
|
||||||
erase = true;
|
|
||||||
} else {
|
|
||||||
TRG_DUR = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
EEPROM.get(HYST_ADDRESS, temp);
|
|
||||||
if (temp < 0 || temp > 1000) {
|
|
||||||
erase = true;
|
|
||||||
} else {
|
|
||||||
Hyst = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
EEPROM.get(PZDET_ADDRESS, temp);
|
|
||||||
if (temp < 0 || temp > 1) {
|
|
||||||
erase = true;
|
|
||||||
} else {
|
|
||||||
PZDET = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
EEPROM.get(LOGIC_ADDRESS, temp);
|
|
||||||
if (temp < 0 || temp > 1) {
|
|
||||||
erase = true;
|
|
||||||
} else {
|
|
||||||
LOGIC = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
long longTemp;
|
|
||||||
EEPROM.get(VM_CONST_ADDRESS, longTemp);
|
|
||||||
if (longTemp < 1000000L || longTemp > 1200000L) {
|
|
||||||
erase = true;
|
|
||||||
} else {
|
|
||||||
voltMeterConstant = longTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (erase) {
|
|
||||||
eraseEEPROM();
|
|
||||||
}
|
|
||||||
|
|
||||||
adjustFollow();
|
|
||||||
adjustComp();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDefaultConfig() {
|
|
||||||
GAIN_FACTOR = GAIN_FACTOR_DEFAULT;
|
|
||||||
followerThrs = FOLLOWER_THRESHOLD_DEFAULT;
|
|
||||||
compThrs = COMP_THRESHOLD_DEFAULT;
|
|
||||||
LOOP_DUR = LOOP_DUR_DEFAULT;
|
|
||||||
TRG_DUR = TRG_DUR_DEFAULT;
|
|
||||||
Hyst = HYST_DEFAULT;
|
|
||||||
PZDET = PZDET_DEFAULT;
|
|
||||||
LOGIC = LOGIC_DEFAULT;
|
|
||||||
voltMeterConstant = VM_CONST_DEFAULT;
|
|
||||||
adjustFollow();
|
|
||||||
adjustComp();
|
|
||||||
}
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
void parseData() {
|
#include "pP_cmd.h"
|
||||||
|
|
||||||
|
void parseData()
|
||||||
|
{
|
||||||
|
|
||||||
// split the data into its parts
|
// split the data into its parts
|
||||||
|
|
||||||
|
|
@ -9,40 +12,48 @@ void parseData() {
|
||||||
|
|
||||||
strtokIndx = strtok(NULL, " "); // this continues where the previous call left off
|
strtokIndx = strtok(NULL, " "); // this continues where the previous call left off
|
||||||
serialLong = atol(strtokIndx); // convert this part to an integer
|
serialLong = atol(strtokIndx); // convert this part to an integer
|
||||||
|
|
||||||
}
|
}
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void identifyMarkers() {
|
void identifyMarkers()
|
||||||
|
{
|
||||||
|
|
||||||
char x = Serial.read();
|
char x = Serial.read();
|
||||||
#ifdef I2C_INPUT
|
#ifdef I2C_INPUT
|
||||||
char y = Wire.read();
|
char y = Wire.read();
|
||||||
#endif // I2C_INPUT
|
#endif // I2C_INPUT
|
||||||
|
|
||||||
if (x == '\n' || x == '\r') {
|
if (x == '\n' || x == '\r')
|
||||||
|
{
|
||||||
serialIncoming = true;
|
serialIncoming = true;
|
||||||
inputBuffer[bytesRecvd] = 0;
|
inputBuffer[bytesRecvd] = 0;
|
||||||
parseData();
|
parseData();
|
||||||
bytesRecvd = 0;
|
bytesRecvd = 0;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
inputBuffer[bytesRecvd] = x;
|
inputBuffer[bytesRecvd] = x;
|
||||||
bytesRecvd++;
|
bytesRecvd++;
|
||||||
if (bytesRecvd == buffSize) {
|
if (bytesRecvd == buffSize)
|
||||||
|
{
|
||||||
bytesRecvd = buffSize - 1;
|
bytesRecvd = buffSize - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef I2C_INPUT
|
#ifdef I2C_INPUT
|
||||||
if (y == '\n' || y == '\r') {
|
if (y == '\n' || y == '\r')
|
||||||
|
{
|
||||||
serialIncoming = true;
|
serialIncoming = true;
|
||||||
inputBuffer[bytesRecvd] = 0;
|
inputBuffer[bytesRecvd] = 0;
|
||||||
parseData();
|
parseData();
|
||||||
bytesRecvd = 0;
|
bytesRecvd = 0;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
inputBuffer[bytesRecvd] = y;
|
inputBuffer[bytesRecvd] = y;
|
||||||
bytesRecvd++;
|
bytesRecvd++;
|
||||||
if (bytesRecvd == buffSize) {
|
if (bytesRecvd == buffSize)
|
||||||
|
{
|
||||||
bytesRecvd = buffSize - 1;
|
bytesRecvd = buffSize - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -51,100 +62,12 @@ void identifyMarkers() {
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
void updateGainFactor()
|
void serialPrintConfig()
|
||||||
{
|
{
|
||||||
if (serialLong >= 0) {
|
|
||||||
GAIN_FACTOR = serialLong;
|
|
||||||
adjustGain();
|
|
||||||
EEPROM.put(GAIN_FACTOR_ADDRESS, GAIN_FACTOR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
|
||||||
|
|
||||||
void updateVFol() {
|
|
||||||
if (serialLong >= 0) {
|
|
||||||
followerThrs = serialLong;
|
|
||||||
adjustFollow();
|
|
||||||
EEPROM.put(FOLLOWER_THRESHOLD_ADDRESS, followerThrs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*------------------------------------------------*/
|
|
||||||
|
|
||||||
void updateVComp() {
|
|
||||||
if (serialLong >= 0) {
|
|
||||||
compThrs = serialLong;
|
|
||||||
adjustComp();
|
|
||||||
EEPROM.put(COMP_THRESHOLD_ADDRESS, compThrs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
|
||||||
|
|
||||||
void updateLoopDuration() {
|
|
||||||
if (serialLong >= 0) {
|
|
||||||
LOOP_DUR = serialLong;
|
|
||||||
EEPROM.put(LOOP_DUR_ADDRESS, LOOP_DUR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*------------------------------------------------*/
|
|
||||||
|
|
||||||
void updateTrigDuration() {
|
|
||||||
if (serialLong >= 0) {
|
|
||||||
TRG_DUR = serialLong;
|
|
||||||
EEPROM.put(TRG_DUR_ADDRESS, TRG_DUR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*------------------------------------------------*/
|
|
||||||
|
|
||||||
void updateHysteresis() {
|
|
||||||
if (serialLong >= 0) {
|
|
||||||
Hyst = serialLong;
|
|
||||||
EEPROM.put(HYST_ADDRESS, Hyst);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*------------------------------------------------*/
|
|
||||||
|
|
||||||
void updateLogic() {
|
|
||||||
if (serialLong >= 0) {
|
|
||||||
LOGIC = serialLong;
|
|
||||||
EEPROM.put(LOGIC_ADDRESS, LOGIC);
|
|
||||||
pulse();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*------------------------------------------------*/
|
|
||||||
|
|
||||||
void updatePzDet() {
|
|
||||||
if (serialLong >= 0) {
|
|
||||||
PZDET = serialLong;
|
|
||||||
EEPROM.put(PZDET_ADDRESS, PZDET);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*------------------------------------------------*/
|
|
||||||
|
|
||||||
void updateConstant() {
|
|
||||||
if (serialLong >= 0) {
|
|
||||||
voltMeterConstant = (long) serialLong;
|
|
||||||
EEPROM.put(VM_CONST_ADDRESS, voltMeterConstant);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
|
||||||
|
|
||||||
void updateDebug() {
|
|
||||||
if (serialLong > 0) {
|
|
||||||
Debug = 1;
|
|
||||||
} else if (serialLong == 0) {
|
|
||||||
Debug = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
|
||||||
|
|
||||||
void serialPrintConfig() {
|
|
||||||
Serial.print("GAIN_F ");
|
Serial.print("GAIN_F ");
|
||||||
Serial.print(GAIN_FACTOR);
|
Serial.print(GAIN_FACTOR);
|
||||||
switch (GAIN_FACTOR) {
|
switch (GAIN_FACTOR)
|
||||||
|
{
|
||||||
case 0:
|
case 0:
|
||||||
Serial.println(" 3x");
|
Serial.println(" 3x");
|
||||||
break;
|
break;
|
||||||
|
|
@ -193,7 +116,8 @@ void serialPrintConfig() {
|
||||||
Serial.println(PP_VERSION);
|
Serial.println(PP_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
void serialPrintState() {
|
void serialPrintState()
|
||||||
|
{
|
||||||
Serial.print("{");
|
Serial.print("{");
|
||||||
|
|
||||||
Serial.print("\"Vcc\":");
|
Serial.print("\"Vcc\":");
|
||||||
|
|
@ -223,49 +147,64 @@ void serialPrintState() {
|
||||||
Serial.println("}");
|
Serial.println("}");
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateParams() {
|
void updateParams()
|
||||||
|
{
|
||||||
serialIncoming = false;
|
serialIncoming = false;
|
||||||
if (strcmp(serialMessageIn, "GAIN_F") == 0) {
|
if (strcmp(serialMessageIn, "GAIN_F") == 0)
|
||||||
updateGainFactor();
|
{
|
||||||
|
updateGainFactor(serialLong);
|
||||||
}
|
}
|
||||||
else if (strcmp(serialMessageIn, "VFOL") == 0) {
|
else if (strcmp(serialMessageIn, "VFOL") == 0)
|
||||||
updateVFol();
|
{
|
||||||
|
updateVFol(serialLong);
|
||||||
}
|
}
|
||||||
else if (strcmp(serialMessageIn, "VCOMP") == 0) {
|
else if (strcmp(serialMessageIn, "VCOMP") == 0)
|
||||||
updateVComp();
|
{
|
||||||
|
updateVComp(serialLong);
|
||||||
}
|
}
|
||||||
else if (strcmp(serialMessageIn, "LOOP_D") == 0) {
|
else if (strcmp(serialMessageIn, "LOOP_D") == 0)
|
||||||
updateLoopDuration();
|
{
|
||||||
|
updateLoopDuration(serialLong);
|
||||||
}
|
}
|
||||||
else if (strcmp(serialMessageIn, "TRG_D") == 0) {
|
else if (strcmp(serialMessageIn, "TRG_D") == 0)
|
||||||
updateTrigDuration();
|
{
|
||||||
|
updateTrigDuration(serialLong);
|
||||||
}
|
}
|
||||||
else if (strcmp(serialMessageIn, "HYST") == 0) {
|
else if (strcmp(serialMessageIn, "HYST") == 0)
|
||||||
updateHysteresis();
|
{
|
||||||
|
updateHysteresis(serialLong);
|
||||||
}
|
}
|
||||||
else if (strcmp(serialMessageIn, "LOGIC") == 0) {
|
else if (strcmp(serialMessageIn, "LOGIC") == 0)
|
||||||
updateLogic();
|
{
|
||||||
|
updateLogic(serialLong);
|
||||||
}
|
}
|
||||||
else if (strcmp(serialMessageIn, "PZDET") == 0) {
|
else if (strcmp(serialMessageIn, "PZDET") == 0)
|
||||||
updatePzDet();
|
{
|
||||||
|
updatePzDet(serialLong);
|
||||||
}
|
}
|
||||||
else if (strcmp(serialMessageIn, "CONST") == 0) {
|
else if (strcmp(serialMessageIn, "CONST") == 0)
|
||||||
updateConstant();
|
{
|
||||||
|
updateConstant(serialLong);
|
||||||
}
|
}
|
||||||
else if (strcmp(serialMessageIn, "DEBUG") == 0) {
|
else if (strcmp(serialMessageIn, "DEBUG") == 0)
|
||||||
updateDebug();
|
{
|
||||||
|
updateDebug(serialLong);
|
||||||
}
|
}
|
||||||
else if (strcmp(serialMessageIn, "CONFIG") == 0) {
|
else if (strcmp(serialMessageIn, "CONFIG") == 0)
|
||||||
|
{
|
||||||
serialPrintConfig();
|
serialPrintConfig();
|
||||||
}
|
}
|
||||||
else if (strcmp(serialMessageIn, "ERASE") == 0) {
|
else if (strcmp(serialMessageIn, "ERASE") == 0)
|
||||||
|
{
|
||||||
eraseEEPROM();
|
eraseEEPROM();
|
||||||
serialPrintConfig();
|
serialPrintConfig();
|
||||||
}
|
}
|
||||||
else if (strcmp(serialMessageIn, "STATE") == 0) {
|
else if (strcmp(serialMessageIn, "STATE") == 0)
|
||||||
|
{
|
||||||
serialPrintState();
|
serialPrintState();
|
||||||
}
|
}
|
||||||
else if (strcmp(serialMessageIn, "HELP") == 0) {
|
else if (strcmp(serialMessageIn, "HELP") == 0)
|
||||||
|
{
|
||||||
#if defined(ARDUINO_AVR_ATmega328PB)
|
#if defined(ARDUINO_AVR_ATmega328PB)
|
||||||
Serial.println("To change gain factor: GAIN_F [integer for gain state - see note*]");
|
Serial.println("To change gain factor: GAIN_F [integer for gain state - see note*]");
|
||||||
Serial.println("To change voltage follower voltage (low threshold): VFOL [float value]");
|
Serial.println("To change voltage follower voltage (low threshold): VFOL [float value]");
|
||||||
|
|
@ -296,10 +235,11 @@ void updateParams() {
|
||||||
parseData();
|
parseData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void serialInput()
|
||||||
void serialInput() {
|
{
|
||||||
// receive data from Serial and save it into inputBuffer
|
// receive data from Serial and save it into inputBuffer
|
||||||
if (Serial.available() > 0) {
|
if (Serial.available() > 0)
|
||||||
|
{
|
||||||
|
|
||||||
// the order of these IF clauses is significant
|
// the order of these IF clauses is significant
|
||||||
identifyMarkers();
|
identifyMarkers();
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,8 @@
|
||||||
|
#ifndef PP_VOLATILE_H
|
||||||
|
#define PP_VOLATILE_H
|
||||||
|
|
||||||
|
#include "LightChrono.h"
|
||||||
|
|
||||||
// these variables will change on their own. Do not edit ANYTHING below this line
|
// these variables will change on their own. Do not edit ANYTHING below this line
|
||||||
volatile int sensorHReading = 0; // variable to store the value read from the sensor pin
|
volatile int sensorHReading = 0; // variable to store the value read from the sensor pin
|
||||||
volatile int ADJ_FOLLOW = 0; // Variable for Follower adjustment
|
volatile int ADJ_FOLLOW = 0; // Variable for Follower adjustment
|
||||||
|
|
@ -41,3 +46,5 @@ long serialLong = 0;
|
||||||
|
|
||||||
// Task scheduler instances
|
// Task scheduler instances
|
||||||
LightChrono mainLoop;
|
LightChrono mainLoop;
|
||||||
|
|
||||||
|
#endif //PP_VOLATILE_H
|
||||||
Loading…
Reference in a new issue