本文整理汇总了C++中dtostrf函数的典型用法代码示例。如果您正苦于以下问题:C++ dtostrf函数的具体用法?C++ dtostrf怎么用?C++ dtostrf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dtostrf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dtostrf
// [ID, PIN, VALUE, TARGET, SENSOR?, TYPE]
int Device::toString(Print* conn){
char v_str[6];
/* 4 is mininum width, 2 is precision; float value is copied onto str_temp*/
dtostrf(getValue(), 4, 2, v_str);
conn->print('[');
#if(ENABLE_PREFIX_NAME)
if(type != Device::BOARD){
conn->print(od::Config.moduleName);
conn->print("::");
}
#endif
conn->print(deviceName);
conn->print(',');
conn->print(id);
conn->print(',');
conn->print(pin);
conn->print(',');
conn->print(v_str);
conn->print(',');
conn->print(targetID);
conn->print(',');
conn->print((sensor ? 1 : 0));
conn->print(',');
conn->print((int)type);
conn->print(']');
// int size = sprintf (buffer, "[%s,%d,%d,%s,%d,%d,%d]",
// (name != NULL ? name : ""),
// id, pin, v_str, targetID, (sensor ? 1 : 0), itype);
// Serial.print(">>>>>> Device :");
// Serial.println(buffer);
return 0;
}
示例2: strcat
/***********************************************************
*
* fractionToString
*
*
*
***********************************************************/
void BulbRamp::fractionToString(int optionConst, int fraction, char buffer[])
{
//output to result to buffer
char tempBuffer[5];
buffer[0] = 0;
if(option(optionConst) < 1000)
{
strcat(buffer,"1/");
utoa(fraction,tempBuffer,10);
strcat(buffer,tempBuffer);
strcat(buffer,"sec");
strcat(buffer,'\0');
}
else if(option(optionConst) <= 60000)
{
float secf = (float) option(optionConst)/1000; //set from EndExposure or Start
dtostrf(secf, 3, 1, tempBuffer); //avr lib float to str
strcat(buffer,tempBuffer);
strcat(buffer,"sec");
strcat(buffer,'\0');
}
}
示例3: loop
void loop() {
if (Serial.available()) {
int value = Serial.parseInt();
// Sometime we see a garbage number, so restrict to a lower number
if(value > 100) {
value = 5;
}
blink(value);
}
strcpy(deviceEvent, "");
char val[10];
strcat(deviceEvent,"status temp:");
dtostrf(getTemp(),1,2, val);
strcat(deviceEvent,val);
strcat(deviceEvent,",pir:");
int buttonState = digitalRead(PIRPIN);
itoa(buttonState, val, 10);
strcat(deviceEvent,val);
Serial.println(deviceEvent);
delay(100);
}
示例4: dtostrf
void DAQ::handleValue(float value){
// Handle averaging if used...
_averagingSum += value;
_dataCount++;
if(_dataCount == _averageCount){
if(_valueHandler){
float value = _averagingSum / _dataCount;
// Don't send same val...! :O(
// TODO - Use hysteresis.
//if(value != _lastValue){
if((value < (_lastValue - _hysteresis)) || (value > (_lastValue + _hysteresis))){
char buf[20];
dtostrf(value, 0, _precision, buf);
_valueHandler(buf);
_lastValue = atof(buf);
}
}
_dataCount = 0;
_averagingSum = 0;
}
}
示例5: dump_fastlog
void dump_fastlog( void )
{
extern unsigned char top_ret;
extern unsigned char bot_ret;
newline();
if(variables.current_cyl_idx < cfg.num_cyls &&
variables.lastknock_tpfd[variables.current_cyl_idx] < 1500 &&
variables.lastknock_tpfd[variables.current_cyl_idx] )
{
snprintf(output, OUTPUT_LEN, "%05lu", TICKS_PER_MIN/((unsigned long int) variables.lastknock_tpfd[variables.current_cyl_idx] *90));
print_str(output);
seperator();
snprintf(output, OUTPUT_LEN, "%u", cfg.firing_order[variables.current_cyl_idx]);
}
else
{
snprintf(output, OUTPUT_LEN, "00000");
print_str(output);
seperator();
snprintf(output, OUTPUT_LEN, "0");
}
print_str(output);
seperator();
dtostrf( (float) (variables.lastknock_volts[variables.current_cyl_idx] * TEN_BIT_LSB), 5, 3, output);
print_str(output);
seperator();
snprintf(output, OUTPUT_LEN, "%u - %02X - %02X ", variables.rknock, top_ret, bot_ret);
print_str(output);
return;
}
示例6: stroke
/**
* Paint the BarGraph
*/
void BarGraph::paint(void) {
char outStr[25];
char outValueStr[6];
//draw bargraph Background and outine
stroke(fgColorR,
fgColorG,
fgColorB);
fill(bgColorR,
bgColorG,
bgColorB);
rect(xLocation,
yLocation,
graphWidth,
graphHeight);
//draw the bargraph label and value
dtostrf(currValue, 5, 1, outValueStr);
sprintf(outStr,"%s %s", graphLabel, outValueStr);
text(outStr,
xLocation,
yLocation-10);
//draw the bar
noStroke();
fill(fgColorR,
fgColorG,
fgColorB);
rect(xLocation,
yLocation,
valueClamped * ((float)graphWidth / (maxValue - minValue)),
graphHeight);
}
示例7: dtostrf
void Gauchito::sendData() {
dtostrf(irs[0]->readInCentimeters(), 0, 2, gData.dataset[0].value);
dtostrf(irs[1]->readInCentimeters(), 0, 2, gData.dataset[1].value);
dtostrf(irs[2]->readInCentimeters(), 0, 2, gData.dataset[2].value);
dtostrf(irs[3]->readInCentimeters(), 0, 2, gData.dataset[3].value);
dtostrf(irs[4]->readInCentimeters(), 0, 2, gData.dataset[4].value);
dtostrf(ultrasonic->readInCentimeters(), 0, 2, gData.dataset[5].value);
/*
Serial.print("IR_01 "); Serial.println(gData.dataset[0].value);
Serial.print("IR_02 "); Serial.println(gData.dataset[1].value);
Serial.print("IR_03 "); Serial.println(gData.dataset[2].value);
Serial.print("IR_04 "); Serial.println(gData.dataset[3].value);
Serial.print("IR_05 "); Serial.println(gData.dataset[4].value);
Serial.print("ULTRASSOM "); Serial.println(gData.dataset[5].value);
*/
}
示例8: String
//call to display detailed position information on the debug port.
void AsiMS2000::displayCurrentToDesired(char message[])
{
char buffer[20];
String reply = String(message);
AxisSettingsF a = AsiSettings.currentPos;
AxisSettingsF d = AsiSettings.desiredPos;
dtostrf(a.x,1,4,buffer);
reply.concat(" " + String(buffer) + "->");
dtostrf(d.x,1,4,buffer);
reply.concat(String(buffer) + " ");
dtostrf(a.y,1,4,buffer);
reply.concat(String(buffer) + "->");
dtostrf(d.y,1,4,buffer);
reply.concat(String(buffer) + " ");
dtostrf(a.z,1,4,buffer);
reply.concat(String(buffer) + "->");
dtostrf(d.z,1,4,buffer);
reply.concat(String(buffer) + " ");
debugPrintln(reply);
}
示例9: init
String::String(float value, unsigned char decimalPlaces)
{
init();
char buf[33];
*this = dtostrf(value, (33 - 1), decimalPlaces, buf);
}
示例10: strncpy
void
CustomFrameBuilder::appendPositioningData()
{
// time of fix
strncpy(this->whereToAppend, this->gps->getTimeOfFix(), 6);
this->whereToAppend += 6;
// separator
this->appendFieldSeparatorChar();
// fix
if (this->gps->getFix())
{
this->whereToAppend++[0] = 'A';
}
else
{
this->whereToAppend++[0] = 'V';
}
// separator
this->appendFieldSeparatorChar();
// longitude
dtostrf(this->gps->getLongitude(), 2, 3, this->whereToAppend);
this->whereToAppend += strlen(this->whereToAppend);
// separator
this->appendFieldSeparatorChar();
// latitude
dtostrf(this->gps->getLatitude(), 2, 3, this->whereToAppend);
this->whereToAppend += strlen(this->whereToAppend);
// separator
this->appendFieldSeparatorChar();
// altitude
dtostrf(this->gps->getAltitude(), 2, 1, this->whereToAppend);
this->whereToAppend += strlen(this->whereToAppend);
// separator
this->appendFieldSeparatorChar();
// speed
dtostrf(this->gps->getSpeedOverGround(), 2, 1, this->whereToAppend);
this->whereToAppend += strlen(this->whereToAppend);
// separator
this->appendFieldSeparatorChar();
// course
dtostrf(this->gps->getCourseOverGround(), 2, 1, this->whereToAppend);
this->whereToAppend += strlen(this->whereToAppend);
// separator
this->appendFieldSeparatorChar();
// satellites in use
itoa(this->gps->getSatellitesInUse(), this->whereToAppend, 10);
this->whereToAppend += strlen(this->whereToAppend);
// separator
this->appendFieldSeparatorChar();
// HDOP
dtostrf(this->gps->getHDOP(), 2, 1, this->whereToAppend);
this->whereToAppend += strlen(this->whereToAppend);
}
示例11: translate
//.........这里部分代码省略.........
j = T % 10; // Nachkommastelle
itoa (j,dest,10);
} else if (T < 0) {
T = -T; // Vorzeichen abschneiden
itoa (T,dest,10);
while (*dest++) // neues Ende finden
++len;
--dest;
// "style rechtsbündig" anhängen
strcpy_P(dest,PSTR("\" style=\"float: right"));
}
else {
itoa (T,dest,10);
}
src += 5;
}
#endif
#if USE_OW
/*
* 1-Wire Temperatursensoren
* -------------------------
* [email protected] nn = 00 bis MAXSENSORS-1 gibt Werte in 1/10 °C aus
* [email protected] mm = 20 bis MAXSENSORS-1+20 gibt Werte in °C mit einer Nachkommastelle aus
* d.h. [email protected] für Balkenbreite verwenden und [email protected] für Celsius-Anzeige
*/
else if (strncasecmp_P(src,PSTR("[email protected]"),3)==0) {
FUNCS_DEBUG(" - 1-wire");
uint8_t i = (*(src+3)-48)*10 + (*(src+4)-48);
if (i >= 20) { // Offset bei Sensor# abziehen und Wert als Dezimalzahl ausgeben
i -= 20;
dtostrf(ow_array[i] / 10.0,3,1,dest);
} else {
itoa (ow_array[i],dest,10);
}
src += 5;
}
#endif
//Einsetzen des Port Status %PORTxy durch "checked" wenn Portx.Piny = 1
//x: A..G y: 0..7
else if (strncasecmp_P(src,PSTR("PORT"),4)==0) {
FUNCS_DEBUG(" - Portstatus");
uint8_t pin = (*(src+5)-48);
uint8_t b = 0;
switch(*(src+4)) {
case 'A':
b = (PORTA & (1<<pin));
break;
case 'B':
b = (PORTB & (1<<pin));
break;
case 'C':
b = (PORTC & (1<<pin));
break;
case 'D':
b = (PORTD & (1<<pin));
break;
}
if(b) {
//strcpy_P(dest, PSTR("checked"));
strcpy_P(dest, PSTR("ledon.gif"));
}
示例12: dtostrf
bool Adafruit_MQTT_Publish::publish(double f, uint8_t precision) {
char payload[40]; // Need to technically hold float max, 39 digits and minus sign.
dtostrf(f, 0, precision, payload);
return mqtt->publish(topic, payload, qos);
}
示例13: dtostrf
unsigned char String::concat(double num)
{
char buf[20];
char* string = dtostrf(num, 4, 2, buf);
return concat(string, strlen(string));
}
示例14: main
//.........这里部分代码省略.........
mpu6050_getRawData(&ax, &ay, &az, &gx, &gy, &gz);
mpu6050_getConvData(&axg, &ayg, &azg, &gxds, &gyds, &gzds);
accXangle = (atan2(ayg,azg)+PI)*RAD_TO_DEG;
gyroXangle = accXangle;
#endif
for(;;) {
#if MPU6050_GETATTITUDE == 0
mpu6050_getRawData(&ax, &ay, &az, &gx, &gy, &gz);
mpu6050_getConvData(&axg, &ayg, &azg, &gxds, &gyds, &gzds);
#endif
accXangle = (atan2(ayg,azg)+PI)*RAD_TO_DEG;
gyroXangle = accXangle + gxds*dt;
Xangle = 0.98*gyroXangle + 0.02*accXangle;
error = 180 - Xangle;
I_error += (error)*dt;
D_error = (error - previous_error)/*/dt*/;
outputspeed = (P_GAIN * error) + (I_GAIN * I_error) + (D_GAIN * D_error);
previous_error = error;
/*Bang Bang Controller
if((Xangle<=(180.01))&&(Xangle>=179.99))
{
PORTA = 0x00;
}
else if (Xangle>(180.01))
{
set_timercounter0_compare_value(255);
set_timercounter2_compare_value(255);
PORTA = 0x0a;
}
else if(Xangle<(179.99))
{
set_timercounter0_compare_value(255);
set_timercounter2_compare_value(255);
PORTA = 0x05;
}
Bang Bang Controller*/
if((Xangle<=(180.1))&&(Xangle>=179.9))
{
PORTA = 0x00;
}
else if (Xangle>(180.1))
{
set_timercounter0_compare_value(abs(outputspeed));
set_timercounter2_compare_value(abs(outputspeed));
PORTA = 0x0a;
}
else if(Xangle<(179.9))
{
set_timercounter0_compare_value(abs(outputspeed));
set_timercounter2_compare_value(abs(outputspeed));
PORTA = 0x05;
}
#if MPU6050_GETATTITUDE == 0
char itmp[10];
/*dtostrf(ax, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');
dtostrf(ay, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');
dtostrf(az, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');
dtostrf(gx, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');
dtostrf(gy, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');
dtostrf(gz, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');
dtostrf(axg, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');
dtostrf(ayg, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');
dtostrf(azg, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');
dtostrf(gxds, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');
dtostrf(gyds, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');
dtostrf(gzds, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');
dtostrf(accXangle, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');
dtostrf(gyroXangle, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');
dtostrf(initangle, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');
dtostrf(Xangle, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');
dtostrf(error, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');
dtostrf(I_error, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');
dtostrf(D_error, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');*/
dtostrf(outputspeed, 3, 5, itmp); uart_puts(itmp); uart_putc(' ');
uart_puts("\r\n");
uart_puts("\r\n");
#endif
}
}
示例15: loop
//.........这里部分代码省略.........
if (dataFile) {
dataFile.print(dateTimeString);
dataFile.print(";");
dataFile.print(SensorData.sensor1);
dataFile.print(";");
dataFile.println(SensorData.sensor2);
dataFile.close();
}
// state change to IDLE
system_FSM = S_IDLE;
break;
default:
system_FSM = S_IDLE;
}
switch(menu_FSM) {
case M_PAGE1:
if(menu_FSM !=menu_last_state) {
DisplayClear();
mySerial.write("Time"); // clear display + legends
MenuShowTime = millis();
}
now = rtc.now();
DisplayGoto(1,0);
mySerial.write("Time"); // clear display + legends
DisplayGoto(1,8);
TimeDate(now,dateTimeString,2);
mySerial.print(dateTimeString);
DisplayGoto(2,6);
TimeDate(now,dateTimeString,3);
mySerial.print(dateTimeString);
//reserved for showing time and SD card status
menu_last_state = M_PAGE1;
if(millis() - MenuShowTime >= MenuDelayInMillis)
menu_FSM = M_PAGE2;
break;
case M_PAGE2:
if(menu_FSM !=menu_last_state) {
DisplayClear();
mySerial.write("Sens 1: C");
mySerial.write("Sens 2: C");
DisplayGoto(1,14);
mySerial.write(223);
DisplayGoto(2,14);
mySerial.write(223);
MenuShowTime = millis();
}
DisplayGoto(1,10);
mySerial.write(dtostrf(SensorData.sensor1,4,1,tempstring)); // write out the RPM value
DisplayGoto(2,10);
mySerial.write(dtostrf(SensorData.sensor2,4,1,tempstring)); // write out the TEMP value
//mySerial.write(dtostrf(system_FSM,4,1,tempstring)); DEBUG
menu_last_state = M_PAGE2;
if(millis() - MenuShowTime >= MenuDelayInMillis)
menu_FSM = M_PAGE3;
break;
case M_PAGE3:
if(menu_FSM !=menu_last_state) {
DisplayClear();
mySerial.write("Sens 3: N/A C"); // clear display + legends
mySerial.write("Sens 4: N/A C");
DisplayGoto(1,14);
mySerial.write(223);
DisplayGoto(2,14);
mySerial.write(223);
MenuShowTime = millis();
}
DisplayGoto(1,7);
// mySerial.write(dtostrf(SensorData.sensor1,4,1,tempstring)); // write out the RPM value
DisplayGoto(2,7);
//mySerial.write(dtostrf(MenuShowTime,4,1,tempstring)); // write out the TEMP value
menu_last_state = M_PAGE3;
if(millis() - MenuShowTime >= MenuDelayInMillis)
menu_FSM = M_PAGE1;
break;
case M_PAGE4:
break;
default:
menu_FSM = M_PAGE1;
}
}