Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 3:185fdbb7ccf0, committed 2013-05-24
- Comitter:
- Lobo
- Date:
- Fri May 24 17:49:26 2013 +0000
- Parent:
- 2:01588bd27169
- Commit message:
- Now includes AnalogIn and AnalogOut functions
Changed in this revision
amxmbed.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/amxmbed.cpp Wed May 22 16:30:01 2013 +0000 +++ b/amxmbed.cpp Fri May 24 17:49:26 2013 +0000 @@ -120,7 +120,7 @@ static cell AMX_NATIVE_CALL n_digitalClose(AMX *amx, const cell *params) { // port->printf("digitalClose\n\r"); - (void)amx; + //(void)amx; DigitalOut* obj = (DigitalOut*)params[1]; if (obj) { @@ -130,6 +130,94 @@ return 0; } +static cell AMX_NATIVE_CALL n_analogInOpen(AMX * amx, const cell *params) +{ + (void)amx; + AnalogIn* self = new AnalogIn((PinName)params[1]); + + return (cell)self; +} + +static cell AMX_NATIVE_CALL n_analogInClose(AMX *amx, const cell params[]) +{ + (void)amx; + AnalogIn* obj = (AnalogIn*)params[1]; + + if(obj) + { + return(obj->read()); + } + + return 0; +} + +static cell AMX_NATIVE_CALL n_analogInRead(AMX *amx, const cell params[]) +{ + (void)amx; + AnalogIn* obj = (AnalogIn*)params[1]; + + if(obj) + { + float voltage = obj->read(); + + port->printf("%f read from analog in pin \n\r",voltage); + return(amx_ftoc(voltage)); + } + + return 0; +} + +static cell AMX_NATIVE_CALL n_analogOutOpen(AMX *amx, const cell params[]) +{ + (void)amx; + AnalogOut* self = new AnalogOut((PinName)params[1]); + + return (cell)self; +} + +static cell AMX_NATIVE_CALL n_analogOutRead(AMX *amx, const cell params[]) +{ + (void)amx; + AnalogOut* obj = (AnalogOut*)params[1]; + + if(obj) + { + float voltage = obj->read(); + port->printf("reading voltage of %f in analog out pin\n\r",voltage); + + return(amx_ftoc(voltage)); + } + + return 0; +} + +static cell AMX_NATIVE_CALL n_analogOutWrite(AMX *amx, const cell params[]) +{ + (void)amx; + AnalogOut* obj = (AnalogOut*)params[1]; + + if(obj) + { + float voltage = amx_ctof(params[2]); + port->printf("writing voltage of %f to analog out pin\n\r",voltage); + obj->write(voltage); + } + + return(0); +} + +static cell AMX_NATIVE_CALL n_analogOutClose(AMX* amx, const cell params[]) +{ + (void)amx; + AnalogOut* obj = (AnalogOut*)params[1]; + + if(obj) + { + delete obj; + } + return 0; +} + #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) static cell AMX_NATIVE_CALL n_wait(AMX *amx, const cell *params) { @@ -168,6 +256,13 @@ { "digitalRead", n_digitalRead }, { "digitalWrite", n_digitalWrite }, { "digitalClose", n_digitalClose }, + { "analogInOpen", n_analogInOpen }, + { "analogInClose", n_analogInClose }, + { "analogInRead", n_analogInRead }, + { "analogOutOpen", n_analogOutOpen }, + { "analogOutRead", n_analogOutRead }, + { "analogOutWrite", n_analogOutWrite }, + { "analogOutClose", n_analogOutClose }, #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) { "wait", n_wait }, // uses a float, which we do not support on LPC11U24 version