Skip to content

Commit

Permalink
fixed platformio.ini to allow build and upload directly #bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
pyr0ball committed Dec 31, 2019
1 parent 30999ed commit 79f0d65
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 8 deletions.
34 changes: 26 additions & 8 deletions firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/platformio.ini
Expand Up @@ -11,12 +11,27 @@
[platformio]
default_envs = ATmega328PB

[env:ICSP_Bootloader]
platform = atmelavr
framework = arduino
upload_protocol = stk500v1
; each flag in a new line
upload_flags =
-P$UPLOAD_PORT
-b$UPLOAD_SPEED

board_build.f_cpu = 8000000L
board_hardware.oscillator = internal
board_hardware.uart = uart0
board_hardware.bod = 1.8v
board_hardware.eesave = yes

[env:ATmega88P]
platform = atmelavr
board = ATmega88P
framework = arduino
lib_deps = Arduino
upload_protocol = stk500v1
upload_protocol = arduino
; each flag in a new line
upload_flags =
-P$UPLOAD_PORT
Expand All @@ -28,24 +43,27 @@ upload_flags =
upload_speed = 38400

board_build.f_cpu = 8000000L
board_fuses.lfuse = "0xE2"
board_fuses.hfuse = "0xDF"
board_fuses.efuse = "0xF9"
board_hardware.oscillator = internal
board_hardware.uart = uart0
board_hardware.bod = 1.8v
board_hardware.eesave = yes

[env:ATmega328PB]
platform = atmelavr
board = ATmega328PB
framework = arduino
lib_deps = Arduino
upload_protocol = stk500v1
upload_protocol = arduino
; each flag in a new line
upload_flags =
-P$UPLOAD_PORT
-b$UPLOAD_SPEED
-fmax_errors=5

; edit these lines
;upload_port = COM4
upload_speed = 38400

board_build.f_cpu = 8000000L
board_build.f_cpu = 8000000L
board_hardware.oscillator = internal
board_hardware.uart = uart0
board_hardware.bod = 1.8v
board_hardware.eesave = yes
97 changes: 97 additions & 0 deletions firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_function.h
Expand Up @@ -186,3 +186,100 @@ void pzConCheck () {
}

/*------------------------------------------------*/
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(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(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;
LOGIC = LOGIC_DEFAULT;
voltMeterConstant = VM_CONST_DEFAULT;
adjustFollow();
adjustComp();
}

0 comments on commit 79f0d65

Please sign in to comment.