mbed.py

00001 # This file is Copyright 2009 Dean Hall.
00002 #
00003 # This file is part of the Python-on-a-Chip program.
00004 # Python-on-a-Chip is free software: you can redistribute it and/or modify
00005 # it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
00006 #
00007 # Python-on-a-Chip is distributed in the hope that it will be useful,
00008 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00010 # A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
00011 # is seen in the file COPYING up one directory from this.
00012 
00013 
00014 """__NATIVE__
00015 #include "mbed.h"
00016 #include "TextLCD.h"
00017 
00018 static DigitalOut led1(LED1);
00019 static DigitalOut led2(LED2);
00020 static DigitalOut led3(LED3);
00021 static DigitalOut led4(LED4);
00022 
00023 /* PinName lookup table.  Converts pin number to PinName. */
00024 static PinName const pinNumToName[] = {
00025     NC, NC, NC, NC, NC, p5, p6, p7, p8, p9,
00026     p10, p11, p12, p13, p14, p15, p16, p17, p18, p19,
00027     p20, p21, p22, p23, p24, p25, p26, p27, p28, p29,
00028     p30
00029 };
00030 """
00031 
00032 
00033 class AnalogIn(object):
00034 
00035     def __init__(self, n):
00036         """__NATIVE__
00037         pPmObj_t pself;
00038         pPmObj_t pn;
00039         pPmObj_t pattrs;
00040         PmReturn_t retval = PM_RET_OK;
00041         AnalogIn *adc;
00042 
00043         /* Raise TypeError if wrong number of args */
00044         if (NATIVE_GET_NUM_ARGS() != 2)
00045         {
00046             PM_RAISE(retval, PM_RET_EX_TYPE);
00047             return retval;
00048         }
00049         pself = NATIVE_GET_LOCAL(0);
00050 
00051         /* Raise TypeError if arg is not the right type */
00052         pn = NATIVE_GET_LOCAL(1);
00053         if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT)
00054         {
00055             PM_RAISE(retval, PM_RET_EX_TYPE);
00056             return retval;
00057         }
00058 
00059         /* Instantiate the C++ object */
00060         adc = new AnalogIn(pinNumToName[((pPmInt_t)pn)->val]);
00061 
00062         /* Save the pointer to adc as an inaccessible attribute */
00063         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
00064         retval = int_new((uint32_t)adc, &pn);
00065         PM_RETURN_IF_ERROR(retval);
00066         retval = dict_setItem(pattrs, PM_NONE, pn);
00067         PM_RETURN_IF_ERROR(retval);
00068 
00069         NATIVE_SET_TOS(PM_NONE);
00070         return retval;
00071         """
00072         pass
00073 
00074 
00075     def read_u16(self,):
00076         """__NATIVE__
00077         pPmObj_t pself;
00078         pPmObj_t pn;
00079         pPmObj_t pattrs;
00080         PmReturn_t retval = PM_RET_OK;
00081         AnalogIn *adc;
00082         int32_t n;
00083 
00084         /* If wrong number of args, throw type exception */
00085         if (NATIVE_GET_NUM_ARGS() != 1)
00086         {
00087             PM_RAISE(retval, PM_RET_EX_TYPE);
00088             return retval;
00089         }
00090         pself = NATIVE_GET_LOCAL(0);
00091 
00092         /* Get the the C++ instance */
00093         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
00094         retval = dict_getItem(pattrs, PM_NONE, &pn);
00095         PM_RETURN_IF_ERROR(retval);
00096         adc = (AnalogIn *)((pPmInt_t)pn)->val;
00097 
00098         /* Return input value on the stack */
00099         n = adc->read_u16();
00100         retval = int_new(n, &pn);
00101         NATIVE_SET_TOS(pn);
00102 
00103         return retval;
00104         """
00105         pass
00106 
00107 
00108     def read(self,):
00109         """__NATIVE__
00110         pPmObj_t pself;
00111         pPmObj_t pn;
00112         pPmObj_t pattrs;
00113         PmReturn_t retval = PM_RET_OK;
00114         AnalogIn *adc;
00115         float n;
00116 
00117         /* Raise TypeError if wrong number of args */
00118         if (NATIVE_GET_NUM_ARGS() != 1)
00119         {
00120             PM_RAISE(retval, PM_RET_EX_TYPE);
00121             return retval;
00122         }
00123         pself = NATIVE_GET_LOCAL(0);
00124 
00125         /* Get the the C++ instance */
00126         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
00127         retval = dict_getItem(pattrs, PM_NONE, &pn);
00128         PM_RETURN_IF_ERROR(retval);
00129         adc = (AnalogIn *)((pPmInt_t)pn)->val;
00130 
00131         /* Return input value on the stack */
00132         n = adc->read();
00133         retval = float_new(n, &pn);
00134         NATIVE_SET_TOS(pn);
00135 
00136         return retval;
00137         """
00138         pass
00139 
00140 
00141 class AnalogOut(object):
00142 
00143     def __init__(self, n):
00144         """__NATIVE__
00145         pPmObj_t pself;
00146         pPmObj_t pn;
00147         pPmObj_t pattrs;
00148         PmReturn_t retval = PM_RET_OK;
00149         AnalogOut *dac;
00150 
00151 
00152         /* Raise TypeError if wrong number of args */
00153         if (NATIVE_GET_NUM_ARGS() != 2)
00154         {
00155             PM_RAISE(retval, PM_RET_EX_TYPE);
00156             return retval;
00157         }
00158         pself = NATIVE_GET_LOCAL(0);
00159 
00160         /* Raise TypeError if arg is not the right type */
00161         pn = NATIVE_GET_LOCAL(1);
00162         if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT)
00163         {
00164             PM_RAISE(retval, PM_RET_EX_TYPE);
00165             return retval;
00166         }
00167 
00168         /* Instantiate the object */
00169         dac = new AnalogOut(pinNumToName[((pPmInt_t)pn)->val]);
00170 
00171         /* Save the pointer to adc as an inaccessible attribute */
00172         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
00173         retval = int_new((uint32_t)dac, &pn);
00174         PM_RETURN_IF_ERROR(retval);
00175         retval = dict_setItem(pattrs, PM_NONE, pn);
00176         PM_RETURN_IF_ERROR(retval);
00177 
00178         NATIVE_SET_TOS(PM_NONE);
00179         return retval;
00180         """
00181         pass
00182 
00183 
00184     def write_u16(self, n):
00185         """__NATIVE__
00186         pPmObj_t pself;
00187         pPmObj_t pn;
00188         pPmObj_t pattrs;
00189         PmReturn_t retval = PM_RET_OK;
00190         AnalogOut *dac;
00191 
00192         /* Raise TypeError if wrong number of args */
00193         if (NATIVE_GET_NUM_ARGS() != 2)
00194         {
00195             PM_RAISE(retval, PM_RET_EX_TYPE);
00196             return retval;
00197         }
00198         pself = NATIVE_GET_LOCAL(0);
00199 
00200         /* Raise TypeError if arg is not the right type */
00201         pn = NATIVE_GET_LOCAL(1);
00202         if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT)
00203         {
00204             PM_RAISE(retval, PM_RET_EX_TYPE);
00205             return retval;
00206         }
00207 
00208         /* Get the the C++ instance */
00209         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
00210         retval = dict_getItem(pattrs, PM_NONE, &pn);
00211         PM_RETURN_IF_ERROR(retval);
00212         dac = (AnalogOut *)((pPmInt_t)pn)->val;
00213 
00214         /* Write value to DAC */
00215         pn = NATIVE_GET_LOCAL(1);
00216         dac->write_u16(((pPmInt_t)pn)->val);
00217 
00218         NATIVE_SET_TOS(PM_NONE);
00219         return retval;
00220         """
00221         pass
00222 
00223 
00224     def write(self, n):
00225         """__NATIVE__
00226         pPmObj_t pself;
00227         pPmObj_t pn;
00228         pPmObj_t pattrs;
00229         PmReturn_t retval = PM_RET_OK;
00230         AnalogOut *dac;
00231         float n;
00232 
00233         /* Raise TypeError if wrong number of args */
00234         if (NATIVE_GET_NUM_ARGS() != 2)
00235         {
00236             PM_RAISE(retval, PM_RET_EX_TYPE);
00237             return retval;
00238         }
00239         pself = NATIVE_GET_LOCAL(0);
00240 
00241         /* Raise TypeError if arg is not the right type */
00242         pn = NATIVE_GET_LOCAL(1);
00243         if (OBJ_GET_TYPE(pn) != OBJ_TYPE_FLT)
00244         {
00245             PM_RAISE(retval, PM_RET_EX_TYPE);
00246             return retval;
00247         }
00248 
00249         /* Get the the C++ instance */
00250         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
00251         retval = dict_getItem(pattrs, PM_NONE, &pn);
00252         PM_RETURN_IF_ERROR(retval);
00253         dac = (AnalogOut *)((pPmInt_t)pn)->val;
00254 
00255         /* Saturate and write value to DAC */
00256         pn = NATIVE_GET_LOCAL(1);
00257         n = ((pPmFloat_t)pn)->val;
00258         if (n < 0.0)
00259         {
00260             n = 0.0;
00261         }
00262         else if (n > 1.0)
00263         {
00264             n = 1.0;
00265         }
00266         dac->write(n);
00267 
00268         NATIVE_SET_TOS(PM_NONE);
00269         return retval;
00270         """
00271         pass
00272 
00273 
00274     def read(self,):
00275         """__NATIVE__
00276         pPmObj_t pself;
00277         pPmObj_t pn;
00278         pPmObj_t pattrs;
00279         PmReturn_t retval = PM_RET_OK;
00280         AnalogOut *dac;
00281         float n;
00282 
00283         /* Raise TypeError if wrong number of args */
00284         if (NATIVE_GET_NUM_ARGS() != 1)
00285         {
00286             PM_RAISE(retval, PM_RET_EX_TYPE);
00287             return retval;
00288         }
00289         pself = NATIVE_GET_LOCAL(0);
00290 
00291         /* Get the the C++ instance */
00292         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
00293         retval = dict_getItem(pattrs, PM_NONE, &pn);
00294         PM_RETURN_IF_ERROR(retval);
00295         dac = (AnalogOut *)((pPmInt_t)pn)->val;
00296 
00297         /* Return output value on the stack */
00298         n = dac->read();
00299         retval = float_new(n, &pn);
00300         NATIVE_SET_TOS(pn);
00301 
00302         return retval;
00303         """
00304         pass
00305 
00306 
00307 class DigitalIn(object):
00308 
00309     def __init__(self, n):
00310         """__NATIVE__
00311         pPmObj_t pself;
00312         pPmObj_t pn;
00313         pPmObj_t pattrs;
00314         PmReturn_t retval = PM_RET_OK;
00315         DigitalIn *din;
00316 
00317         /* Raise TypeError if wrong number of args */
00318         if (NATIVE_GET_NUM_ARGS() != 2)
00319         {
00320             PM_RAISE(retval, PM_RET_EX_TYPE);
00321             return retval;
00322         }
00323         pself = NATIVE_GET_LOCAL(0);
00324 
00325         /* Raise TypeError if arg is not the right type */
00326         pn = NATIVE_GET_LOCAL(1);
00327         if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT)
00328         {
00329             PM_RAISE(retval, PM_RET_EX_TYPE);
00330             return retval;
00331         }
00332 
00333         /* Instantiate the C++ object */
00334         din = new DigitalIn(pinNumToName[((pPmInt_t)pn)->val]);
00335 
00336         /* Save the pointer to adc as an inaccessible attribute */
00337         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
00338         retval = int_new((uint32_t)din, &pn);
00339         PM_RETURN_IF_ERROR(retval);
00340         retval = dict_setItem(pattrs, PM_NONE, pn);
00341         PM_RETURN_IF_ERROR(retval);
00342 
00343         NATIVE_SET_TOS(PM_NONE);
00344         return retval;
00345         """
00346         pass
00347 
00348 
00349     def read(self,):
00350         """__NATIVE__
00351         pPmObj_t pself;
00352         pPmObj_t pn;
00353         pPmObj_t pattrs;
00354         PmReturn_t retval = PM_RET_OK;
00355         DigitalIn *din;
00356         int32_t n;
00357 
00358         /* If wrong number of args, throw type exception */
00359         if (NATIVE_GET_NUM_ARGS() != 1)
00360         {
00361             PM_RAISE(retval, PM_RET_EX_TYPE);
00362             return retval;
00363         }
00364         pself = NATIVE_GET_LOCAL(0);
00365 
00366         /* Get the the C++ instance */
00367         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
00368         retval = dict_getItem(pattrs, PM_NONE, &pn);
00369         PM_RETURN_IF_ERROR(retval);
00370         din = (DigitalIn *)((pPmInt_t)pn)->val;
00371 
00372         /* Return input value on the stack */
00373         n = din->read();
00374         retval = int_new(n, &pn);
00375         NATIVE_SET_TOS(pn);
00376 
00377         return retval;
00378         """
00379         pass
00380 
00381 
00382 class DigitalOut(object):
00383 
00384     def __init__(self, n):
00385         """__NATIVE__
00386         pPmObj_t pself;
00387         pPmObj_t pn;
00388         pPmObj_t pattrs;
00389         PmReturn_t retval = PM_RET_OK;
00390         DigitalOut *dout;
00391 
00392         /* Raise TypeError if wrong number of args */
00393         if (NATIVE_GET_NUM_ARGS() != 2)
00394         {
00395             PM_RAISE(retval, PM_RET_EX_TYPE);
00396             return retval;
00397         }
00398         pself = NATIVE_GET_LOCAL(0);
00399 
00400         /* Raise TypeError if arg is not the right type */
00401         pn = NATIVE_GET_LOCAL(1);
00402         if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT)
00403         {
00404             PM_RAISE(retval, PM_RET_EX_TYPE);
00405             return retval;
00406         }
00407 
00408         /* Instantiate the C++ object */
00409         dout = new DigitalOut(pinNumToName[((pPmInt_t)pn)->val]);
00410 
00411         /* Save the pointer to adc as an inaccessible attribute */
00412         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
00413         retval = int_new((uint32_t)dout, &pn);
00414         PM_RETURN_IF_ERROR(retval);
00415         retval = dict_setItem(pattrs, PM_NONE, pn);
00416         PM_RETURN_IF_ERROR(retval);
00417 
00418         NATIVE_SET_TOS(PM_NONE);
00419         return retval;
00420         """
00421         pass
00422 
00423 
00424     def read(self,):
00425         """__NATIVE__
00426         pPmObj_t pself;
00427         pPmObj_t pn;
00428         pPmObj_t pattrs;
00429         PmReturn_t retval = PM_RET_OK;
00430         DigitalOut *dout;
00431         int32_t n;
00432 
00433         /* If wrong number of args, throw type exception */
00434         if (NATIVE_GET_NUM_ARGS() != 1)
00435         {
00436             PM_RAISE(retval, PM_RET_EX_TYPE);
00437             return retval;
00438         }
00439         pself = NATIVE_GET_LOCAL(0);
00440 
00441         /* Get the the C++ instance */
00442         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
00443         retval = dict_getItem(pattrs, PM_NONE, &pn);
00444         PM_RETURN_IF_ERROR(retval);
00445         dout = (DigitalOut *)((pPmInt_t)pn)->val;
00446 
00447         /* Return input value on the stack */
00448         n = dout->read();
00449         retval = int_new(n, &pn);
00450         NATIVE_SET_TOS(pn);
00451 
00452         return retval;
00453         """
00454         pass
00455 
00456 
00457     def write(self, n):
00458         """__NATIVE__
00459         pPmObj_t pself;
00460         pPmObj_t pn;
00461         pPmObj_t pattrs;
00462         PmReturn_t retval = PM_RET_OK;
00463         DigitalOut *dout;
00464 
00465         /* Raise TypeError if wrong number of args */
00466         if (NATIVE_GET_NUM_ARGS() != 2)
00467         {
00468             PM_RAISE(retval, PM_RET_EX_TYPE);
00469             return retval;
00470         }
00471         pself = NATIVE_GET_LOCAL(0);
00472 
00473         /* Raise TypeError if arg is not the right type */
00474         pn = NATIVE_GET_LOCAL(1);
00475         if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT)
00476         {
00477             PM_RAISE(retval, PM_RET_EX_TYPE);
00478             return retval;
00479         }
00480 
00481         /* Get the the C++ instance */
00482         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
00483         retval = dict_getItem(pattrs, PM_NONE, &pn);
00484         PM_RETURN_IF_ERROR(retval);
00485         dout = (DigitalOut *)((pPmInt_t)pn)->val;
00486 
00487         /* Write value to DAC */
00488         pn = NATIVE_GET_LOCAL(1);
00489         dout->write(((pPmInt_t)pn)->val);
00490 
00491         NATIVE_SET_TOS(PM_NONE);
00492         return retval;
00493         """
00494         pass
00495 
00496 
00497 class PwmOut(object):
00498 
00499     def __init__(self, n):
00500         """__NATIVE__
00501         pPmObj_t pself;
00502         pPmObj_t pn;
00503         pPmObj_t pattrs;
00504         PmReturn_t retval = PM_RET_OK;
00505         PwmOut *pwm;
00506 
00507         /* Raise TypeError if wrong number of args */
00508         if (NATIVE_GET_NUM_ARGS() != 2)
00509         {
00510             PM_RAISE(retval, PM_RET_EX_TYPE);
00511             return retval;
00512         }
00513         pself = NATIVE_GET_LOCAL(0);
00514 
00515         /* Raise TypeError if arg is not the right type */
00516         pn = NATIVE_GET_LOCAL(1);
00517         if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT)
00518         {
00519             PM_RAISE(retval, PM_RET_EX_TYPE);
00520             return retval;
00521         }
00522 
00523         /* Instantiate the C++ object */
00524         pwm = new PwmOut(pinNumToName[((pPmInt_t)pn)->val]);
00525 
00526         /* Save the pointer to pwm as an inaccessible attribute */
00527         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
00528         retval = int_new((uint32_t)pwm, &pn);
00529         PM_RETURN_IF_ERROR(retval);
00530         retval = dict_setItem(pattrs, PM_NONE, pn);
00531         PM_RETURN_IF_ERROR(retval);
00532 
00533         NATIVE_SET_TOS(PM_NONE);
00534         return retval;
00535         """
00536         pass
00537 
00538 
00539     def read(self,):
00540         """__NATIVE__
00541         pPmObj_t pself;
00542         pPmObj_t pn;
00543         pPmObj_t pattrs;
00544         PmReturn_t retval = PM_RET_OK;
00545         DigitalOut *dout;
00546         int32_t n;
00547 
00548         /* If wrong number of args, throw type exception */
00549         if (NATIVE_GET_NUM_ARGS() != 1)
00550         {
00551             PM_RAISE(retval, PM_RET_EX_TYPE);
00552             return retval;
00553         }
00554         pself = NATIVE_GET_LOCAL(0);
00555 
00556         /* Get the the C++ instance */
00557         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
00558         retval = dict_getItem(pattrs, PM_NONE, &pn);
00559         PM_RETURN_IF_ERROR(retval);
00560         dout = (DigitalOut *)((pPmInt_t)pn)->val;
00561 
00562         /* Return input value on the stack */
00563         n = dout->read();
00564         retval = int_new(n, &pn);
00565         NATIVE_SET_TOS(pn);
00566 
00567         return retval;
00568         """
00569         pass
00570 
00571 
00572     def period(self, t):
00573         """__NATIVE__
00574         pPmObj_t pself;
00575         pPmObj_t pn;
00576         pPmObj_t pattrs;
00577         PmReturn_t retval = PM_RET_OK;
00578         PwmOut *pwm;
00579 
00580         /* Raise TypeError if wrong number of args */
00581         if (NATIVE_GET_NUM_ARGS() != 2)
00582         {
00583             PM_RAISE(retval, PM_RET_EX_TYPE);
00584             return retval;
00585         }
00586         pself = NATIVE_GET_LOCAL(0);
00587 
00588         /* Raise TypeError if arg is not the right type */
00589         pn = NATIVE_GET_LOCAL(1);
00590         if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT)
00591         {
00592             PM_RAISE(retval, PM_RET_EX_TYPE);
00593             return retval;
00594         }
00595 
00596         /* Get the the C++ instance */
00597         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
00598         retval = dict_getItem(pattrs, PM_NONE, &pn);
00599         PM_RETURN_IF_ERROR(retval);
00600         pwm = (PwmOut *)((pPmInt_t)pn)->val;
00601 
00602         /* Write value to DAC */
00603         pn = NATIVE_GET_LOCAL(1);
00604         pwm->period(((pPmInt_t)pn)->val);
00605 
00606         NATIVE_SET_TOS(PM_NONE);
00607         return retval;
00608         """
00609         pass
00610 
00611 
00612     def period_ms(self, t):
00613         """__NATIVE__
00614         pPmObj_t pself;
00615         pPmObj_t pn;
00616         pPmObj_t pattrs;
00617         PmReturn_t retval = PM_RET_OK;
00618         PwmOut *pwm;
00619 
00620         /* Raise TypeError if wrong number of args */
00621         if (NATIVE_GET_NUM_ARGS() != 2)
00622         {
00623             PM_RAISE(retval, PM_RET_EX_TYPE);
00624             return retval;
00625         }
00626         pself = NATIVE_GET_LOCAL(0);
00627 
00628         /* Raise TypeError if arg is not the right type */
00629         pn = NATIVE_GET_LOCAL(1);
00630         if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT)
00631         {
00632             PM_RAISE(retval, PM_RET_EX_TYPE);
00633             return retval;
00634         }
00635 
00636         /* Get the the C++ instance */
00637         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
00638         retval = dict_getItem(pattrs, PM_NONE, &pn);
00639         PM_RETURN_IF_ERROR(retval);
00640         pwm = (PwmOut *)((pPmInt_t)pn)->val;
00641 
00642         /* Write value to DAC */
00643         pn = NATIVE_GET_LOCAL(1);
00644         pwm->period_ms(((pPmInt_t)pn)->val);
00645 
00646         NATIVE_SET_TOS(PM_NONE);
00647         return retval;
00648         """
00649         pass
00650 
00651 
00652     def period_us(self, t):
00653         """__NATIVE__
00654         pPmObj_t pself;
00655         pPmObj_t pn;
00656         pPmObj_t pattrs;
00657         PmReturn_t retval = PM_RET_OK;
00658         PwmOut *pwm;
00659 
00660         /* Raise TypeError if wrong number of args */
00661         if (NATIVE_GET_NUM_ARGS() != 2)
00662         {
00663             PM_RAISE(retval, PM_RET_EX_TYPE);
00664             return retval;
00665         }
00666         pself = NATIVE_GET_LOCAL(0);
00667 
00668         /* Raise TypeError if arg is not the right type */
00669         pn = NATIVE_GET_LOCAL(1);
00670         if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT)
00671         {
00672             PM_RAISE(retval, PM_RET_EX_TYPE);
00673             return retval;
00674         }
00675 
00676         /* Get the the C++ instance */
00677         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
00678         retval = dict_getItem(pattrs, PM_NONE, &pn);
00679         PM_RETURN_IF_ERROR(retval);
00680         pwm = (PwmOut *)((pPmInt_t)pn)->val;
00681 
00682         /* Write value to DAC */
00683         pn = NATIVE_GET_LOCAL(1);
00684         pwm->period_us(((pPmInt_t)pn)->val);
00685 
00686         NATIVE_SET_TOS(PM_NONE);
00687         return retval;
00688         """
00689         pass
00690 
00691 
00692     def pulsewidth(self, n):
00693         """__NATIVE__
00694         pPmObj_t pself;
00695         pPmObj_t pn;
00696         pPmObj_t pattrs;
00697         PmReturn_t retval = PM_RET_OK;
00698         PwmOut *pwm;
00699 
00700         /* Raise TypeError if wrong number of args */
00701         if (NATIVE_GET_NUM_ARGS() != 2)
00702         {
00703             PM_RAISE(retval, PM_RET_EX_TYPE);
00704             return retval;
00705         }
00706         pself = NATIVE_GET_LOCAL(0);
00707 
00708         /* Raise TypeError if arg is not the right type */
00709         pn = NATIVE_GET_LOCAL(1);
00710         if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT)
00711         {
00712             PM_RAISE(retval, PM_RET_EX_TYPE);
00713             return retval;
00714         }
00715 
00716         /* Get the the C++ instance */
00717         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
00718         retval = dict_getItem(pattrs, PM_NONE, &pn);
00719         PM_RETURN_IF_ERROR(retval);
00720         pwm = (PwmOut *)((pPmInt_t)pn)->val;
00721 
00722         /* Write value to DAC */
00723         pn = NATIVE_GET_LOCAL(1);
00724         pwm->pulsewidth(((pPmInt_t)pn)->val);
00725 
00726         NATIVE_SET_TOS(PM_NONE);
00727         return retval;
00728         """
00729         pass
00730 
00731 
00732     def puslewidth_ms(self, n):
00733         """__NATIVE__
00734         pPmObj_t pself;
00735         pPmObj_t pn;
00736         pPmObj_t pattrs;
00737         PmReturn_t retval = PM_RET_OK;
00738         PwmOut *pwm;
00739 
00740         /* Raise TypeError if wrong number of args */
00741         if (NATIVE_GET_NUM_ARGS() != 2)
00742         {
00743             PM_RAISE(retval, PM_RET_EX_TYPE);
00744             return retval;
00745         }
00746         pself = NATIVE_GET_LOCAL(0);
00747 
00748         /* Raise TypeError if arg is not the right type */
00749         pn = NATIVE_GET_LOCAL(1);
00750         if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT)
00751         {
00752             PM_RAISE(retval, PM_RET_EX_TYPE);
00753             return retval;
00754         }
00755 
00756         /* Get the the C++ instance */
00757         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
00758         retval = dict_getItem(pattrs, PM_NONE, &pn);
00759         PM_RETURN_IF_ERROR(retval);
00760         pwm = (PwmOut *)((pPmInt_t)pn)->val;
00761 
00762         /* Write value to DAC */
00763         pn = NATIVE_GET_LOCAL(1);
00764         pwm->pulsewidth_ms(((pPmInt_t)pn)->val);
00765 
00766         NATIVE_SET_TOS(PM_NONE);
00767         return retval;
00768         """
00769         pass
00770 
00771 
00772     def pulsewidth_us(self, n):
00773         """__NATIVE__
00774         pPmObj_t pself;
00775         pPmObj_t pn;
00776         pPmObj_t pattrs;
00777         PmReturn_t retval = PM_RET_OK;
00778         PwmOut *pwm;
00779 
00780         /* Raise TypeError if wrong number of args */
00781         if (NATIVE_GET_NUM_ARGS() != 2)
00782         {
00783             PM_RAISE(retval, PM_RET_EX_TYPE);
00784             return retval;
00785         }
00786         pself = NATIVE_GET_LOCAL(0);
00787 
00788         /* Raise TypeError if arg is not the right type */
00789         pn = NATIVE_GET_LOCAL(1);
00790         if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT)
00791         {
00792             PM_RAISE(retval, PM_RET_EX_TYPE);
00793             return retval;
00794         }
00795 
00796         /* Get the the C++ instance */
00797         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
00798         retval = dict_getItem(pattrs, PM_NONE, &pn);
00799         PM_RETURN_IF_ERROR(retval);
00800         pwm = (PwmOut *)((pPmInt_t)pn)->val;
00801 
00802         /* Write value to DAC */
00803         pn = NATIVE_GET_LOCAL(1);
00804         pwm->pulsewidth_us(((pPmInt_t)pn)->val);
00805 
00806         NATIVE_SET_TOS(PM_NONE);
00807         return retval;
00808         """
00809         pass
00810 
00811 
00812 class Serial(object):
00813 
00814     def __init__(self, tx, rx):
00815         """__NATIVE__
00816         pPmObj_t pself;
00817         pPmObj_t pn;
00818         pPmObj_t ptx;
00819         pPmObj_t prx;
00820         pPmObj_t pattrs;
00821         PmReturn_t retval = PM_RET_OK;
00822         Serial *ser;
00823 
00824         /* Raise TypeError if wrong number of args */
00825         if (NATIVE_GET_NUM_ARGS() != 3)
00826         {
00827             PM_RAISE(retval, PM_RET_EX_TYPE);
00828             return retval;
00829         }
00830         pself = NATIVE_GET_LOCAL(0);
00831 
00832         /* Raise TypeError if arg is not the right type */
00833         ptx = NATIVE_GET_LOCAL(1);
00834         prx = NATIVE_GET_LOCAL(2);
00835         if ((OBJ_GET_TYPE(ptx) != OBJ_TYPE_INT)
00836             || (OBJ_GET_TYPE(prx) != OBJ_TYPE_INT))
00837         {
00838             PM_RAISE(retval, PM_RET_EX_TYPE);
00839             return retval;
00840         }
00841 
00842         /* Instantiate the C++ object */
00843         ser = new Serial(pinNumToName[((pPmInt_t)ptx)->val],
00844                          pinNumToName[((pPmInt_t)prx)->val]);
00845 
00846         /* Save the pointer to ser as an inaccessible attribute */
00847         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
00848         retval = int_new((uint32_t)ser, &pn);
00849         PM_RETURN_IF_ERROR(retval);
00850         retval = dict_setItem(pattrs, PM_NONE, pn);
00851         PM_RETURN_IF_ERROR(retval);
00852 
00853         NATIVE_SET_TOS(PM_NONE);
00854         return retval;
00855         """
00856         pass
00857 
00858 
00859     def putc(self, s):
00860         """__NATIVE__
00861         pPmObj_t pself;
00862         pPmObj_t pn;
00863         pPmObj_t pattrs;
00864         PmReturn_t retval = PM_RET_OK;
00865         Serial *ser;
00866 
00867         /* Raise TypeError if wrong number of args */
00868         if (NATIVE_GET_NUM_ARGS() != 2)
00869         {
00870             PM_RAISE(retval, PM_RET_EX_TYPE);
00871             return retval;
00872         }
00873         pself = NATIVE_GET_LOCAL(0);
00874 
00875         /* Raise TypeError if arg is not the right type */
00876         pn = NATIVE_GET_LOCAL(1);
00877         if (OBJ_GET_TYPE(pn) != OBJ_TYPE_STR)
00878         {
00879             PM_RAISE(retval, PM_RET_EX_TYPE);
00880             return retval;
00881         }
00882 
00883         /* Get the the C++ instance */
00884         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
00885         retval = dict_getItem(pattrs, PM_NONE, &pn);
00886         PM_RETURN_IF_ERROR(retval);
00887         ser = (Serial *)((pPmInt_t)pn)->val;
00888 
00889         /* Write value to DAC */
00890         pn = NATIVE_GET_LOCAL(1);
00891         ser->putc(((pPmString_t)pn)->val[0]);
00892 
00893         NATIVE_SET_TOS(PM_NONE);
00894         return retval;
00895         """
00896         pass
00897 
00898 
00899     def puts(self, s):
00900         """__NATIVE__
00901         pPmObj_t pself;
00902         pPmObj_t pn;
00903         pPmObj_t pattrs;
00904         PmReturn_t retval = PM_RET_OK;
00905         Serial *ser;
00906 
00907         /* Raise TypeError if wrong number of args */
00908         if (NATIVE_GET_NUM_ARGS() != 2)
00909         {
00910             PM_RAISE(retval, PM_RET_EX_TYPE);
00911             return retval;
00912         }
00913         pself = NATIVE_GET_LOCAL(0);
00914 
00915         /* Raise TypeError if arg is not the right type */
00916         pn = NATIVE_GET_LOCAL(1);
00917         if (OBJ_GET_TYPE(pn) != OBJ_TYPE_STR)
00918         {
00919             PM_RAISE(retval, PM_RET_EX_TYPE);
00920             return retval;
00921         }
00922 
00923         /* Get the the C++ instance */
00924         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
00925         retval = dict_getItem(pattrs, PM_NONE, &pn);
00926         PM_RETURN_IF_ERROR(retval);
00927         ser = (Serial *)((pPmInt_t)pn)->val;
00928 
00929         /* Write value to DAC */
00930         pn = NATIVE_GET_LOCAL(1);
00931         ser->puts((const char *)((pPmString_t)pn)->val);
00932 
00933         NATIVE_SET_TOS(PM_NONE);
00934         return retval;
00935         """
00936         pass
00937 
00938 
00939     def getc(self,):
00940         """__NATIVE__
00941         pPmObj_t pself;
00942         pPmObj_t pn;
00943         pPmObj_t pattrs;
00944         PmReturn_t retval = PM_RET_OK;
00945         Serial *ser;
00946         int32_t n;
00947 
00948         /* If wrong number of args, throw type exception */
00949         if (NATIVE_GET_NUM_ARGS() != 1)
00950         {
00951             PM_RAISE(retval, PM_RET_EX_TYPE);
00952             return retval;
00953         }
00954         pself = NATIVE_GET_LOCAL(0);
00955 
00956         /* Get the the C++ instance */
00957         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
00958         retval = dict_getItem(pattrs, PM_NONE, &pn);
00959         PM_RETURN_IF_ERROR(retval);
00960         ser = (Serial *)((pPmInt_t)pn)->val;
00961 
00962         /* Return char (as string) on the stack */
00963         n = ser->getc();
00964         retval = string_newFromChar((uint8_t)n, &pn);
00965         NATIVE_SET_TOS(pn);
00966 
00967         return retval;
00968         """
00969         pass
00970 
00971 
00972 class SPI(object):
00973 
00974     def __init__(self, mosi, miso, sclk):
00975         """__NATIVE__
00976         pPmObj_t pself;
00977         pPmObj_t pn;
00978         pPmObj_t pmosi;
00979         pPmObj_t pmiso;
00980         pPmObj_t psclk;
00981         pPmObj_t pattrs;
00982         PmReturn_t retval = PM_RET_OK;
00983         SPI *spi;
00984 
00985         /* Raise TypeError if wrong number of args */
00986         if (NATIVE_GET_NUM_ARGS() != 4)
00987         {
00988             PM_RAISE(retval, PM_RET_EX_TYPE);
00989             return retval;
00990         }
00991         pself = NATIVE_GET_LOCAL(0);
00992 
00993         /* Raise TypeError if arg is not the right type */
00994         pmosi = NATIVE_GET_LOCAL(1);
00995         pmiso = NATIVE_GET_LOCAL(2);
00996         psclk = NATIVE_GET_LOCAL(3);
00997         if ((OBJ_GET_TYPE(pmosi) != OBJ_TYPE_INT)
00998             || (OBJ_GET_TYPE(pmiso) != OBJ_TYPE_INT)
00999             || (OBJ_GET_TYPE(psclk) != OBJ_TYPE_INT))
01000         {
01001             PM_RAISE(retval, PM_RET_EX_TYPE);
01002             return retval;
01003         }
01004 
01005         /* Instantiate the C++ object */
01006         spi = new SPI(pinNumToName[((pPmInt_t)pmosi)->val],
01007                       pinNumToName[((pPmInt_t)pmiso)->val],
01008                       pinNumToName[((pPmInt_t)psclk)->val]);
01009 
01010         /* Save the pointer to ser as an inaccessible attribute */
01011         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
01012         retval = int_new((uint32_t)spi, &pn);
01013         PM_RETURN_IF_ERROR(retval);
01014         retval = dict_setItem(pattrs, PM_NONE, pn);
01015         PM_RETURN_IF_ERROR(retval);
01016 
01017         NATIVE_SET_TOS(PM_NONE);
01018         return retval;
01019         """
01020         pass
01021 
01022 
01023     def format(self, bits, mode=0):
01024         """__NATIVE__
01025         pPmObj_t pself;
01026         pPmObj_t pn;
01027         pPmObj_t pbits;
01028         pPmObj_t pmode;
01029         pPmObj_t pattrs;
01030         PmReturn_t retval = PM_RET_OK;
01031         SPI *spi;
01032 
01033         /* Raise TypeError if wrong number of args */
01034         if ((NATIVE_GET_NUM_ARGS() < 2) || (NATIVE_GET_NUM_ARGS() > 3))
01035         {
01036             PM_RAISE(retval, PM_RET_EX_TYPE);
01037             return retval;
01038         }
01039         pself = NATIVE_GET_LOCAL(0);
01040 
01041         /* Raise TypeError if arg is not the right type */
01042         pbits = NATIVE_GET_LOCAL(1);
01043         if (OBJ_GET_TYPE(pbits) != OBJ_TYPE_INT)
01044         {
01045             PM_RAISE(retval, PM_RET_EX_TYPE);
01046             return retval;
01047         }
01048 
01049         /* Get the mode arg if it exists */
01050         pmode = PM_ZERO;
01051         if (NATIVE_GET_NUM_ARGS() == 3)
01052         {
01053             pmode = NATIVE_GET_LOCAL(3);
01054         }
01055 
01056         /* Get the the C++ instance */
01057         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
01058         retval = dict_getItem(pattrs, PM_NONE, &pn);
01059         PM_RETURN_IF_ERROR(retval);
01060         spi = (SPI *)((pPmInt_t)pn)->val;
01061 
01062         /* Set format args */
01063         spi->format(((pPmInt_t)pbits)->val, ((pPmInt_t)pmode)->val);
01064 
01065         NATIVE_SET_TOS(PM_NONE);
01066         return retval;
01067         """
01068         pass
01069 
01070 
01071     def frequency(self, hz):
01072         """__NATIVE__
01073         pPmObj_t pself;
01074         pPmObj_t pn;
01075         pPmObj_t phz;
01076         pPmObj_t pattrs;
01077         PmReturn_t retval = PM_RET_OK;
01078         SPI *spi;
01079 
01080         /* Raise TypeError if wrong number of args */
01081         if (NATIVE_GET_NUM_ARGS() != 2)
01082         {
01083             PM_RAISE(retval, PM_RET_EX_TYPE);
01084             return retval;
01085         }
01086         pself = NATIVE_GET_LOCAL(0);
01087 
01088         /* Raise TypeError if arg is not the right type */
01089         phz = NATIVE_GET_LOCAL(1);
01090         if (OBJ_GET_TYPE(phz) != OBJ_TYPE_INT)
01091         {
01092             PM_RAISE(retval, PM_RET_EX_TYPE);
01093             return retval;
01094         }
01095 
01096         /* Get the the C++ instance */
01097         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
01098         retval = dict_getItem(pattrs, PM_NONE, &pn);
01099         PM_RETURN_IF_ERROR(retval);
01100         spi = (SPI *)((pPmInt_t)pn)->val;
01101 
01102         /* Set frequency */
01103         spi->frequency(((pPmInt_t)phz)->val);
01104 
01105         NATIVE_SET_TOS(PM_NONE);
01106         return retval;
01107         """
01108         pass
01109 
01110 
01111     def write(self, v):
01112         """__NATIVE__
01113         pPmObj_t pself;
01114         pPmObj_t pn;
01115         pPmObj_t pv;
01116         pPmObj_t pattrs;
01117         PmReturn_t retval = PM_RET_OK;
01118         SPI *spi;
01119         int32_t r;
01120 
01121         /* Raise TypeError if wrong number of args */
01122         if (NATIVE_GET_NUM_ARGS() != 2)
01123         {
01124             PM_RAISE(retval, PM_RET_EX_TYPE);
01125             return retval;
01126         }
01127         pself = NATIVE_GET_LOCAL(0);
01128 
01129         /* Raise TypeError if arg is not the right type */
01130         pv = NATIVE_GET_LOCAL(1);
01131         if (OBJ_GET_TYPE(pv) != OBJ_TYPE_INT)
01132         {
01133             PM_RAISE(retval, PM_RET_EX_TYPE);
01134             return retval;
01135         }
01136 
01137         /* Get the the C++ instance */
01138         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
01139         retval = dict_getItem(pattrs, PM_NONE, &pn);
01140         PM_RETURN_IF_ERROR(retval);
01141         spi = (SPI *)((pPmInt_t)pn)->val;
01142 
01143         /* Write the value and return the response */
01144         r = spi->write(((pPmInt_t)pv)->val);
01145         retval = int_new(r, &pn);
01146         NATIVE_SET_TOS(pn);
01147         return retval;
01148         """
01149         pass
01150 
01151 
01152 class I2C(object):
01153 
01154     def __init__(self, sda, scl):
01155         """__NATIVE__
01156         pPmObj_t pself;
01157         pPmObj_t pn;
01158         pPmObj_t psda;
01159         pPmObj_t pscl;
01160         pPmObj_t pattrs;
01161         PmReturn_t retval = PM_RET_OK;
01162         I2C *i2c;
01163 
01164         /* Raise TypeError if wrong number of args */
01165         if (NATIVE_GET_NUM_ARGS() != 3)
01166         {
01167             PM_RAISE(retval, PM_RET_EX_TYPE);
01168             return retval;
01169         }
01170         pself = NATIVE_GET_LOCAL(0);
01171 
01172         /* Raise TypeError if arg is not the right type */
01173         psda = NATIVE_GET_LOCAL(1);
01174         pscl = NATIVE_GET_LOCAL(2);
01175         if ((OBJ_GET_TYPE(psda) != OBJ_TYPE_INT)
01176             || (OBJ_GET_TYPE(pscl) != OBJ_TYPE_INT))
01177         {
01178             PM_RAISE(retval, PM_RET_EX_TYPE);
01179             return retval;
01180         }
01181 
01182         /* Instantiate the C++ object */
01183         i2c = new I2C(pinNumToName[((pPmInt_t)psda)->val],
01184                       pinNumToName[((pPmInt_t)pscl)->val]);
01185 
01186         /* Save the pointer to ser as an inaccessible attribute */
01187         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
01188         retval = int_new((uint32_t)i2c, &pn);
01189         PM_RETURN_IF_ERROR(retval);
01190         retval = dict_setItem(pattrs, PM_NONE, pn);
01191         PM_RETURN_IF_ERROR(retval);
01192 
01193         NATIVE_SET_TOS(PM_NONE);
01194         return retval;
01195         """
01196         pass
01197 
01198 
01199     def frequency(self, hz):
01200         """__NATIVE__
01201         pPmObj_t pself;
01202         pPmObj_t pn;
01203         pPmObj_t phz;
01204         pPmObj_t pattrs;
01205         PmReturn_t retval = PM_RET_OK;
01206         I2C *i2c;
01207 
01208         /* Raise TypeError if wrong number of args */
01209         if (NATIVE_GET_NUM_ARGS() != 2)
01210         {
01211             PM_RAISE(retval, PM_RET_EX_TYPE);
01212             return retval;
01213         }
01214         pself = NATIVE_GET_LOCAL(0);
01215 
01216         /* Raise TypeError if arg is not the right type */
01217         phz = NATIVE_GET_LOCAL(1);
01218         if (OBJ_GET_TYPE(phz) != OBJ_TYPE_INT)
01219         {
01220             PM_RAISE(retval, PM_RET_EX_TYPE);
01221             return retval;
01222         }
01223 
01224         /* Get the the C++ instance */
01225         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
01226         retval = dict_getItem(pattrs, PM_NONE, &pn);
01227         PM_RETURN_IF_ERROR(retval);
01228         i2c = (I2C *)((pPmInt_t)pn)->val;
01229 
01230         /* Set frequency */
01231         i2c->frequency(((pPmInt_t)phz)->val);
01232 
01233         NATIVE_SET_TOS(PM_NONE);
01234         return retval;
01235         """
01236         pass
01237 
01238 
01239     def read(self, addr, data, length):
01240         """__NATIVE__
01241         pPmObj_t pself;
01242         pPmObj_t pn;
01243         pPmObj_t paddr;
01244         pPmObj_t pdata;
01245         pPmObj_t plen;
01246         pPmObj_t pattrs;
01247         PmReturn_t retval = PM_RET_OK;
01248         I2C *i2c;
01249 
01250         /* Raise TypeError if wrong number of args */
01251         if (NATIVE_GET_NUM_ARGS() != 4)
01252         {
01253             PM_RAISE(retval, PM_RET_EX_TYPE);
01254             return retval;
01255         }
01256         pself = NATIVE_GET_LOCAL(0);
01257 
01258         /* Raise TypeError if arg is not the right type */
01259         paddr = NATIVE_GET_LOCAL(1);
01260         pdata = NATIVE_GET_LOCAL(2);
01261         plen = NATIVE_GET_LOCAL(3);
01262         if ((OBJ_GET_TYPE(paddr) != OBJ_TYPE_INT)
01263             || (OBJ_GET_TYPE(pdata) != OBJ_TYPE_STR)
01264             || (OBJ_GET_TYPE(plen) != OBJ_TYPE_INT))
01265         {
01266             PM_RAISE(retval, PM_RET_EX_TYPE);
01267             return retval;
01268         }
01269 
01270         /* Get the the C++ instance */
01271         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
01272         retval = dict_getItem(pattrs, PM_NONE, &pn);
01273         PM_RETURN_IF_ERROR(retval);
01274         i2c = (I2C *)((pPmInt_t)pn)->val;
01275 
01276         /* Read the bytes into the string */
01277         /* WARNING: Changing the bytes of a string object is BAD. */
01278         i2c->read(((pPmInt_t)paddr)->val,
01279                   (char *)((pPmString_t)pdata)->val,
01280                   ((pPmInt_t)plen)->val);
01281         NATIVE_SET_TOS(PM_NONE);
01282         return retval;
01283         """
01284         pass
01285 
01286 
01287     def write(self, addr, data, length):
01288         """__NATIVE__
01289         pPmObj_t pself;
01290         pPmObj_t pn;
01291         pPmObj_t paddr;
01292         pPmObj_t pdata;
01293         pPmObj_t plen;
01294         pPmObj_t pattrs;
01295         PmReturn_t retval = PM_RET_OK;
01296         I2C *i2c;
01297 
01298         /* Raise TypeError if wrong number of args */
01299         if (NATIVE_GET_NUM_ARGS() != 4)
01300         {
01301             PM_RAISE(retval, PM_RET_EX_TYPE);
01302             return retval;
01303         }
01304         pself = NATIVE_GET_LOCAL(0);
01305 
01306         /* Raise TypeError if arg is not the right type */
01307         paddr = NATIVE_GET_LOCAL(1);
01308         pdata = NATIVE_GET_LOCAL(2);
01309         plen = NATIVE_GET_LOCAL(3);
01310         if ((OBJ_GET_TYPE(paddr) != OBJ_TYPE_INT)
01311             || (OBJ_GET_TYPE(pdata) != OBJ_TYPE_STR)
01312             || (OBJ_GET_TYPE(plen) != OBJ_TYPE_INT))
01313         {
01314             PM_RAISE(retval, PM_RET_EX_TYPE);
01315             return retval;
01316         }
01317 
01318         /* Get the the C++ instance */
01319         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
01320         retval = dict_getItem(pattrs, PM_NONE, &pn);
01321         PM_RETURN_IF_ERROR(retval);
01322         i2c = (I2C *)((pPmInt_t)pn)->val;
01323 
01324         /* Write the value and return the response */
01325         i2c->write(((pPmInt_t)paddr)->val,
01326                    (char *)((pPmString_t)pdata)->val,
01327                    ((pPmInt_t)plen)->val);
01328         NATIVE_SET_TOS(PM_NONE);
01329         return retval;
01330         """
01331         pass
01332 
01333 
01334 class TextLCD(object):
01335 
01336     def __init__(self,):
01337         """__NATIVE__
01338         pPmObj_t pself;
01339         pPmObj_t pn;
01340         pPmObj_t pattrs;
01341         PmReturn_t retval = PM_RET_OK;
01342         TextLCD *lcd;
01343 
01344         /* Raise TypeError if wrong number of args */
01345         if (NATIVE_GET_NUM_ARGS() != 1)
01346         {
01347             PM_RAISE(retval, PM_RET_EX_TYPE);
01348             return retval;
01349         }
01350         pself = NATIVE_GET_LOCAL(0);
01351 
01352         /* Instantiate the C++ object */
01353         lcd = new TextLCD(pinNumToName[24],
01354                           pinNumToName[25],
01355                           pinNumToName[26],
01356                           pinNumToName[27],
01357                           pinNumToName[28],
01358                           pinNumToName[29],
01359                           pinNumToName[30]);
01360 
01361         /* Save the pointer to pwm as an inaccessible attribute */
01362         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
01363         retval = int_new((uint32_t)lcd, &pn);
01364         PM_RETURN_IF_ERROR(retval);
01365         retval = dict_setItem(pattrs, PM_NONE, pn);
01366         PM_RETURN_IF_ERROR(retval);
01367 
01368         NATIVE_SET_TOS(PM_NONE);
01369         return retval;
01370         """
01371         pass
01372 
01373 
01374     def printf(self, n):
01375         """__NATIVE__
01376         pPmObj_t pself;
01377         pPmObj_t pn;
01378         pPmObj_t pattrs;
01379         PmReturn_t retval = PM_RET_OK;
01380         TextLCD *lcd;
01381 
01382         /* Raise TypeError if wrong number of args */
01383         if (NATIVE_GET_NUM_ARGS() != 2)
01384         {
01385             PM_RAISE(retval, PM_RET_EX_TYPE);
01386             return retval;
01387         }
01388         pself = NATIVE_GET_LOCAL(0);
01389 
01390         /* Raise TypeError if arg is not the right type */
01391         pn = NATIVE_GET_LOCAL(1);
01392         if (OBJ_GET_TYPE(pn) != OBJ_TYPE_STR)
01393         {
01394             PM_RAISE(retval, PM_RET_EX_TYPE);
01395             return retval;
01396         }
01397 
01398         /* Get the the C++ instance */
01399         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
01400         retval = dict_getItem(pattrs, PM_NONE, &pn);
01401         PM_RETURN_IF_ERROR(retval);
01402         lcd = (TextLCD *)((pPmInt_t)pn)->val;
01403 
01404         /* Write value to DAC */
01405         pn = NATIVE_GET_LOCAL(1);
01406         lcd->printf((char const *)((pPmString_t)pn)->val);
01407 
01408         NATIVE_SET_TOS(PM_NONE);
01409         return retval;
01410         """
01411         pass
01412 
01413 
01414     def cls(self,):
01415         """__NATIVE__
01416         pPmObj_t pself;
01417         pPmObj_t pn;
01418         pPmObj_t pattrs;
01419         PmReturn_t retval = PM_RET_OK;
01420         TextLCD *lcd;
01421 
01422         /* Raise TypeError if wrong number of args */
01423         if (NATIVE_GET_NUM_ARGS() != 1)
01424         {
01425             PM_RAISE(retval, PM_RET_EX_TYPE);
01426             return retval;
01427         }
01428         pself = NATIVE_GET_LOCAL(0);
01429 
01430         /* Get the the C++ instance */
01431         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
01432         retval = dict_getItem(pattrs, PM_NONE, &pn);
01433         PM_RETURN_IF_ERROR(retval);
01434         lcd = (TextLCD *)((pPmInt_t)pn)->val;
01435 
01436         /* Clear LCD */
01437         lcd->cls();
01438 
01439         NATIVE_SET_TOS(PM_NONE);
01440         return retval;
01441         """
01442         pass
01443 
01444 
01445     def locate(self, column, row):
01446         """__NATIVE__
01447         pPmObj_t pself;
01448         pPmObj_t pn;
01449         pPmObj_t pc;
01450         pPmObj_t pr;
01451         pPmObj_t pattrs;
01452         PmReturn_t retval = PM_RET_OK;
01453         TextLCD *lcd;
01454 
01455         /* Raise TypeError if wrong number of args */
01456         if (NATIVE_GET_NUM_ARGS() != 3)
01457         {
01458             PM_RAISE(retval, PM_RET_EX_TYPE);
01459             return retval;
01460         }
01461         pself = NATIVE_GET_LOCAL(0);
01462 
01463         /* Raise TypeError if arg is not the right type */
01464         pc = NATIVE_GET_LOCAL(1);
01465         pr = NATIVE_GET_LOCAL(2);
01466         if ((OBJ_GET_TYPE(pc) != OBJ_TYPE_INT)
01467             || (OBJ_GET_TYPE(pr) != OBJ_TYPE_INT))
01468         {
01469             PM_RAISE(retval, PM_RET_EX_TYPE);
01470             return retval;
01471         }
01472 
01473         /* Get the the C++ instance */
01474         pattrs = (pPmObj_t)((pPmInstance_t)pself)->cli_attrs;
01475         retval = dict_getItem(pattrs, PM_NONE, &pn);
01476         PM_RETURN_IF_ERROR(retval);
01477         lcd = (TextLCD *)((pPmInt_t)pn)->val;
01478 
01479         /* Set the location of the LCD's cursor */
01480         lcd->locate(((pPmInt_t)pc)->val, ((pPmInt_t)pr)->val);
01481 
01482         NATIVE_SET_TOS(PM_NONE);
01483         return retval;
01484         """
01485         pass
01486 
01487 
01488 
01489 
01490 def set_led(led, val):
01491     """__NATIVE__
01492     pPmObj_t pled;
01493     pPmObj_t pval;
01494     int32_t nled;
01495     int32_t nval;
01496     PmReturn_t retval = PM_RET_OK;
01497 
01498     /* If wrong number of args, raise TypeError */
01499     if (NATIVE_GET_NUM_ARGS() > 2)
01500     {
01501         PM_RAISE(retval, PM_RET_EX_TYPE);
01502         return retval;
01503     }
01504 
01505     /* If arg is not an int, raise TypeError */
01506     pled = NATIVE_GET_LOCAL(0);
01507     pval = NATIVE_GET_LOCAL(1);
01508     if ((OBJ_GET_TYPE(pled) != OBJ_TYPE_INT)
01509         || (OBJ_GET_TYPE(pval) != OBJ_TYPE_INT))
01510     {
01511         PM_RAISE(retval, PM_RET_EX_TYPE);
01512         return retval;
01513     }
01514 
01515     /* Get int value from the arg */
01516     nled = ((pPmInt_t)pled)->val;
01517     nval = ((pPmInt_t)pval)->val;
01518 
01519     /* Set the LED to the given value */
01520     switch (nled)
01521     {
01522         case 1: led1 = nval; break;
01523         case 2: led2 = nval; break;
01524         case 3: led3 = nval; break;
01525         case 4: led4 = nval; break;
01526     }
01527 
01528     NATIVE_SET_TOS(PM_NONE);
01529     return retval;
01530     """
01531     pass
01532 
01533 # :mode=c:

Generated on Mon Oct 18 07:40:46 2010 for Python-on-a-chip by  doxygen 1.5.9