// Send control constants as JSON string. Might contain spaces between minus sign and number. Python will have to strip these void PiLink::sendControlConstants(void){ char tempString[12]; print_P(PSTR("C:{")); sendJsonPair(jsonKeys.tempFormat, tempControl.cc.tempFormat); sendJsonPair(jsonKeys.tempSettingMin, tempToString(tempString, tempControl.cc.tempSettingMin, 1, 12)); sendJsonPair(jsonKeys.tempSettingMax, tempToString(tempString, tempControl.cc.tempSettingMax, 1, 12)); sendJsonPair(jsonKeys.KpHeat, fixedPointToString(tempString, tempControl.cc.KpHeat, 3, 12)); sendJsonPair(jsonKeys.KpCool, fixedPointToString(tempString, tempControl.cc.KpCool, 3, 12)); sendJsonPair(jsonKeys.Ki, fixedPointToString(tempString, tempControl.cc.Ki, 3, 12)); sendJsonPair(jsonKeys.KdCool, fixedPointToString(tempString, tempControl.cc.KdCool, 3, 12)); sendJsonPair(jsonKeys.KdHeat, fixedPointToString(tempString, tempControl.cc.KdHeat, 3, 12)); sendJsonPair(jsonKeys.iMaxError, tempDiffToString(tempString, tempControl.cc.iMaxError, 3, 12)); sendJsonPair(jsonKeys.iMaxSlope, tempDiffToString(tempString, tempControl.cc.iMaxSlope, 3, 12)); sendJsonPair(jsonKeys.iMinSlope, tempDiffToString(tempString, tempControl.cc.iMinSlope, 3, 12)); sendJsonPair(jsonKeys.idleRangeHigh, tempDiffToString(tempString, tempControl.cc.idleRangeHigh, 3, 12)); sendJsonPair(jsonKeys.idleRangeLow, tempDiffToString(tempString, tempControl.cc.idleRangeLow, 3, 12)); sendJsonPair(jsonKeys.heatingTargetUpper, tempDiffToString(tempString, tempControl.cc.heatingTargetUpper, 3, 12)); sendJsonPair(jsonKeys.heatingTargetLower, tempDiffToString(tempString, tempControl.cc.heatingTargetLower, 3, 12)); sendJsonPair(jsonKeys.coolingTargetUpper, tempDiffToString(tempString, tempControl.cc.coolingTargetUpper, 3, 12)); sendJsonPair(jsonKeys.coolingTargetLower, tempDiffToString(tempString, tempControl.cc.coolingTargetLower, 3, 12)); sendJsonPair(jsonKeys.maxHeatTimeForEstimate, tempControl.cc.maxHeatTimeForEstimate); sendJsonPair(jsonKeys.maxCoolTimeForEstimate, tempControl.cc.maxCoolTimeForEstimate); sendJsonPair(jsonKeys.fridgeFastFilter, tempControl.cc.fridgeFastFilter); sendJsonPair(jsonKeys.fridgeSlowFilter, tempControl.cc.fridgeSlowFilter); sendJsonPair(jsonKeys.fridgeSlopeFilter, tempControl.cc.fridgeSlopeFilter); sendJsonPair(jsonKeys.beerFastFilter, tempControl.cc.beerFastFilter); sendJsonPair(jsonKeys.beerSlowFilter, tempControl.cc.beerSlowFilter); // last one 'manually' to have no trailing comma print_P(PSTR("\"%s\":%u}\n"), jsonKeys.beerSlopeFilter, tempControl.cc.beerSlopeFilter); }
/** *Affiche les racines de P */ void print_racines(mpz_t *P, int deg_P, mpz_t mod){ int i, nb_racines=0; mpz_t rac[deg_P+1]; for(i=0; i<deg_P+1; i++){ mpz_init_set_str(rac[i], "-1", 10); } printf("\n\nEtude du Polynome : "); print_P(P, deg_P); racines(rac, P, deg_P,&nb_racines, mod); for(i=0; i<deg_P+1; i++){ if (!mpz_cmp_si(rac[i],-1)){ printf("Polynome : "); print_P(P, deg_P); printf("%d racine(s)\n", nb_racines); return; } printf("%ld est racine\n", mpz_get_si(rac[i])); } printf("Polynome : "); print_P(P, deg_P); printf("%d racines\n", nb_racines); }
//------------------------------------------------------------------------------ void testEnd() { testOut->println(); println_P(testOut, PSTR("Compiled: " __DATE__ " " __TIME__)); print_P(testOut, PSTR("FreeRam: ")); testOut->println(FreeRam()); print_P(testOut, PSTR("Test count: ")); testOut->println(testCount); print_P(testOut, PSTR("Fail count: ")); testOut->println(failCount); }
// Send settings as JSON string void PiLink::sendControlSettings(void){ char tempString[12]; print_P(PSTR("S:{")); sendJsonPair(jsonKeys.mode, tempControl.cs.mode); sendJsonPair(jsonKeys.beerSetting, tempToString(tempString, tempControl.cs.beerSetting, 2, 12)); sendJsonPair(jsonKeys.fridgeSetting, tempToString(tempString, tempControl.cs.fridgeSetting, 2, 12)); sendJsonPair(jsonKeys.heatEstimator, fixedPointToString(tempString, tempControl.cs.heatEstimator, 3, 12)); // last one 'manually' to have no trailing comma print_P(PSTR("\"%s\":%s}\n"), jsonKeys.coolEstimator, fixedPointToString(tempString, tempControl.cs.coolEstimator, 3, 12)); }
size_t RedFlyServer::println_P(PGM_P s) { size_t len; len = print_P(s); if(len) { len += print_P(PSTR("\r\n")); } return len; }
void PiLink::debugMessage(const char * message, ...){ char tempString[128]; // resulting string limited to 128 chars va_list args; //print 'D:' as prefix print_P(PSTR("D:")); // Using print_P for the Annotation fails. Arguments are not passed correctly. Use Serial directly as a work around. va_start (args, message ); vsnprintf_P(tempString, 128, message, args); va_end (args); Serial.print(tempString); print_P(PSTR("\n")); // print newline }
// private int8_t RogueSD::_open(int8_t handle, const char *path, openMode mode, int8_t pgmspc) { int8_t resp; print(_prefix); print('O'); print((char)('0' + handle)); print(' '); switch (mode) { case OPEN_READ: case OPEN_RW: print('R'); if (mode == OPEN_READ) break; case OPEN_WRITE: print('W'); break; case OPEN_APPEND: print('A'); break; } print(' '); if (pgmspc) print_P(path); else print(path); print('\r'); resp = _getResponse(); return resp ? handle : 0; }
// private int8_t RogueSD::_open(int8_t handle, const char *filename, open_mode mode, int8_t pgmspc) { int8_t resp; if (_moduletype != uMMC) { print("FC"); }; print('O'); write('0'+handle); print(' '); switch (mode) { case OPEN_READ: case OPEN_RW: print('R'); if (mode == OPEN_READ) break; case OPEN_WRITE: print('W'); break; case OPEN_APPEND: print('A'); break; } print(' '); if (pgmspc) print_P(filename); else print(filename); print('\r'); resp = _get_response(); return resp < 0 ? resp : handle; }
void div_aux(mpz_t *res_int, mpz_t *P, mpz_t *Q, int deg_P, int deg_Q, mpz_t mod){ printf("entree dans div_aux\n"); int i; mpz_t inverse, S[deg_P+1]; mpz_init(inverse); for(i=0; i<deg_P+1; i++){ mpz_init(S[i]); } printf("fin init S\n"); inverse_modulaire(inverse, Q[0], mod); /* de deg_Q a deg_P, les coeffs sont a 0 */ for(i=0; i<=deg_Q; i++){ mpz_set(S[i], inverse); mpz_mul(S[i], Q[i], S[i]); mpz_mod(S[i], S[i], mod); mpz_mul(S[i], S[i], P[0]); mpz_mod(S[i], S[i], mod); } print_P(S, deg_P); printf("fin remplissage S\n"); /* On remplit res_int */ for(i=1; i<deg_P+1; i++){ mpz_sub(res_int[i], P[i], S[i]); mpz_mod(res_int[i], res_int[i], mod); } printf("fin remplissage res_int\n"); }
static void outputCsv(void) { #ifdef HEATERMETER_SERIAL print_P(PSTR("HMSU" CSV_DELIMITER)); pid.status(); Serial_nl(); #endif /* HEATERMETER_SERIAL */ }
static void reportLidParameters(void) { print_P(PSTR("HMLD" CSV_DELIMITER)); SerialX.print(pid.LidOpenOffset, DEC); Serial_csv(); SerialX.print(pid.getLidOpenDuration(), DEC); Serial_nl(); }
void PiLink::receive(void){ if (Serial.available() > 0){ char inByte = Serial.read(); switch(inByte){ case 't': // temperatures requested printTemperatures(); break; case 'C': // Set default constants tempControl.loadDefaultConstants(); display.printStationaryText(); // reprint stationary text to update to right degree unit sendControlConstants(); // update script with new settings debugMessage(PSTR("Default constants loaded.")); break; case 'S': // Set default settings tempControl.loadDefaultSettings(); sendControlSettings(); // update script with new settings debugMessage(PSTR("Default settings loaded.")); break; case 's': // Control settings requested sendControlSettings(); break; case 'c': // Control constants requested sendControlConstants(); break; case 'v': // Control variables requested sendControlVariables(); break; case 'l': // Display content requested print_P(PSTR("L:")); char stringBuffer[21]; for(uint8_t i=0;i<4;i++){ display.lcd.getLine(i, stringBuffer); print_P(PSTR("%s<BR>"), stringBuffer); } print_P(PSTR("\n")); break; case 'j': // Receive settings as json receiveJson(); break; default: debugMessage(PSTR("Invalid command Received by Arduino: %c"), inByte); } //Serial.flush(); Messages can be back to back. Flush should not be necessary. // Functions should not read more than what is meant for that function. } }
// Send all control variables. Useful for debugging and choosing parameters void PiLink::sendControlVariables(void){ char tempString[12]; print_P(PSTR("V:{")); sendJsonPair(jsonKeys.beerDiff, tempDiffToString(tempString, tempControl.cv.beerDiff, 3, 12)); sendJsonPair(jsonKeys.diffIntegral, tempDiffToString(tempString, tempControl.cv.diffIntegral, 3, 12)); sendJsonPair(jsonKeys.beerSlope, tempDiffToString(tempString, tempControl.cv.beerSlope, 3, 12)); sendJsonPair(jsonKeys.p, fixedPointToString(tempString, tempControl.cv.p, 3, 12)); sendJsonPair(jsonKeys.i, fixedPointToString(tempString, tempControl.cv.i, 3, 12)); sendJsonPair(jsonKeys.d, fixedPointToString(tempString, tempControl.cv.d, 3, 12)); sendJsonPair(jsonKeys.Kp, fixedPointToString(tempString, tempControl.cv.Kp, 3, 12)); sendJsonPair(jsonKeys.Kd, fixedPointToString(tempString, tempControl.cv.Kd, 3, 12)); sendJsonPair(jsonKeys.estimatedPeak, tempToString(tempString, tempControl.cv.estimatedPeak, 3, 12)); sendJsonPair(jsonKeys.negPeakSetting, tempToString(tempString, tempControl.cv.negPeakSetting, 3, 12)); sendJsonPair(jsonKeys.posPeakSetting, tempToString(tempString, tempControl.cv.posPeakSetting, 3, 12)); sendJsonPair(jsonKeys.negPeak, tempToString(tempString, tempControl.cv.negPeak, 3, 12)); print_P(PSTR("\"%s\":%s}\n"), jsonKeys.posPeak, tempToString(tempString, tempControl.cv.posPeak, 3, 12)); }
void SerialUI::showFreeRAM() { extern int __heap_start, *__brkval; int v; print_P(PSTR("Free RAM: ")); println(freeRAM()); }
void PiLink::printJsonName(const char * name) { printJsonSeparator(); piStream.print('"'); print_P(name); piStream.print('"'); piStream.print(':'); }
//------------------------------------------------------------------------------ void testVerify_P(char* result, PGM_P expect) { testOut->write('"'); testOut->print(result); testOut->print("\",\""); print_P(testOut, expect); testOut->write('"'); uint8_t n = strlen(result) + strlen_P(expect) + 5; testResult(!strcmp_P(result, expect), n); }
void SerialOutput::printFloat(double number, uint8_t digits) { if (isnan(number)) { print_P(PSTR("NAN")); return; } if (isinf(number)) { print_P(PSTR("INF")); return; } // Handle negative numbers if (number < 0.0) { write('-'); number = -number; } // Round correctly so that print(1.999, 2) prints as "2.00" double rounding = 0.5; for (uint8_t i=0; i<digits; ++i) rounding /= 10.0; number += rounding; // Extract the integer part of the number and print it unsigned long int_part = (unsigned long)number; double remainder = number - (double)int_part; print(int_part); // Print the decimal point, but only if there are digits beyond if (digits > 0) write('.'); // Extract digits from the remainder one at a time while (digits-- > 0) { remainder *= 10.0; int toPrint = int(remainder); print(toPrint); remainder -= toPrint; } }
bool Trace::begin(IOStream::Device* dev, const char* banner) { set_device(dev); if (banner != NULL) { print_P(banner); println(); } return (true); }
void GuiPainter::text_P(const char * msg) { if ( (msg != NULL) && (strlen_P(msg) > 0) ) { setColorIndex(1); setFont(FontType_t::BODY_FONT); setPrintPos(m_working_area.x_init + (m_working_area.width() - strlen_P(msg) * max_font_width) / 2, m_working_area.y_init); print_P(msg); } }
static void reportProbeOffsets(void) { print_P(PSTR("HMPO")); for (unsigned char i=0; i<TEMP_COUNT; ++i) { Serial_csv(); SerialX.print(pid.Probes[i]->Offset, DEC); } Serial_nl(); }
//------------------------------------------------------------------------------ void testBegin(Print* pr) { testOut = pr; SerialPrintln_P(PSTR("Type any character to begin.")); while (!Serial.available()); print_P(testOut, PSTR("FreeRam: ")); testOut->println(FreeRam()); testOut->println(); failCount = 0; testCount = 0; }
static void reportPidParams(void) { print_P(PSTR("HMPD")); for (unsigned char i=0; i<4; ++i) { Serial_csv(); //printSciFloat(pid.Pid[i]); SerialX.print(pid.Pid[i], 8); } Serial_nl(); }
static void reportProbeNames(void) { print_P(PSTR("HMPN")); for (unsigned char i=0; i<TEMP_COUNT; ++i) { loadProbeName(i); Serial_csv(); SerialX.print(editString); } Serial_nl(); }
static void reportRfMap(void) { print_P(PSTR("HMRM")); for (unsigned char i=0; i<TEMP_COUNT; ++i) { Serial_csv(); if (pid.Probes[i]->getProbeType() == PROBETYPE_RF12) SerialX.print(rfMap[i], DEC); } Serial_nl(); }
void ProgramData::createName(int index) { char *buf = name; uint8_t maxSize = PROGRAM_DATA_MAX_NAME; const char * type = pgm::read(&batteryString[battery.type]); printIndex(buf,maxSize, index); print_P (buf, maxSize, type); printChar(buf, maxSize, ' '); printUInt(buf, maxSize, battery.C); printChar(buf, maxSize, '/'); printUInt(buf, maxSize, battery.cells); }
static void outputAdcStatus(void) { #if defined(HEATERMETER_SERIAL) print_P(PSTR("HMAR")); for (unsigned char i=0; i<NUM_ANALOG_INPUTS; ++i) { Serial_csv(); SerialX.print(analogReadRange(i), DEC); } Serial_nl(); #endif }
void reportLcdParameters(void) { print_P(PSTR("HMLB" CSV_DELIMITER)); SerialX.print(g_LcdBacklight, DEC); Serial_csv(); SerialX.print(g_HomeDisplayMode, DEC); for (unsigned char i=0; i<LED_COUNT; ++i) { Serial_csv(); SerialX.print(ledmanager.getAssignment(i), DEC); } Serial_nl(); }
static void reportFanParams(void) { print_P(PSTR("HMFN" CSV_DELIMITER)); SerialX.print(pid.getMinFanSpeed(), DEC); Serial_csv(); SerialX.print(pid.getMaxFanSpeed(), DEC); Serial_csv(); SerialX.print(pid.getMinServoPos(), DEC); Serial_csv(); SerialX.print(pid.getMaxServoPos(), DEC); Serial_csv(); SerialX.print(pid.getOutputFlags(), DEC); Serial_nl(); }
//------------------------------------------------------------------------------ void testBegin() { Serial.begin(9600); while (!Serial) {} // wait for leonardo testOut = &Serial; SerialPrintln_P(PSTR("Type any character to begin.")); while (Serial.read() <= 0) {} delay(200); // Catch Due reset problem print_P(testOut, PSTR("FreeRam: ")); testOut->println(FreeRam()); testOut->println(); failCount = 0; testCount = 0; }
void SerialUI::showEnterDataPrompt() { #ifdef SUI_ENABLE_MODES if (mode() == SUIMode_Program) { println_P(moredata_prompt_prog_str); println_P(end_of_tx_str); return; } #endif print_P(moredata_prompt_str); }