python

Dependencies:   TSI mbed

Fork of pymite by Norimasa Okamoto

Revision:
3:559c4bd38111
Parent:
2:a2bea117e22e
Child:
4:23becb24acb8
--- a/platform/mbed/NativeClassInterface.cpp	Tue Mar 12 11:40:41 2013 +0000
+++ b/platform/mbed/NativeClassInterface.cpp	Wed Mar 13 10:05:34 2013 +0000
@@ -1,8 +1,9 @@
-// NativeClassInterface.cpp 2013/3/12
+// NativeClassInterface.cpp 2013/3/13
 #include "mbed.h"
 #define __DEBUG__ 1
 #include "pm.h"
 #include "NativeClassInterface.h"
+#include "PinNameTable.h"
 
 #undef __FILE_ID__
 #define __FILE_ID__ 0x71
@@ -62,19 +63,30 @@
 template<>
 PinName NativeClassInterface::argv<PinName>(int n)
 {
-    /* PinName lookup table.  Converts pin number to PinName. */
-    const PinName pinNumToName[] = {
-        NC, LED1, LED2, LED3, LED4, p5, p6, p7, p8, p9,
-        p10, p11, p12, p13, p14, p15, p16, p17, p18, p19,
-        p20, p21, p22, p23, p24, p25, p26, p27, p28, p29,
-        p30
-    };
-
     pPmObj_t pn = NATIVE_GET_LOCAL(n);
-    return pinNumToName[((pPmInt_t)pn)->val];
+    if (OBJ_GET_TYPE(pn) == OBJ_TYPE_INT) {
+        return (PinName)(((pPmInt_t)pn)->val);
+    }
+    if (OBJ_GET_TYPE(pn) != OBJ_TYPE_STR) {
+        return NC;
+    }       
+    int imin = 0;
+    int imax = sizeof(pinname_table) / sizeof(pinNameStr) - 1;
+    char *key = reinterpret_cast<char*>(((pPmString_t)pn)->val);
+    while(imax >= imin) {
+        int i = (imin + imax) / 2;
+        int c = strcmp(key, pinname_table[i].name);
+        if (c == 0) {
+            return pinname_table[i].pin;
+        } else if (c > 0) {
+            imin = i + 1;
+        } else {
+            imax = i - 1;
+        }
+    }
+    return NC;
 }
 
-
 template<>
 PmReturn_t NativeClassInterface::set_return_value<int>(PmType_t ret_type, int value)
 {