• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ dtostrf函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中dtostrf函数的典型用法代码示例。如果您正苦于以下问题:C++ dtostrf函数的具体用法?C++ dtostrf怎么用?C++ dtostrf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了dtostrf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:OpenDevice,项目名称:opendevice-lib-arduino,代码行数:39,代码来源:Device.cpp


示例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');
	 }
}
开发者ID:jongeldyret,项目名称:Triggertrap,代码行数:30,代码来源:bulbRamp.cpp


示例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);
}
开发者ID:SkyNet-Solutions,项目名称:iot-gateway-samples,代码行数:23,代码来源:ArduinoSketch.c


示例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;
  }
}
开发者ID:JanJohansen,项目名称:EspAri_Client,代码行数:23,代码来源:daq.cpp


示例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;
}
开发者ID:keith-daigle,项目名称:avr-tpic8101-420a,代码行数:37,代码来源:serial_menu.c


示例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);


}
开发者ID:GandalfGecko,项目名称:antipasto_arduino,代码行数:40,代码来源:BarGraph.cpp


示例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);
*/

}
开发者ID:rochapaulo,项目名称:Gauchito,代码行数:19,代码来源:Gauchito.cpp


示例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);
}
开发者ID:AllenBurnham,项目名称:microscope,代码行数:24,代码来源:AsiMS2000.cpp


示例9: init

String::String(float value, unsigned char decimalPlaces)
{
	init();
	char buf[33];
	*this = dtostrf(value, (33 - 1), decimalPlaces, buf);
}
开发者ID:bokibi,项目名称:corelibs-arduino101,代码行数:6,代码来源:WString.cpp


示例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);
}
开发者ID:sebastienjean,项目名称:arduino-HAO-tracker,代码行数:69,代码来源:CustomFrameBuilder.cpp


示例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"));
				}
开发者ID:jlunz,项目名称:AVR-Webserver,代码行数:67,代码来源:translate.c


示例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);
}
开发者ID:hamling-ling,项目名称:IoPocketMiku,代码行数:5,代码来源:Adafruit_MQTT.cpp


示例13: dtostrf

unsigned char String::concat(double num)
{
	char buf[20];
	char* string = dtostrf(num, 4, 2, buf);
	return concat(string, strlen(string));
}
开发者ID:spirilis,项目名称:arduino-msp430-1.6,代码行数:6,代码来源:WString.cpp


示例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 

	}

}
开发者ID:vishnukijai,项目名称:Self_balance_bot,代码行数:101,代码来源:Self_balance_bot_IMU.c


示例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;
  }
 }
开发者ID:lvesterg,项目名称:heater,代码行数:101,代码来源:heater_FSM.c


示例16: PacketReceived


//.........这里部分代码省略.........
				{
					loggingFlag = 1;
					if (debugMode) {
						debugMode = 0;
					} else {
						InitUART ();
						fdevopen (UART1_PutCharStdio, UART1_GetCharStdio);
					}
					eeprom_write_byte((float*)(CALIBRATION_EEPROM_BASE + LOGGING_FLAG_LOCATION), loggingFlag);
					turnOnAsyncCapture();
					break;
				}
				
				case PACKET_CMD_STOP_LOGGING:
				{
					sendingSamples = 0;
					loggingFlag = 0;
					eeprom_write_byte((float*)(CALIBRATION_EEPROM_BASE + LOGGING_FLAG_LOCATION), loggingFlag);
					break;
				}
				
				case PACKET_CMD_CHECK_AUX_BATTERY:
				{
					loggingFlag = 0;
					if (debugMode) {
						debugMode = 0;
					} else {
						InitUART ();
						fdevopen (UART1_PutCharStdio, UART1_GetCharStdio);
					}
					printf("I2C Test\n");
                    float voltage = readAuxBatteryVoltage();
                    char output[16];
                    dtostrf(voltage, 4, 2, output);
                    printf("Battery Voltage: %s volts\n", output);
					break;
				}

                case PACKET_CMD_TURN_OFF_AUX_USB:
                {
                    //printf ("got TURN_OFF_BATTERY command\n");
                    AuxUSB_Disable();
                    break;
                }

                case PACKET_CMD_TURN_ON_AUX_USB:
                {
                    //printf ("got TURN_ON_BATTERY command\n");
                    AuxUSB_Enable();
                    break;
                }

                case PACKET_CMD_GET_TEMPERATURE:
                {
                    if (debugMode) {
                        printf ("got PACKET_CMD_GET_TEMPERATURE command\n");
                    }
                    float temperature = ReadTemperatureProbe();
                    RingBuffer_Insert(&Send_USB_Buffer, 0xFF);
                    RingBuffer_Insert(&Send_USB_Buffer, 0xFF);
                    RingBuffer_Insert(&Send_USB_Buffer, 0x01); // ammeter id
                    uint8_t checksum = 0x01;
                    uint8_t floatSize = sizeof(temperature);
                    uint8_t packetLength = floatSize + 2;
                    RingBuffer_Insert(&Send_USB_Buffer, packetLength); // packet length, including all framing
                    checksum += packetLength;
开发者ID:JonHylands,项目名称:MozAvrAmmeter,代码行数:67,代码来源:MozAvrAmmeter.c


示例17: snprintf

void CardReader::closeFile(bool store_location /*=false*/) {
  file.sync();
  file.close();
  saving = false;

  if (store_location) {
    char bufferFilerestart[50];
    char bufferX[11];
    char bufferY[11];
    char bufferZ[11];
    char bufferE[11];
    char bufferCoord[50];
    char bufferCoord1[50];
    char bufferCoord2[50];
    char bufferSdpos[11];
    char nameFile[15];
    snprintf(bufferSdpos, sizeof bufferSdpos, "%lu", (unsigned long)sdpos);

    strcpy(nameFile, "restart.gcode");
    if (!fileRestart.exists(nameFile)) {
      fileRestart.createContiguous(&workDir, nameFile, 1);
      fileRestart.close();
    }

    fileRestart.open(&workDir, nameFile, O_WRITE);
    fileRestart.truncate(0);

    dtostrf(current_position[X_AXIS], 1, 3, bufferX);
    dtostrf(current_position[Y_AXIS], 1, 3, bufferY);
    dtostrf(current_position[Z_AXIS], 1, 3, bufferZ);
    dtostrf(current_position[E_AXIS], 1, 3, bufferE);

    #if MECH(DELTA)
      strcpy(bufferCoord1, "G1 Z");
      strcat(bufferCoord1, bufferZ);
      strcat(bufferCoord1, " F8000");
    #else
      strcpy(bufferCoord1, "G92 Z");
      strcat(bufferCoord1, bufferZ);
    #endif

    strcpy(bufferCoord, "G1 X");
    strcat(bufferCoord, bufferX);
    strcat(bufferCoord, " Y");
    strcat(bufferCoord, bufferY);
    strcat(bufferCoord, " Z");
    strcat(bufferCoord, bufferZ);
    strcat(bufferCoord, " F3600");
    strcpy(bufferCoord2, "G92 E");
    strcat(bufferCoord2, bufferE);

    for (int8_t i = 0; i < (int8_t)strlen(fullName); i++)
      fullName[i] = tolower(fullName[i]);

    strcpy(bufferFilerestart, "M34 S");
    strcat(bufferFilerestart, bufferSdpos);
    strcat(bufferFilerestart, " @");
    strcat(bufferFilerestart, fullName);

    #if MECH(DELTA)
      fileRestart.write("G28\n");
    #else
      fileRestart.write(bufferCoord1);
      fileRestart.write("\n");
      fileRestart.write("G28 X Y\n");
    #endif

    if (degTargetBed() > 0) {
      char Bedtemp[15];
      sprintf(Bedtemp, "M190 S%i\n", (int)degTargetBed());
      fileRestart.write(Bedtemp);
    }

    char CurrHotend[10];
    sprintf(CurrHotend, "T%i\n", active_extruder);
    fileRestart.write(CurrHotend);

    for (uint8_t h = 0; h < HOTENDS; h++) {
      if (degTargetHotend(h) > 0) {
        char Hotendtemp[15];
        sprintf(Hotendtemp, "M109 T%i S%i\n", h, (int)degTargetHotend(h));
        fileRestart.write(Hotendtemp);
      }
    }

    #if MECH(DELTA)
      fileRestart.write(bufferCoord1);
      fileRestart.write("\n");
    #endif

    fileRestart.write(bufferCoord);
    fileRestart.write("\n");

   	if (fanSpeed > 0) {
      char fanSp[15];
      sprintf(fanSp, "M106 S%i\n", fanSpeed);
      fileRestart.write(fanSp);
    }

    fileRestart.write(bufferCoord2);
//.........这里部分代码省略.........
开发者ID:RicardoGA,项目名称:MarlinKimbra,代码行数:101,代码来源:cardreader.cpp


示例18: loop

void loop() {

  int tenMinArrayMin[2], tenMinArrayMax[2], tenMinArrayAvg[2]; //changing to 2 for testing purposes
  int oneMinArray[59];
  int oneSecArray[3];
  int qSecondCount = 0, maxVal = 0, secondTotal = 0, minVal = 25;
  int tenMinAvg, tenMinMax, tenMinMin;



  //getTemp
 
  char bufH[10], bufC[10], bufT[10], bufF[10], bufHI[10];  

  float h = dht.readHumidity();
  // Read temperature as Celsius
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit
  float f = dht.readTemperature(true);
  
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f))
  {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index
  // Must send in temp in Fahrenheit!
  float hi = dht.computeHeatIndex(f, h);

  Serial.print("Humidity: "); 
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: "); 
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hi);
  Serial.println(" *F");
  


  dtostrf(h,4,2,bufH);
  dtostrf(t,4,2,bufC);
  dtostrf(f,4,2,bufF);
  dtostrf(hi,4,2,bufHI);
  
  Serial.println(bufH);
  Serial.println(bufC);
  Serial.println(bufF);
  Serial.println(bufHI);
        
 
  
  //getBaroPress
  
  char bufBT[10], bufBP[10];
  
   if(!BaroSensor.isOK()) 
  {
    Serial.print("Sensor not Found/OK. Error: "); 
    Serial.println(BaroSensor.getError());
    BaroSensor.begin(); // Try to reinitialise the sensor if we can
  }
  else 
  {
  float baroSensorTemp = BaroSensor.getTemperature();
  float baroSensorPress = BaroSensor.getPressure();
  
  dtostrf(baroSensorTemp,4,2,bufBT);
  dtostrf(baroSensorPress,4,2,bufBP);    
  }
  
  Serial.print("This is bufT:");  
  Serial.println(bufBT);
  Serial.print("This is bufBP:");  
  Serial.println(bufBP);


//char outBuf[64];
char urlStr[200];
//String urlStr = "POST /weather4/?DHTCelcius="+ bufF;// "&DHTFarenheight="+ bufF +"&DHTHeatIndex=" +bufHI+"&DHTHumidity="+bufH+"&BaroCelcius="+bufBT+"&BaroPressure="+bufBP+ "HTTP/1.1";

sprintf(urlStr,"POST /weather4/?DHTCelcius=%s&DHTFarenheight=%s&DHTHeatIndex=%s&DHTHumidity=%s&BaroCelcius=%s&BaroPressure=%s HTTP/1.1",bufC,bufF,bufHI,bufH,bufBT,bufBP);

//sprintf(outBuf,"POST %s HTTP/1.1",urlStr);

//send to api

  if (client.connect(server, 5000)) {
    Serial.println("connected");
    // Make a HTTP request:
    //client.println("POST /weather4/?t=abc&h=def&ws=hij&wd=klm23344 HTTP/1.1");
    client.println(urlStr);
    client.println("Host: 192.168.0.110");
    client.println("Content-Type: application/x-www-form-urlencoded");
    client.println("Content-Length:0");
//.........这里部分代码省略.........
开发者ID:killbox101,项目名称:weatherStation,代码行数:101,代码来源:weatherStation.cpp


示例19: switch

HomeNetPartialPacket* HomeNetDeviceLCD::process(const uint16_t& fromNode, const uint8_t& fromDevice, const uint8_t& command, const HomeNetPayload& payload) {
#ifdef DEBUG
    Serial.println("Process LCD");
#endif

    //receive outside packets
  //  if (fromNode != _homeNet->_nodeId) {
        for (uint8_t i = 0; i < _displayCount; i++) {
            if ((fromNode == _display[i].fromNode) && (fromDevice == _display[i].fromDevice)) {
#ifdef DEBUG
                    Serial.println("LCD Display Packet Matched");
#endif
                 _lcd->setCursor(0, _display[i].row);
                 char line[16];// = "                ";
                 char num[9];
                //display = &_display[i];
                switch (command) {

                    case CMD_REPLYBYTE:
                        //_lcd->print("Byte");
                        //_lcd->print(payload.getByte(),DEC);
                        sprintf(line,_display[i].message, itoa(payload.getByte(), num, 10));
                        break;

                    case CMD_REPLYINT:
                        //_lcd->print("Int");
                        //_lcd->print(payload.getInt(),DEC);
                        sprintf(line,_display[i].message, itoa(payload.getInt(), num, 10));
                        break;

                    case CMD_REPLYFLOAT:
                        //_lcd->print(_display[i].message);
                        //_lcd->print();
                        sprintf(line,_display[i].message, dtostrf(payload.getFloat(), 5, 2,num));
                        break;
                    
                }
                _lcd->print(line);
                return NULL;
            } 
        }
    //}

    switch (command) {

        case CMD_SETVALUE:
        case CMD_SETSTRING:
            uint8_t length;
            length = payload.getLength();
            _lcd->clear();
            _lcd->setCursor(0, 0);
            if (length <= 16) {
                for (uint8_t i = 0; i < length; i++) {
                    _lcd->print(payload.getByte(i));
                }
                break;
            }
            for (uint8_t i = 0; i < 16; i++) {
                _lcd->print(payload.getByte(i));
            }
            _lcd->setCursor(0, 1);
            for (uint8_t i = 16; i < length; i++) {
                _lcd->print(payload.getByte(i));
            }
            break;

        case CMD_ON:
            _lcd->backlight();
            break;

        case CMD_OFF:
            _lcd->noBacklight();
            break;
    }
    return NULL;
}
开发者ID:ArchiCroc,项目名称:HomeNet.me-Arduino,代码行数:76,代码来源:HomeNetDeviceLCD.cpp


示例20: wsMessageReceived

void wsMessageReceived(WebSocket& socket, const String& message) {
	//Serial.printf("WebSocket message received:\r\n%s\r\n", message.c_str());
	char buf[22];
	dtostrf(pf, 10, 8, buf);
	socket.sendString(buf);
}
开发者ID:zhivko,项目名称:Sming,代码行数:6,代码来源:application.cpp



注:本文中的dtostrf函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ dtsize_t函数代码示例发布时间:2022-05-30
下一篇:
C++ dtoh32函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap