Skip to content

Commit

Permalink
Fixed reset settings and calculation of nMaxByte and nMessageBlocks. …
Browse files Browse the repository at this point in the history
…Should fix #1
  • Loading branch information
aringot committed Dec 16, 2019
1 parent 4733357 commit 3f41eeb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ private void startDecoder() {
config.setFrequencyZero(f0);
config.setBitperiod(bitperiod);
config.setPauseperiod(pauseperiod);
int nMessageBlocks = (nMaxBytes+2) / 2; // Default is 10 (transmitting 20 bytes with 16 frequencies)
int nMessageBlocks = calculateNumberOfMessageBlocks(nFrequencies, nMaxBytes);// Default is 10 (transmitting 20 bytes with 16 frequencies)
config.setnMessageBlocks(nMessageBlocks);
config.setnFrequencies(nFrequencies);
config.setFrequencySpace(frequencySpace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import at.ac.fhstp.sonitalk.SoniTalkConfig;
import at.ac.fhstp.sonitalk.exceptions.ConfigException;
import at.ac.fhstp.sonitalk.utils.ConfigFactory;
import at.ac.fhstp.sonitalk.utils.EncoderUtils;

public class SettingsFragment extends PreferenceFragment {

Expand Down Expand Up @@ -374,36 +375,8 @@ public void onClick(DialogInterface dialog, int which) {
private void resetSettings() {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
SharedPreferences.Editor editor = preferences.edit();
SoniTalkConfig config = getDefaultSettings();

editor.putString(ConfigConstants.FREQUENCY_ZERO, String.valueOf(config.getFrequencyZero()));
editor.putString(ConfigConstants.BIT_PERIOD, String.valueOf(config.getBitperiod()));
editor.putString(ConfigConstants.PAUSE_PERIOD, String.valueOf(config.getPauseperiod()));
editor.putString(ConfigConstants.SPACE_BETWEEN_FREQUENCIES, String.valueOf(config.getFrequencySpace()));
editor.putString(ConfigConstants.NUMBER_OF_BYTES, String.valueOf((config.getnMessageBlocks()*2-2)));
editor.putString(ConfigConstants.LOUDNESS, ConfigConstants.SETTING_LOUDNESS_DEFAULT);
editor.putString(ConfigConstants.PRESET, String.valueOf("default_config.json"));

/*editor.putString(ConfigConstants.FREQUENCY_ZERO, ConfigConstants.SETTING_FREQUENCY_ZERO_DEFAULT);
editor.putString(ConfigConstants.BIT_PERIOD, ConfigConstants.SETTING_BIT_PERIOD_DEFAULT);
editor.putString(ConfigConstants.PAUSE_PERIOD, ConfigConstants.SETTING_PAUSE_PERIOD_DEFAULT);
editor.putString(ConfigConstants.SPACE_BETWEEN_FREQUENCIES, ConfigConstants.SETTING_SPACE_BETWEEN_FREQUENCIES_DEFAULT);
editor.putString(ConfigConstants.NUMBER_OF_BYTES, ConfigConstants.SETTING_NUMBER_OF_BYTES_DEFAULT);
editor.putInt(ConfigConstants.LOUDNESS, ConfigConstants.SETTING_LOUDNESS_DEFAULT);*/
editor.apply();
editor.commit();

etFrequencyZero.setText(String.valueOf(config.getFrequencyZero()));
etBitperiod.setText(String.valueOf(config.getBitperiod()));
etPauseperiod.setText(String.valueOf(config.getPauseperiod()));
etFrequencyspace.setText(String.valueOf(config.getFrequencySpace()));
etNMaxCharacters.setText(String.valueOf(config.getnMessageBlocks()*2-2));
lpNumberOfFrequencies.setValueIndex(1);

String presetsStr = String.format(getString(R.string.settings_preset_title), String.valueOf("default_config.json"));
prefPresets.setTitle(presetsStr);

setPreferenceValues();
SoniTalkConfig defaultConfig = getDefaultConfig();
setToConfig(defaultConfig, "default_config.json");
}

private void setPreferenceValues(){
Expand Down Expand Up @@ -443,7 +416,7 @@ private void setPreferenceValues(){
prefPresets.setTitle(prPresets);
}

private SoniTalkConfig getDefaultSettings(){
private SoniTalkConfig getDefaultConfig(){
SoniTalkConfig config = null;
try {
config = ConfigFactory.getDefaultConfig(getContext());
Expand All @@ -462,22 +435,25 @@ private void setToConfig(SoniTalkConfig config, String configName){
editor.putString(ConfigConstants.FREQUENCY_ZERO, String.valueOf(config.getFrequencyZero()));
editor.putString(ConfigConstants.BIT_PERIOD, String.valueOf(config.getBitperiod()));
editor.putString(ConfigConstants.PAUSE_PERIOD, String.valueOf(config.getPauseperiod()));
editor.putString(ConfigConstants.NUMBER_OF_FREQUENCIES, String.valueOf(config.getnFrequencies()));
editor.putString(ConfigConstants.SPACE_BETWEEN_FREQUENCIES, String.valueOf(config.getFrequencySpace()));
editor.putString(ConfigConstants.NUMBER_OF_BYTES, String.valueOf((config.getnMessageBlocks()*2-2)));
editor.putString(ConfigConstants.NUMBER_OF_BYTES, String.valueOf(EncoderUtils.getMaxChars(config.getnMessageBlocks(), config.getnFrequencies())));
editor.putString(ConfigConstants.LOUDNESS, ConfigConstants.SETTING_LOUDNESS_DEFAULT);
editor.putString(ConfigConstants.PRESET, configName);

editor.apply();
editor.commit();

etFrequencyZero.setText(String.valueOf(config.getFrequencyZero()));
etBitperiod.setText(String.valueOf(config.getBitperiod()));
etPauseperiod.setText(String.valueOf(config.getPauseperiod()));
etFrequencyspace.setText(String.valueOf(config.getFrequencySpace()));
etNMaxCharacters.setText(String.valueOf(config.getnMessageBlocks()*2-2));
etNMaxCharacters.setText(String.valueOf(EncoderUtils.getMaxChars(config.getnMessageBlocks(), config.getnFrequencies())));

lpNumberOfFrequencies.setValueIndex(checkFrequencyListViewIndex(String.valueOf(config.getnFrequencies())));

String presetsStr = String.format(getString(R.string.settings_preset_title), configName);
prefPresets.setTitle(presetsStr);

setPreferenceValues();
}

Expand Down

0 comments on commit 3f41eeb

Please sign in to comment.