You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ArdUtils.cpp 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //
  2. // Created by robin on 1/8/16.
  3. //
  4. #ifdef ARD_UTILS_DELAYMS
  5. void ArdUtils::delayMs(unsigned ms)
  6. {
  7. for (unsigned i = 0; i < ms; i++) {
  8. delayMicroseconds(1000);
  9. }
  10. }
  11. #endif
  12. #ifdef ARD_UTILS_UTF8
  13. byte ArdUtils::_utf8ToAscii(byte ascii, byte& c1)
  14. {
  15. if ( ascii<128 ) // Standard ASCII-set 0..0x7F handling
  16. { c1=0;
  17. return( ascii );
  18. }
  19. // get previous input
  20. byte last = c1; // get last char
  21. c1=ascii; // remember actual character
  22. switch (last) // conversion depnding on first UTF8-character
  23. { case 0xC2: return (ascii); break;
  24. case 0xC3: return (ascii | 0xC0); break;
  25. case 0x82: if(ascii==0xAC) return(0x80); // special case Euro-symbol
  26. }
  27. return (0); // otherwise: return zero, if character has to be ignored
  28. }
  29. void ArdUtils::utf8ToAscii(char* s)
  30. {
  31. byte c1 = 0;
  32. int k=0;
  33. byte c;
  34. unsigned len = strlen(s);
  35. for (unsigned i=0; i<len; i++)
  36. {
  37. c = ArdUtils::_utf8ToAscii(s[i], c1);
  38. if (c!=0)
  39. s[k++]=c;
  40. }
  41. s[k]=0;
  42. }
  43. #endif