Skip to content

Commit

Permalink
rename USER_PRINTF and prf to ppf (print->printf)
Browse files Browse the repository at this point in the history
  • Loading branch information
ewoudwijma committed Apr 18, 2024
1 parent 956cd9f commit d33ee8e
Show file tree
Hide file tree
Showing 19 changed files with 199 additions and 200 deletions.
2 changes: 1 addition & 1 deletion src/App/AppModDemo.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class AppModDemo: public SysModule {
// SysModule::loop();
if (blinkPin != UINT16_MAX && millis() - lastMillis >= frequency) {
lastMillis = millis();
// USER_PRINTF(" %d: %d", blinkPin, digitalRead(blinkPin));
// ppf(" %d: %d", blinkPin, digitalRead(blinkPin));
int value = digitalRead(blinkPin);
digitalWrite(blinkPin, value == LOW?HIGH:LOW);
}
Expand Down
18 changes: 9 additions & 9 deletions src/Sys/SysModFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

SysModFiles::SysModFiles() :SysModule("Files") {
if (!LittleFS.begin(true)) { //true: formatOnFail
USER_PRINTF(" An Error has occurred while mounting File system");
USER_PRINTF(" fail\n");
ppf(" An Error has occurred while mounting File system");
ppf(" fail\n");
success = false;
}
};
Expand All @@ -43,7 +43,7 @@ void SysModFiles::setup() {
case f_DelRow:
if (rowNr != UINT8_MAX && rowNr < fileList.size()) {
const char * fileName = fileList[rowNr].name;
USER_PRINTF("chFun delRow %s[%d] = %s %s\n", mdl->varID(var), rowNr, var["value"].as<String>().c_str(), fileName);
ppf("chFun delRow %s[%d] = %s %s\n", mdl->varID(var), rowNr, var["value"].as<String>().c_str(), fileName);
this->removeFiles(fileName, false);
}
print->printJson(" ", var);
Expand Down Expand Up @@ -142,7 +142,7 @@ void SysModFiles::loop10s() {
}

bool SysModFiles::remove(const char * path) {
USER_PRINTF("File remove %s\n", path);
ppf("File remove %s\n", path);
return LittleFS.remove(path);
filesChanged = true;
}
Expand Down Expand Up @@ -178,7 +178,7 @@ void SysModFiles::dirToJson(JsonArray array, bool nameOnly, const char * filter)
strncat(urlString, file.name(), sizeof(urlString)-1);
row.add(JsonString(urlString, JsonString::Copied));
}
// USER_PRINTF("FILE: %s %d\n", file.name(), file.size());
// ppf("FILE: %s %d\n", file.name(), file.size());
}

file.close();
Expand All @@ -196,7 +196,7 @@ bool SysModFiles::seqNrToName(char * fileName, size_t seqNr) {
size_t counter = 0;
while (file) {
if (counter == seqNr) {
// USER_PRINTF("seqNrToName: %d %s %d\n", seqNr, file.name(), file.size());
// ppf("seqNrToName: %d %s %d\n", seqNr, file.name(), file.size());
root.close();
strncat(fileName, "/", 31); //add root prefix, fileName is 32 bytes but sizeof doesn't know so cheating
strncat(fileName, file.name(), 31);
Expand All @@ -217,15 +217,15 @@ bool SysModFiles::readObjectFromFile(const char* path, JsonDocument* dest) {
// if (doCloseFile) closeFile();
File f = open(path, "r");
if (!f) {
USER_PRINTF("File %s open not successful\n", path);
ppf("File %s open not successful\n", path);
return false;
}
else {
USER_PRINTF("File %s open to read, size %d bytes\n", path, (int)f.size());
ppf("File %s open to read, size %d bytes\n", path, (int)f.size());
DeserializationError error = deserializeJson(*dest, f, DeserializationOption::NestingLimit(20)); //StarMod requires more then 10
if (error) {
print->printJDocInfo("readObjectFromFile", *dest);
USER_PRINTF("readObjectFromFile deserializeJson failed with code %s\n", error.c_str());
ppf("readObjectFromFile deserializeJson failed with code %s\n", error.c_str());
f.close();
return false;
} else {
Expand Down
12 changes: 6 additions & 6 deletions src/Sys/SysModModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ SysModModel::SysModModel() :SysModule("Model") {

JsonArray root = model->to<JsonArray>(); //create

USER_PRINTF("Reading model from /model.json... (deserializeConfigFromFS)\n");
ppf("Reading model from /model.json... (deserializeConfigFromFS)\n");
if (files->readObjectFromFile("/model.json", model)) {//not part of success...
// print->printJson("Read model", *model);
// web->sendDataWs(*model);
Expand Down Expand Up @@ -82,7 +82,7 @@ void SysModModel::setup() {
}

if (doWriteModel) {
USER_PRINTF("Writing model to /model.json... (serializeConfig)\n");
ppf("Writing model to /model.json... (serializeConfig)\n");

// files->writeObjectToFile("/model.json", model);

Expand Down Expand Up @@ -118,7 +118,7 @@ void SysModModel::cleanUpModel(JsonObject parent, bool oPos, bool ro) {
if (oPos) {
if (var["o"].isNull() || varOrder(var) >= 0) { //not set negative in initVar
if (!doShowObsolete) {
USER_PRINTF("cleanUpModel remove var %s (""o"">=0)\n", varID(var));
ppf("cleanUpModel remove var %s (""o"">=0)\n", varID(var));
vars.remove(varV); //remove the obsolete var (no o or )
}
}
Expand All @@ -127,7 +127,7 @@ void SysModModel::cleanUpModel(JsonObject parent, bool oPos, bool ro) {
}
} else { //!oPos
if (var["o"].isNull() || varOrder(var) < 0) {
USER_PRINTF("cleanUpModel remove var %s (""o""<0)\n", varID(var));
ppf("cleanUpModel remove var %s (""o""<0)\n", varID(var));
vars.remove(varV); //remove the obsolete var (no o or o is negative - not cleanedUp)
}
}
Expand All @@ -136,7 +136,7 @@ void SysModModel::cleanUpModel(JsonObject parent, bool oPos, bool ro) {
//remove ro values (ro vars cannot be deleted as SM uses these vars)
// remove if var is ro or table is instance table (exception here, values don't need to be saved)
if (ro && (parent["id"] == "insTbl" || varRO(var))) {// && !var["value"].isNull())
USER_PRINTF("remove ro value %s\n", varID(var));
ppf("remove ro value %s\n", varID(var));
var.remove("value");
}

Expand Down Expand Up @@ -165,7 +165,7 @@ JsonObject SysModModel::findVar(const char * id, JsonArray parent) {
JsonObject foundVar = findVar(id, var["n"]);
if (!foundVar.isNull()) {
if (modelParentVar.isNull()) modelParentVar = var; //only recursive lowest assigns parentVar
// USER_PRINTF("findvar parent of %s is %s\n", id, varID(modelParentVar));
// ppf("findvar parent of %s is %s\n", id, varID(modelParentVar));
return foundVar;
}
}
Expand Down
44 changes: 22 additions & 22 deletions src/Sys/SysModModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct Coord3D {

//comparisons
bool operator!=(Coord3D rhs) {
// USER_PRINTF("Coord3D compare%d %d %d %d %d %d\n", x, y, z, rhs.x, rhs.y, rhs.z);
// ppf("Coord3D compare%d %d %d %d %d %d\n", x, y, z, rhs.x, rhs.y, rhs.z);
// return x != rhs.x || y != rhs.y || z != rhs.z;
return !(*this==rhs);
}
Expand All @@ -58,7 +58,7 @@ struct Coord3D {

//assignments
Coord3D operator=(Coord3D rhs) {
// USER_PRINTF("Coord3D assign %d,%d,%d\n", rhs.x, rhs.y, rhs.z);
// ppf("Coord3D assign %d,%d,%d\n", rhs.x, rhs.y, rhs.z);
x = rhs.x;
y = rhs.y;
z = rhs.z;
Expand Down Expand Up @@ -136,12 +136,12 @@ namespace ArduinoJson {
dst["x"] = src.x;
dst["y"] = src.y;
dst["z"] = src.z;
// USER_PRINTF("Coord3D toJson %d,%d,%d -> %s\n", src.x, src.y, src.z, dst.as<String>().c_str());
// ppf("Coord3D toJson %d,%d,%d -> %s\n", src.x, src.y, src.z, dst.as<String>().c_str());
return true;
}

static Coord3D fromJson(JsonVariantConst src) {
// USER_PRINTF("Coord3D fromJson %s\n", src.as<String>().c_str());
// ppf("Coord3D fromJson %s\n", src.as<String>().c_str());
return Coord3D{src["x"], src["y"], src["z"]};
}

Expand Down Expand Up @@ -200,7 +200,7 @@ class SysModModel:public SysModule {
return setValue(var, value, rowNr);
}
else {
USER_PRINTF("setValue Var %s not found\n", id);
ppf("setValue Var %s not found\n", id);
return JsonObject();
}
}
Expand All @@ -217,14 +217,14 @@ class SysModModel:public SysModule {
//trick to remove null values
if (var["value"].isNull() || var["value"].as<unsigned16>() == UINT16_MAX) {
var.remove("value");
USER_PRINTF("dev setValue value removed %s %s\n", varID(var), var["oldValue"].as<String>().c_str());
ppf("dev setValue value removed %s %s\n", varID(var), var["oldValue"].as<String>().c_str());
}
else {
//only print if ! read only
if (!varRO(var))
USER_PRINTF("setValue changed %s %s -> %s\n", varID(var), var["oldValue"].as<String>().c_str(), var["value"].as<String>().c_str());
ppf("setValue changed %s %s -> %s\n", varID(var), var["oldValue"].as<String>().c_str(), var["value"].as<String>().c_str());
// else
// USER_PRINTF("setValue changed %s %s\n", varID(var), var["value"].as<String>().c_str());
// ppf("setValue changed %s %s\n", varID(var), var["value"].as<String>().c_str());
web->addResponse(var["id"], "value", var["value"]);
changed = true;
}
Expand All @@ -234,7 +234,7 @@ class SysModModel:public SysModule {
//if we deal with multiple rows, value should be an array, if not we create one

if (var["value"].isNull() || !var["value"].is<JsonArray>()) {
// USER_PRINTF("setValue var %s[%d] value %s not array, creating\n", varID(var), rowNr, var["value"].as<String>().c_str());
// ppf("setValue var %s[%d] value %s not array, creating\n", varID(var), rowNr, var["value"].as<String>().c_str());
var["value"].to<JsonArray>();
}

Expand All @@ -248,15 +248,15 @@ class SysModModel:public SysModule {

if (notSame) {
// if (rowNr >= valueArray.size())
// USER_PRINTF("notSame %d %d\n", rowNr, valueArray.size());
// ppf("notSame %d %d\n", rowNr, valueArray.size());
valueArray[rowNr] = value; //if valueArray[<rowNr] not exists it will be created
// USER_PRINTF(" assigned %d %d %s\n", rowNr, valueArray.size(), valueArray[rowNr].as<String>().c_str());
// ppf(" assigned %d %d %s\n", rowNr, valueArray.size(), valueArray[rowNr].as<String>().c_str());
web->addResponse(var["id"], "value", var["value"]); //send the whole array to UI as response is in format value:<value> !!
changed = true;
}
}
else {
USER_PRINTF("setValue %s could not create value array\n", varID(var));
ppf("setValue %s could not create value array\n", varID(var));
}
}

Expand All @@ -275,7 +275,7 @@ class SysModModel:public SysModule {

va_end(args);

USER_PRINTF("setValueV %s[%d] = %s\n", id, rowNr, value);
ppf("setValueV %s[%d] = %s\n", id, rowNr, value);
return setValue(id, JsonString(value, JsonString::Copied), rowNr);
}

Expand All @@ -298,7 +298,7 @@ class SysModModel:public SysModule {
return getValue(var, rowNr);
}
else {
// USER_PRINTF("getValue: Var %s does not exist!!\n", id);
// ppf("getValue: Var %s does not exist!!\n", id);
return JsonVariant();
}
}
Expand All @@ -311,7 +311,7 @@ class SysModModel:public SysModule {
else if (valueArray.size())
return valueArray[0]; //return the first element
else {
USER_PRINTF("dev getValue no array or rownr wrong %s %s %d\n", varID(var), var["value"].as<String>().c_str(), rowNr);
ppf("dev getValue no array or rownr wrong %s %s %d\n", varID(var), var["value"].as<String>().c_str(), rowNr);
return JsonVariant(); // return null
}
}
Expand Down Expand Up @@ -375,19 +375,19 @@ class SysModModel:public SysModule {
}
}
setValueRowNr = rowNr;
USER_PRINTF("varPreDetails post ");
ppf("varPreDetails post ");
print->printVar(var);
USER_PRINTF("\n");
ppf("\n");
}

void varPostDetails(JsonObject var, unsigned8 rowNr) {

setValueRowNr = UINT8_MAX;
if (rowNr != UINT8_MAX) {

USER_PRINTF("varPostDetails pre ");
ppf("varPostDetails pre ");
print->printVar(var);
USER_PRINTF("\n");
ppf("\n");

//check if post init added: parent is already >=0
if (varOrder(var) >= 0) {
Expand All @@ -399,7 +399,7 @@ class SysModModel:public SysModule {
if (varOrder(childVar) < 0) { //if not updated
valArray[rowNr] = (char*)0; // set element in valArray to 0

USER_PRINTF("varPostDetails %s.%s[%d] <- null\n", varID(var), varID(childVar), rowNr);
ppf("varPostDetails %s.%s[%d] <- null\n", varID(var), varID(childVar), rowNr);
// setValue(var, -99, rowNr); //set value -99
varOrder(childVar, -varOrder(childVar)); //make positive again
//if some values in array are not -99
Expand All @@ -423,9 +423,9 @@ class SysModModel:public SysModule {

}
} //if new added
USER_PRINTF("varPostDetails post ");
ppf("varPostDetails post ");
print->printVar(var);
USER_PRINTF("\n");
ppf("\n");

web->addResponse("details", "rowNr", rowNr);
}
Expand Down
18 changes: 9 additions & 9 deletions src/Sys/SysModNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void SysModNetwork::loop1s() {

void SysModNetwork::handleConnection() {
if (lastReconnectAttempt == 0) { // do this only once
USER_PRINTF("lastReconnectAttempt == 0\n");
ppf("lastReconnectAttempt == 0\n");
initConnection();
return;
}
Expand All @@ -85,18 +85,18 @@ void SysModNetwork::handleConnection() {
//if not connected to Wifi
if (!(WiFi.localIP()[0] != 0 && WiFi.status() == WL_CONNECTED)) { //!Network.isConfirmedConnection()
if (isConfirmedConnection) { //should not be confirmed as not connected -> lost connection -> retry
USER_PRINTF("Disconnected!\n");
ppf("Disconnected!\n");
initConnection();
}

//if no connection for more then 6 seconds (was 12)
if (!apActive && millis() - lastReconnectAttempt > 6000 ) { //&& (!wasConnected || apBehavior == AP_BEHAVIOR_NO_CONN)
USER_PRINTF("Not connected AP.\n");
ppf("Not connected AP.\n");
initAP();
}
} else if (!isConfirmedConnection) { //newly connected
mdl->setUIValueV("nwstatus", "Connected %d.%d.%d.%d", WiFi.localIP()[0], WiFi.localIP()[1], WiFi.localIP()[2], WiFi.localIP()[3]);
USER_PRINTF("Connected %s\n", WiFi.localIP().toString().c_str());
ppf("Connected %s\n", WiFi.localIP().toString().c_str());

isConfirmedConnection = true;

Expand Down Expand Up @@ -126,7 +126,7 @@ void SysModNetwork::initConnection() {
if (ssid && strlen(ssid)>0) {
char passXXX [32] = "";
for (int i = 0; i < strlen(password); i++) strncat(passXXX, "*", sizeof(passXXX)-1);
USER_PRINTF("Connecting to WiFi %s / %s\n", ssid, passXXX);
ppf("Connecting to WiFi %s / %s\n", ssid, passXXX);
WiFi.begin(ssid, password);
#if defined(STARMOD_LOLIN_WIFI_FIX )
WiFi.setTxPower(WIFI_POWER_8_5dBm );
Expand All @@ -135,14 +135,14 @@ void SysModNetwork::initConnection() {
WiFi.setHostname(mdns->cmDNS); //use the mdns name (instance name or star-mac)
}
else
USER_PRINTF("No SSID");
ppf("No SSID");

isConfirmedConnection = false; //need to test if really connected in handleConnection
}

void SysModNetwork::initAP() {
const char * apSSID = mdl->getValue("instanceName");
USER_PRINTF("Opening access point %s\n", apSSID);
ppf("Opening access point %s\n", apSSID);
WiFi.softAPConfig(IPAddress(4, 3, 2, 1), IPAddress(4, 3, 2, 1), IPAddress(255, 255, 255, 0));
WiFi.softAP(apSSID, NULL, apChannel, false); //no password!!!
#if defined(STARMOD_LOLIN_WIFI_FIX )
Expand All @@ -165,7 +165,7 @@ void SysModNetwork::stopAP() {
dnsServer.stop();
WiFi.softAPdisconnect(true);
apActive = false;
USER_PRINTF("Access point disabled (handle).\n");
ppf("Access point disabled (handle).\n");
}

void SysModNetwork::handleAP() {
Expand All @@ -176,7 +176,7 @@ void SysModNetwork::handleAP() {
if (stac != stacO) {
stacO = stac;
if (WiFi.status() != WL_CONNECTED) {
USER_PRINTF("Connected AP clients: %d %d\n", stac, WiFi.status());
ppf("Connected AP clients: %d %d\n", stac, WiFi.status());
if (stac)
WiFi.disconnect(); // disable search so that AP can work
else
Expand Down
Loading

0 comments on commit d33ee8e

Please sign in to comment.