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

in progress kibbles detect threshold #14

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion examples/main/particle-test-local.ino
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ void loop() {

lastmemcheck = millis();

Serial.printlnf("\hackerpet_plus 0.1.111; MILLIS: %lu\tSYSTEM MEMORY=%lu", lastmemcheck, FREE_MEMORY);
Serial.printlnf("\hackerpet_plus 0.1.112; MILLIS: %lu\tSYSTEM MEMORY=%lu", lastmemcheck, FREE_MEMORY);

}
}
6 changes: 3 additions & 3 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name=hackerpet_plus
version=0.1.111
version=0.1.112
license=AGPL
author=Csaba Petre <[email protected]>
maintainer=Csaba Petre <[email protected]>
sentence=(Alpha Version!) Long-term cloud-less firmware!
sentence=(Dev Version!) Long-term cloud-less firmware!
category=Other
url=http://hackerpet.com
repository=https://github.com/CleverPet/hackerpet_plus/
architectures=particle-photon
dependencies.hackerpet=0.2.6
dependencies.hackerpet=0.2.7
34 changes: 31 additions & 3 deletions src/config-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ bool ConfigManager::Initialize()

EEPROM.get(_KIBBLES_LIMIT_ADDRESS, _kibbles_limit);

EEPROM.get(_FOODTREAT_THRESH_ADDRESS, _foodtreat_detect_thresh);

_last_hub_mode = _hub_mode;

}
Expand Down Expand Up @@ -143,11 +145,15 @@ bool ConfigManager::Initialize()
_kibbles_limit = 0;
EEPROM.put(_KIBBLES_LIMIT_ADDRESS, _kibbles_limit);

_foodtreat_detect_thresh = 60; // 40 for empty dish fix
EEPROM.put(_FOODTREAT_THRESH_ADDRESS, _foodtreat_detect_thresh);
}

// to force initialization to a valid _hub_state in Run()
_hub_state = _HUB_STATE_INIT;

_hub->SetFoodTreatDetectThresh(_foodtreat_detect_thresh);

mgschwan_mdns = new MDNS;

return true;
Expand Down Expand Up @@ -645,6 +651,7 @@ bool ConfigManager::_process_api_get_req(String req_str)
"\"hub_state\":\"" + hub_state_str + "\","
"\"time\":\"" + Time.timeStr() + "\","
"\"max_kibbles\":\"" + int_to_string(_kibbles_limit) + "\","
"\"kibthresh\":\"" + int_to_string(_foodtreat_detect_thresh) + "\","
"\"kibbles_eaten_today\":\"" + int_to_string(_kibbles_eaten_today) + "\""
"}";
_webclient.println(return_str);
Expand Down Expand Up @@ -823,10 +830,31 @@ bool ConfigManager::_process_set_max_kibbles_req(String req_str)
bool ConfigManager::_process_set_kibbles_thresh_req(String req_str)
{

// TODO is there abranch where we have eeprom etc. stuff for this already coded?
// yes:
// https://github.com/CleverPet/hackerpet_plus/pull/7/files
// TODO FINISH

// TODO NEEDS TESTING
String thresh_str = req_str.substring(req_str.indexOf("kibbles_thresh\"") + 16);
int index_stop = thresh_str.indexOf("}"); // TODO is this correct?
thresh_str = thresh_str.substring(0, index_stop);

int thresh = thresh_str.toInt();

Serial.println("New threshold set for kibbles detect:");
Serial.println(int_to_string(thresh));
Serial.println("");

_foodtreat_detect_thresh = thresh;

_hub->SetFoodTreatDetectThresh(_foodtreat_detect_thresh);

EEPROM.put(_FOODTREAT_THRESH_ADDRESS, _foodtreat_detect_thresh);

String return_str = "HTTP/1.1 200 OK\r\nConnection: Closed\r\n\r\n"
"{}";
Log.info("sending back: string:");
Log.print(return_str);
_webclient.println(return_str);

return true;
}

Expand Down
7 changes: 5 additions & 2 deletions src/config-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ class ConfigManager
const int _SCHED_WEEKEND_FROM_ADDRESS = 260;
const int _SCHED_WEEKEND_TO_ADDRESS = 360;
const int _KIBBLES_LIMIT_ADDRESS = 460;

const int _FOODTREAT_THRESH_ADDRESS = 560;

// ***************** const other *****************

// we can change this number to force an eeprom "reset" to defaults; and to avoid undefined state when adding new variables
const int _EVER_STORED_CHECK_VALUE = 12357; // EVER_STORED_CHECK_VALUE = 12346;
const int _EVER_STORED_CHECK_VALUE = 12358; // EVER_STORED_CHECK_VALUE = 12346;

const int _HUB_MODE_STAY_OFF = 0;
const int _HUB_MODE_STAY_ON = 1;
Expand Down Expand Up @@ -102,6 +103,8 @@ class ConfigManager
int _kibbles_limit;
int _kibbles_eaten_today;

int _foodtreat_detect_thresh;

int _last_day;

unsigned long _last_mdns_reconnect_attempt;
Expand Down
Loading