Browse Source

init

master
Robin Thoni 8 years ago
commit
9583de9f03
3 changed files with 83 additions and 0 deletions
  1. 1
    0
      .gitignore
  2. 50
    0
      ArdUtils.cpp
  3. 32
    0
      ArdUtils.h

+ 1
- 0
.gitignore View File

@@ -0,0 +1 @@
1
+/.idea

+ 50
- 0
ArdUtils.cpp View File

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

+ 32
- 0
ArdUtils.h View File

@@ -0,0 +1,32 @@
1
+//
2
+// Created by robin on 1/8/16.
3
+//
4
+
5
+/*
6
+#define ARD_UTILS_DELAYMS
7
+#define ARD_UTILS_UTF8
8
+*/
9
+
10
+#ifndef ARDUTILS_ARDUTILS_H
11
+#define ARDUTILS_ARDUTILS_H
12
+
13
+#include "Arduino.h"
14
+
15
+class ArdUtils
16
+{
17
+public:
18
+#ifdef ARD_UTILS_DELAYMS
19
+    static void delayMs(unsigned ms);
20
+#endif
21
+#ifdef ARD_UTILS_UTF8
22
+    static void utf8ToAscii(char* s);
23
+#endif
24
+
25
+private:
26
+#ifdef ARD_UTILS_UTF8
27
+    static byte _utf8ToAscii(byte ascii, byte& c1);
28
+#endif
29
+};
30
+
31
+#include "ArdUtils.cpp"
32
+#endif //ARDUTILS_ARDUTILS_H

Loading…
Cancel
Save