static int getUnicodeCharacter (DataFile *file, wchar_t *character, const char *description) { DataOperand string; if (getDataOperand(file, &string, description)) { if (string.length > 2) { if ((string.characters[0] == WC_C('U')) && (string.characters[1] == WC_C('+'))) { const wchar_t *digit = &string.characters[2]; int length = string.length - 2; *character = 0; while (length) { int value; int shift; if (!isHexadecimalDigit(*digit++, &value, &shift)) break; *character <<= shift; *character |= value; length -= 1; } if (!length) return 1; } } reportDataError(file, "invalid Unicode character: %.*" PRIws, string.length, string.characters); } return 0; }
//------------------------------------------ // return True if s contain only hexadecimal figure boolean WebDS18B20Buses::isROMCodeString(const char* s) { if (strlen(s) != 16) return false; for (int i = 0; i < 16; i++) { if (!isHexadecimalDigit(s[i])) return false; } return true; }
int isFloatingConstant(unsigned char* s) { int i = 0, iLen; if (isHexadecimalDigit(s)) { i += 2; while (isHexadecimalDigit(s + i)) i++; if (*(s + i) == '.') i++; while (isHexadecimalDigit(s + i)) i++; if (*(s + i) == 'p' || *(s + i) == 'P') { i++; if (isSign(s + i)) i++; while (isDigit(s + i)) i++; } else return 0; } else if (isDigit(s)) { int isFractional = 0; i += 1; while (isDigit(s + i)) i++; if (*(s + i) == '.') { i++; isFractional = 1; } while (isDigit(s + i)) i++; if (*(s + i) == 'e' || *(s + i) == 'E') { i++; if (isSign(s + i)) i++; while (isDigit(s + i)) i++; } else if (!isFractional) return 0; } if (i && (iLen = isFloatingSuffix(s + i))) i += iLen; return i; }
int HttpClient::available() { if (iState == eReadingChunkLength) { while (iClient->available()) { char c = iClient->read(); if (c == '\n') { iState = eReadingBodyChunk; break; } else if (c == '\r') { // no-op } else if (isHexadecimalDigit(c)) { char digit[2] = {c, '\0'}; iChunkLength = (iChunkLength * 16) + strtol(digit, NULL, 16); } } } if (iState == eReadingBodyChunk && iChunkLength == 0) { iState = eReadingChunkLength; } if (iState == eReadingChunkLength) { return 0; } int clientAvailable = iClient->available(); if (iState == eReadingBodyChunk) { return min(clientAvailable, iChunkLength); } else { return clientAvailable; } }
int isIntegerConstant(unsigned char* s) { int i = 0, iLen = 0; if (isNonzeroDigit(s)) { while (isDigit(s + i)) i++; } else if (isHexadecimalPerfix(s)) { i += 2; while (isHexadecimalDigit(s + i)) i++; } else if (*s == '0'){ i += 1; while (isOctalDigit(s + i)) i++; } if (i && (iLen = isIntegerSuffix(s + i))) i += iLen; return i; }
void loop( void ) { // Serial.write( '\n' ) ; // send a char // Serial.write( '\r' ) ; // send a char // Serial5.write( '-' ) ; // send a char // adding a constant integer to a string: stringThree = stringOne + 123; Serial.println(stringThree); // prints "stringThree = 123" // adding a constant long interger to a string: stringThree = stringOne + 123456789; Serial.println(stringThree); // prints " You added 123456789" // adding a constant character to a string: stringThree = stringOne + 'A'; Serial.println(stringThree); // prints "You added A" // adding a constant string to a string: stringThree = stringOne + "abc"; Serial.println(stringThree); // prints "You added abc" stringThree = stringOne + stringTwo; Serial.println(stringThree); // prints "You added this string" // adding a variable integer to a string: int sensorValue = analogRead(A0); stringOne = "Sensor value: "; stringThree = stringOne + sensorValue; Serial.println(stringThree); // prints "Sensor Value: 401" or whatever value analogRead(A0) has // adding a variable long integer to a string: long currentTime = millis(); stringOne = "millis() value: "; stringThree = stringOne + millis(); Serial.println(stringThree); // prints "The millis: 345345" or whatever value currentTime has // do nothing while true: while (true); #if 0 // get any incoming bytes: if (Serial.available() > 0) { int thisChar = Serial.read(); //////// int thisChar = 'a'; // say what was sent: Serial.print("You sent me: \'"); Serial.write(thisChar); Serial.print("\' ASCII Value: "); Serial.println(thisChar); // analyze what was sent: if (isAlphaNumeric(thisChar)) { Serial.println("it's alphanumeric"); } if (isAlpha(thisChar)) { Serial.println("it's alphabetic"); } if (isAscii(thisChar)) { Serial.println("it's ASCII"); } if (isWhitespace(thisChar)) { Serial.println("it's whitespace"); } if (isControl(thisChar)) { Serial.println("it's a control character"); } if (isDigit(thisChar)) { Serial.println("it's a numeric digit"); } if (isGraph(thisChar)) { Serial.println("it's a printable character that's not whitespace"); } if (isLowerCase(thisChar)) { Serial.println("it's lower case"); } if (isPrintable(thisChar)) { Serial.println("it's printable"); } if (isPunct(thisChar)) { Serial.println("it's punctuation"); } if (isSpace(thisChar)) { Serial.println("it's a space character"); } if (isUpperCase(thisChar)) { Serial.println("it's upper case"); } if (isHexadecimalDigit(thisChar)) { Serial.println("it's a valid hexadecimaldigit (i.e. 0 - 9, a - F, or A - F)"); } // add some space and ask for another byte: Serial.println(); Serial.println("Give me another byte:"); Serial.println(); } #endif #if 0 sensorValue = analogRead(A0); // apply the calibration to the sensor reading sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255); Serial.print("sensor = " ); Serial.print(sensorValue); // in case the sensor value is outside the range seen during calibration outputValue = constrain(sensorValue, 0, 255); // print the results to the serial monitor: Serial.print("\t output = "); Serial.println(outputValue); // fade the LED using the calibrated value: analogWrite(9/*ledPin*/, sensorValue); delay(1); #endif #if 0 // read the analog in value: sensorValue = analogRead(A0); // map it to the range of the analog out: outputValue = map(sensorValue, 0, 1023, 0, 255); // change the analog out value: analogWrite(9/*analogOutPin*/, outputValue); // print the results to the serial monitor: Serial.print("sensor = " ); Serial.print(sensorValue); Serial.print("\t output = "); Serial.println(outputValue); // wait 2 milliseconds before the next loop // for the analog-to-digital converter to settle // after the last reading: delay(2); // delay(1000); #endif #if 0 digitalWrite( 0, HIGH ) ; // set the red LED on digitalWrite( 0, LOW ) ; // set the red LED on digitalWrite( 1, HIGH ) ; // set the red LED on digitalWrite( 1, LOW ) ; // set the red LED on digitalWrite( 4, HIGH ) ; // set the red LED on digitalWrite( 4, LOW ) ; // set the red LED on digitalWrite( 5, HIGH ) ; // set the red LED on digitalWrite( 5, LOW ) ; // set the red LED on digitalWrite( 6, HIGH ) ; // set the red LED on digitalWrite( 6, LOW ) ; // set the red LED on digitalWrite( 7, HIGH ) ; // set the red LED on digitalWrite( 7, LOW ) ; // set the red LED on digitalWrite( 8, HIGH ) ; // set the red LED on digitalWrite( 8, LOW ) ; // set the red LED on digitalWrite( 9, HIGH ) ; // set the red LED on digitalWrite( 9, LOW ) ; // set the red LED on digitalWrite( 10, HIGH ) ; // set the red LED on digitalWrite( 10, LOW ) ; // set the red LED on digitalWrite( 11, HIGH ) ; // set the red LED on digitalWrite( 11, LOW ) ; // set the red LED on digitalWrite( 12, HIGH ) ; // set the red LED on digitalWrite( 12, LOW ) ; // set the red LED on digitalWrite( 13, HIGH ) ; // set the red LED on digitalWrite( 13, LOW ) ; // set the red LED on #endif #if 0 // int a = 123; // Serial.print(a, DEC); // for ( uint32_t i = A0 ; i <= A0+NUM_ANALOG_INPUTS ; i++ ) for ( uint32_t i = 0 ; i <= NUM_ANALOG_INPUTS ; i++ ) { int a = analogRead(i); // int a = 123; Serial.print(a, DEC); Serial.print(" "); // Serial.write( ' ' ) ; // send a char // Serial.write( 0x30 + i ) ; // send a char // Serial.write( 0x30 + ((a/1000)%10) ) ; // send a char // Serial.write( 0x30 + ((a/100)%10) ) ; // send a char // Serial.write( 0x30 + ((a/10)%10) ) ; // send a char // Serial.write( 0x30 + (a%10) ) ; // send a char // Serial.write( ' ' ) ; // send a char } Serial.println(); #endif #if 0 volatile int pin_value=0 ; static volatile uint8_t duty_cycle=0 ; static volatile uint16_t dac_value=0 ; // Test digitalWrite led_step1() ; delay( 500 ) ; // wait for a second led_step2() ; delay( 500 ) ; // wait for a second // Test Serial output Serial5.write( '-' ) ; // send a char Serial5.write( "test1\n" ) ; // send a string Serial5.write( "test2" ) ; // send another string // Test digitalRead: connect pin 2 to either GND or 3.3V. !!!! NOT on 5V pin !!!! pin_value=digitalRead( 2 ) ; Serial5.write( "pin 2 value is " ) ; Serial5.write( (pin_value == LOW)?"LOW\n":"HIGH\n" ) ; duty_cycle+=8 ;//=(uint8_t)(millis() & 0xff) ; analogWrite( 13, duty_cycle ) ; analogWrite( 12, duty_cycle ) ; analogWrite( 11, duty_cycle ) ; analogWrite( 10 ,duty_cycle ) ; analogWrite( 9, duty_cycle ) ; analogWrite( 8, duty_cycle ) ; dac_value += 64; analogWrite(A0, dac_value); Serial5.print("\r\nAnalog pins: "); for ( uint32_t i = A0 ; i <= A0+NUM_ANALOG_INPUTS ; i++ ) { int a = analogRead(i); Serial5.print(a, DEC); Serial5.print(" "); } Serial5.println(); Serial5.println("External interrupt pins:"); if ( ul_Interrupt_Pin3 == 1 ) { Serial5.println( "Pin 3 triggered (LOW)" ) ; ul_Interrupt_Pin3 = 0 ; } if ( ul_Interrupt_Pin4 == 1 ) { Serial5.println( "Pin 4 triggered (HIGH)" ) ; ul_Interrupt_Pin4 = 0 ; } if ( ul_Interrupt_Pin5 == 1 ) { Serial5.println( "Pin 5 triggered (FALLING)" ) ; ul_Interrupt_Pin5 = 0 ; } if ( ul_Interrupt_Pin6 == 1 ) { Serial5.println( "Pin 6 triggered (RISING)" ) ; ul_Interrupt_Pin6 = 0 ; } if ( ul_Interrupt_Pin7 == 1 ) { Serial5.println( "Pin 7 triggered (CHANGE)" ) ; ul_Interrupt_Pin7 = 0 ; } #endif }