Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Factory setting mode" #146

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 20 additions & 152 deletions firmware/src/keypad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

// OpenSmartMeter libraries
#include "led_buzzer.hpp"
#include "time_management.hpp"
#include "token_management.hpp"

#define STAR_KEY -1
#define HASH_KEY -2
Expand All @@ -31,146 +29,6 @@ byte colPins[COLS] = {PA7, PA6, PA5, PC13};
Keypad customKeypad =
Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void FactorySetting() {
lcd.clear();
lcd.setCursor(0, 0);
data_count = 0;
lcd_count = 8;
dt = 0;
switch (setting_mode) {
case 1:
lcd.println(
"001:Reinitialisation 011:Configuration 021:Change password");
setting_mode = 2;
break;

case 2: // Reinitialize values
if (sts_data == "001") {
fault = 0;
billing = 0.0;
true_power = 0.0;
ENERGY = 0.0;
freq = 0.0;
curr = 0.0;
powerFactor = 0.0;
mains_input_value = 0.0;

InvalidTokenCount = 0;
TokenCount = 1;
UsedTokens = 0;
PAYGEnabled = true;
ActiveUntil = 0;
TokenEntryLockedUntil = 0;
nbDisconnections = 0;
StoreActivationVariables();

topup = 0.0;
topupnew = 0;

warntime = 0;
warn_now = 0;

timeInitializationRtc = 0;
hours = 0;
minutes = 0;
seconds = 0;
rtcday = 0;
nw_month_cnt = 0;
rtcmonth = 0;
rtcnewmonth = 0;
billing_date = 0;

thingsboard_check = 0;

lastmonth_KWH = 0.0;
initializeTime();

lcdtime_now = 0;
prev_lcdtime = 0;
cnt = 0;
lcd_count = 0;
data_count = 0;
dt = 0;
parameters = 0;
token_used = 0;

sts_eeprom_fetched = 0;
token_eeprom_location = 20;
eeprom_location_cnt = 40;

sts_value = 0;
sts_mode = 0;

lcd.println("Values reinitialize");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
setting_mode = 0;
}

if (sts_data == "011") { // Configure mode
lcd.println("112:STS 122:Energy-based 132:Timed-based");
setting_mode = 3;
}

if (sts_data == "021") { // Change Password
lcd.println("Old password: ");
setting_mode = 4;
}
break;

case 3:
if (sts_data == "112") {
Mode_select = 1; // For STS Mode (Energy-based)
lcd.println("configured to STS Mode");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
}

if (sts_data == "122") {
Mode_select = 2; // For OpenPaygo Energy-based
lcd.println("configured to OPaygo Energy-based Mode");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
}

if (sts_data == "132") {
Mode_select = 3; // For OpenPaygo Time-based
lcd.println("configured to OPaygo Time-based Mode");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
}
setting_mode = 0;
break;

case 4: // Enter new password
if (sts_data == password) {
lcd.println("New password: ");
setting_mode = 5;
}
break;

case 5: // confirm new password
new_password = sts_data;
lcd.println("confirm new password: ");
setting_mode = 6;
break;

case 6: // Password Changed
if (sts_data == new_password) {
password = new_password;
lcd.println("password changed ");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
setting_mode = 0;
}
break;
}
}
// For STS

void STS_keypad() {
Expand All @@ -186,11 +44,9 @@ void STS_keypad() {
lcd.setCursor(0, 0);
sts_mode = 1;
if (customKeypad.getState() == HOLD) {
lcd.println("Enter Password to start factory setting: ");
setting_mode = 1;
lcd.println("Password: ");
} else {
lcd.print("TOKEN: ");
setting_mode = 0;
}
}

Expand Down Expand Up @@ -240,13 +96,25 @@ void STS_keypad() {
}
}

if (data_count < 19 && data_count >= 3) {
if (setting_mode == 1) {
if (sts_data == password) {
FactorySetting();
}
} else if (setting_mode > 1) {
FactorySetting();
if (data_count < 19 && data_count > 3) {
if (sts_data == password) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("MODE: ");
data_count = 0;
lcd_count = 8;
dt = 0;
}
if (sts_data == "112") {
Mode_select = 1; // For STS Mode (Energy-based)
}

if (sts_data == "122") {
Mode_select = 2; // For OpenPaygo Energy-based
}

if (sts_data == "132") {
Mode_select = 3; // For OpenPaygo Time-based
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions firmware/src/mem_operation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ uint32_t ActiveUntil = 0;
uint32_t TokenEntryLockedUntil = 0;
uint8_t nbDisconnections = 0;

int InvalidTokenCount = 0;

void LoadActivationVariables() {
TokenCount =
mem.readInt(TokenCount_eeprom_location); // We load TokenCount (&
Expand Down
2 changes: 2 additions & 0 deletions firmware/src/opaygo_token.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ extern "C" {
# define TOKEN_LENGTH 9
#endif

int InvalidTokenCount = 0;

bool TokenEntryAllowed() {
if (TokenEntryLockedUntil > GetTimeInSeconds()) {
return false;
Expand Down
3 changes: 0 additions & 3 deletions firmware/src/token_management.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ byte dt = 0;
byte parameters = 0;
byte token_used = 0;
String password = "1234";
String new_password = "1234";

// for meter
unsigned long sts_eeprom_fetched = 0;
Expand All @@ -29,8 +28,6 @@ unsigned long eeprom_location_cnt = 40;
unsigned long sts_value = 0;
unsigned long sts_mode = 0;
unsigned long Mode_select = 0;
unsigned long setting_mode =
0; // when the value is 1 we are in Factory Setting Mode

void check_tokenused() {
token_eeprom_location = mem.readLong(eeprom_location_cnt);
Expand Down