static bool parseKeyTimes(const String& string, Vector<float>& result, bool verifyOrder)
{
    result.clear();
    Vector<String> parseList;
    string.split(';', true, parseList);
    for (unsigned n = 0; n < parseList.size(); ++n) {
        String timeString = parseList[n].stripWhiteSpace();
        bool ok;
        float time = timeString.toFloat(&ok);
        if (!ok || time < 0 || time > 1)
            goto fail;
        if (verifyOrder) {
            if (!n) {
                if (time)
                    goto fail;
            } else if (time < result.last()) {
                goto fail;
            }
        }
        result.append(time);
    }
    return true;
fail:
    result.clear();
    return false;
}
Example #2
0
/**
 * Valid Pitch Lines

	81/64
	408.0
	408.
	5
	-5.0
	10/20
	100.0 cents
	100.0 C#
	5/4   E\

	Note : They can also have comments placed after them.
 */
float Tuning::processRatio(String* ratioText) {
	float ratio = 0.0;

	if(ratioText->indexOf(".") > 0) {
		int spacePos = ratioText->indexOf(" ");
		float cents = 0.0;
		if(spacePos > 0) {
			String centsSubstring = ratioText->substring(0,spacePos);

#ifdef DEBUG_TUNING
			Serial.print("Cents Substring:");
			Serial.print(centsSubstring);
			Serial.println(":");
#endif

			cents = centsSubstring.toFloat();
		} else {
			cents = ratioText->toFloat();
		}

		ratio = pow(2,(cents/100.0)/12.0);

#ifdef DEBUG_TUNING
		Serial.print("Ratio is cents ");
		Serial.println(cents);
#endif

	} else if(ratioText->indexOf("/") > 0) {
		int slashPos = ratioText->indexOf("/");
		float numerator = ratioText->substring(0,slashPos).toFloat();
		float denominator = ratioText->substring(slashPos+1).toFloat();
		if(numerator != 0 && denominator != 0) {
			ratio = numerator / denominator;
		}

#ifdef DEBUG_TUNING
		Serial.print("Ratio is ratio ");
		Serial.print(numerator);
		Serial.print("/");
		Serial.print(denominator);
		Serial.print(" = ");
		Serial.println(ratio,4);
#endif

	} else {
		ratio = ratioText->toFloat();
//		Serial.println("Ratio is float");
	}
//	Serial.println(ratio);
	return ratio;
}
Example #3
0
void ROTankWire::handleCmd(String var, String val) {
    if(var == "tdsoffset") {
        double offset = val.toFloat();
        //TheSensorsMem.TdsOffset = offset;
        TheTDSSensor.Update(offset);
    }
    else if(var == "phoffset") {
        double offset = val.toFloat();
        //ThePHSensor.Update(offset);
    }
    else if(var == "tdsVolts") {
        double volts = val.toFloat();
        TheTDSSensor.UpdateVolts(volts);
    }
    else if(var == "tdsMin") {
        int tdsMin = val.toInt();
        TheTDSSensor.UpdateTdsMin(tdsMin);
    }
    else if(var == "doseDurr") {
        int doseDurr = val.toInt();
        TheTDSSensor.UpdateRunDurration(doseDurr);
    }

}
Example #4
0
/**********************************************************
 * @brief  readFloatData
 * @param  
 * @retval None
**********************************************************/
static float readFloatData()
{ 
char c=0;        
String readString;

  while (c != '\n')
  {
    if (Serial.available() >0)
    {
      c = Serial.read();  //gets one byte from serial buffer
      if ( c != '$')
        readString += c; //makes the string readString
    } 
  }    

  return readString.toFloat();
}
Example #5
0
static float numericPrefix(const String& keyString, const String& valueString, Document* document, bool* ok)
{
    // If a prefix of property-value can be converted to a number using strtod,
    // the value will be that number. The remainder of the string is ignored.
    // So when String::toFloat says there is an error, it may be a false positive,
    // and we should check if the valueString prefix was a number.

    bool didReadNumber;
    float value = valueString.toFloat(ok, &didReadNumber);
    if (!*ok) {
        if (!didReadNumber) {
            ASSERT(!value);
            reportViewportWarning(document, UnrecognizedViewportArgumentValueError, valueString, keyString);
            return value;
        }
        *ok = true;
        reportViewportWarning(document, TruncatedViewportArgumentValueError, valueString, keyString);
    }
    return value;
}
static void parseKeyTimes(const String& parse, Vector<float>& result, bool verifyOrder)
{
    result.clear();
    Vector<String> parseList;
    parse.split(';', parseList);
    for (unsigned n = 0; n < parseList.size(); ++n) {
        String timeString = parseList[n];
        bool ok;
        float time = timeString.toFloat(&ok);
        if (!ok || time < 0 || time > 1)
            goto fail;
        if (verifyOrder) {
            if (!n) {
                if (time)
                    goto fail;
            } else if (time < result.last())
                goto fail;
        }
        result.append(time);
    }
    return;
fail:
    result.clear();
}
void AtlasDo::read_response() {
  Wire.requestFrom(_i2c_address, 20, 1);
  byte response = Wire.read();
  String string = Wire.readStringUntil(0);

  if (response == 255) {
    status_level = ERROR;
    status_code = CODE_NO_RESPONSE;
    status_msg = "No response";
    _waiting_for_response = false;
  }
  else if (response == 254) {
    // Request hasn't been processed yet
    return;
  }
  else if (response == 2) {
    status_level = ERROR;
    status_code = CODE_REQUEST_FAILED;
    status_msg = "Request failed";
    _waiting_for_response = false;
  }
  else if (response == 1) {
    status_level = OK;
    status_code = CODE_OK;
    status_msg = "";
    _water_dissolved_oxygen = string.toFloat();
    _send_water_dissolved_oxygen = true;
    _waiting_for_response = false;
  }
  else {
    status_level = ERROR;
    status_code = CODE_UNKNOWN_ERROR;
    status_msg = "Unknown error";
    _waiting_for_response = false;
  }
}
Example #8
0
void Settings::setMetadataSettings(const String& key, const String& value)
{
    if (key == "width") {
        if (value == "device-width") {
            m_viewport_width = 0;
        } else {
            int width = value.toInt();
            if (width <= 10000) {
                if (width <= 320) {
                    // This is a hack to accommodate the pages designed for the
                    // original iPhone. The new version, since 10/2007, is to
                    // use device-width which works for both portrait and
                    // landscape modes.
                    m_viewport_width = 0;
                } else {
                    m_viewport_width = width;
                }
            }
        }
    } else if (key == "height") {
        if (value == "device-height") {
            m_viewport_height = 0;
        } else {
            int height = value.toInt();
            if (height >= 200 && height <= 10000) {
                m_viewport_height = height;
            }
        }
    } else if (key == "initial-scale") {
        int scale = int(value.toFloat() * 100);
        if (scale >= 1 && scale <= 1000) {
            m_viewport_initial_scale = scale;
        }
    } else if (key == "minimum-scale") {
        int scale = int(value.toFloat() * 100);
        if (scale >= 1 && scale <= 1000) {
            m_viewport_minimum_scale = scale;
        }
    } else if (key == "maximum-scale") {
        int scale = int(value.toFloat() * 100);
        if (scale >= 1 && scale <= 1000) {
            m_viewport_maximum_scale = scale;
        }
    } else if (key == "user-scalable") {
        // even Apple doc says using "no", "0" is common in the real world, and
        // some sites, e.g. gomoviesapp.com, use "false".
        if (value == "no" || value == "0" || value == "false") {
            m_viewport_user_scalable = false;
        }
    } else if (key == "target-densitydpi") {
        if (value == "device-dpi") {
            m_viewport_target_densitydpi = 0;
        } else if (value == "low-dpi") {
            m_viewport_target_densitydpi = 120;
        } else if (value == "medium-dpi") {
            m_viewport_target_densitydpi = 160;
        } else if (value == "high-dpi") {
            m_viewport_target_densitydpi = 240;
        } else {
            int dpi = value.toInt();
            if (dpi >= 70 && dpi <= 400) {
                m_viewport_target_densitydpi = dpi;
            }
        }
    } else if (key == "telephone") {
        if (value == "no") {
            m_format_detection_telephone = false;
        }
    } else if (key == "address") {
        if (value == "no") {
            m_format_detection_address = false;
        }
    } else if (key == "email") {
        if (value == "no") {
            m_format_detection_email = false;
        }
    } else if (key == "format-detection") {
        // even Apple doc says "format-detection" should be the name of the
        // <meta> tag. In the real world, e.g. amazon.com, use
        // "format-detection=no" in the "viewport" <meta> tag to disable all
        // format detection.
        if (value == "no") {
            m_format_detection_telephone = false;
            m_format_detection_address = false;
            m_format_detection_email = false;
        }
    }
}
Example #9
0
bool WebServerTask::parse(String key, String value) {

    DSKey newKey;

    if (key.equals("tz")) {
        newKey = DS_TIMEZONE;
    } else if (key.equals("brightness")) {
        newKey = DS_BRIGHTNESS;
    } else if (key.equals("hour_color")) {
        newKey = DS_HOUR_COLOR;
    } else if (key.equals("minute_color")) {
        newKey = DS_MINUTE_COLOR;
    } else if (key.equals("second_color")) {
        newKey = DS_SECOND_COLOR;
    } else if (key.equals("animation")) {
        newKey = DS_CLOCK_ANIMATION;
    } else if (key.equals("night_mode_enable")) {
        newKey = DS_NIGHT_MODE_ENABLE;
    } else if (key.equals("night_mode_brightness")) {
        newKey = DS_NIGHT_MODE_BRIGHTNESS;
    } else if (key.equals("gamma")) {
        newKey = DS_GAMMA;
    } else {
        return false;
    }

    int newVal;
    float f;

    switch(newKey) {

        case DS_TIMEZONE:
        case DS_BRIGHTNESS:
        case DS_CLOCK_ANIMATION:
        case DS_NIGHT_MODE_ENABLE:
        case DS_NIGHT_MODE_BRIGHTNESS:
            newVal = value.toInt();
            break;

        case DS_HOUR_COLOR:
        case DS_MINUTE_COLOR:
        case DS_SECOND_COLOR:
            // Convert the hex string to an int. Offset to remove the preceding # symbol.
            newVal = (int)strtol(&value[1], NULL, 16);
            break;

        case DS_GAMMA:
            // Force the 32-bit float into an int type for storage
            f = value.toFloat();
            newVal = *reinterpret_cast<int*>(&f);
            break;

        default:
            newVal = -1;
            break;
    }

    Serial.println(key + "," + value + " -> " +
                   String(newKey) + "," + String(newVal));

    return DataStore.set(newKey, newVal);
}
Example #10
0
// Returns true if sentence parsed
bool MAXM8interface::parseSentence() {
	int sentenceEnd = sentence.length() - 1;
	bool sentenceValid = false;
	int valStart = 0;
	int valEnd = 0;
	int valIndex = 0;
	String value;
	
	valEnd = sentence.indexOf(',', valStart);
	if (valEnd > 0) {
		if (valEnd + 3 <= sentenceEnd) valEnd += 3; // Skip comma and include msgID
		value = sentence.substring(valStart, valEnd);
		if (value == "$PUBX,00") {
			sentenceValid = true;
			valStart = valEnd + 1; // Skip the next comma delimiter
			valIndex += 2;
		}
	}

	if (sentenceValid) {
		while (valEnd < sentenceEnd) {
			valEnd = sentence.indexOf(',', valStart); // index of comma
			if (valEnd < 0) valEnd = sentenceEnd; // indexOf returns -1 if no token found

			value = sentence.substring(valStart, valEnd); // Start inclusive, end exclusive
		
			switch(valIndex) {
				case PUBX00_TIME: // Format: hhmmss.s
					time = value.toFloat() + TIMEZONE;
					if (time < 0) time += 240000;
					else if (time > 240000) time -= 240000;
					if ((time - 10000*int(time/10000.0)) > 6000.0) time -= 4000.0;
					break;
				case PUBX00_LAT:
					latitude = value.toFloat();
					break;
				case PUBX00_NS:
					// Represent southern latitude as negative
					if (value == "S") latitude = -latitude;
					break;
				case PUBX00_LONG:
					longitude = value.toFloat();
					break;
				case PUBX00_EW:
					// Represent eastern latitude as negative
					if (value == "W") longitude = -longitude;
					break;
				case PUBX00_ALT:
					altitude = value.toFloat();
					break;
				case PUBX00_LOCK:
					if (value == "G3" || value == "D3" || value == "RK") gpsLock = true;
					else gpsLock = false;
					break;
				case PUBX00_HACC:
					accuracy = value.toFloat();
					break;
				case PUBX00_VACC: // This comes after PUBX00_HACC
					accuracy = sqrt(pow(accuracy, 2.0) + pow(value.toFloat(), 2.0));
					break;
				case PUBX00_SOG:
					groundSpeed = 0.2777778*value.toFloat(); // km/hr to m/s
					break;
				case PUBX00_COG:
					groundCourse = value.toFloat();
					break;
				case PUBX00_VVEL:
					rateOfClimb = -value.toFloat(); // Need to change sign
					break;
				case PUBX00_NSAT:
					nSats = value.toInt();
					break;
			}

			valStart = valEnd + 1;
			valIndex ++;
		}

		if (gpsLock && maxAlt < altitude - accuracy) {
			maxAlt = altitude - accuracy;
			maxAltIncreased = true;
		}
		else maxAltIncreased = false;

		sentence = "";
		return true;
	}
	else {
		sentence = "";
		return false;
	}
}
Example #11
0
uint32_t RTCDue::unixtime (String abbreviation)
{
  float adjustment = abbreviation.toFloat() * SECONDS_PER_HOUR;
  
  return unixtime() - (int)adjustment;
}