Takehisa Oneta
/
TinyJS
TinyJS on mbed. TinyJS is very simple JavaScript engine.
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 /* 00002 * TinyJS for mbed. 00003 * 00004 * Authored by Takehisa Oneta (ohneta@gmail.com) 00005 * 10th Jan. 2013 00006 */ 00007 00008 /* 00009 * JavaScript samples 00010 * for (x = 0; x < 256; x++) {for (var i = 0; i <= 3; i++) {mbed.DigitalOut(led1, (1 << i) & 0x01);mbed.DigitalOut(led2, (1 << i) & 0x02);mbed.DigitalOut(led3, (1 << i) & 0x04);mbed.DigitalOut(led4, (1 << i) & 0x08);for (j = 0; j < 300; j++) dummy=0;}for (var i = 3; i >= 0; i--) {mbed.DigitalOut(led1, (1 << i) & 0x01);mbed.DigitalOut(led2, (1 << i) & 0x02);mbed.DigitalOut(led3, (1 << i) & 0x04);mbed.DigitalOut(led4, (1 << i) & 0x08);for (j = 0; j < 10; j++) dummy=0;}}; 00011 */ 00012 00013 #include "mbed.h" 00014 #include "TinyJS.h" 00015 #include "Mbed_Functions.h" 00016 00017 Serial pc(USBTX, USBRX); 00018 00019 //unsigned char usbArea[1024] __attribute__((section("AHBSRAM0"))); 00020 //unsigned char ethArea[1024] __attribute__((section("AHBSRAM1"))); 00021 00022 00023 extern int tinyjs_main(int argc, char **argv); 00024 00025 //--------------------------------------------- 00026 00027 int readOneLine(char *buffer, const int bufferSize) 00028 { 00029 int len = 0; 00030 00031 buffer[0] = '\0'; 00032 while (true) { 00033 char c = pc.getc(); 00034 pc.putc(c); 00035 00036 if ('\r' == c) { 00037 return len; 00038 } else if( '\n' == c ) { 00039 } else { 00040 buffer[len] = c; 00041 buffer[len + 1] = '\0'; 00042 len++; 00043 if (len > bufferSize) { 00044 return len; 00045 } 00046 } 00047 } 00048 00049 return len; 00050 } 00051 00052 //--------------------------------------------- 00053 //--------------------------------------------- 00054 00055 int main() { 00056 pc.baud(57600); 00057 00058 while(1) { 00059 printf("\n"); 00060 printf("--------------------------\n"); 00061 printf("TinyJS on mbed\n"); 00062 00063 tinyjs_main(NULL, NULL); 00064 00065 printf("--------------------------\n"); 00066 printf("bye bye\n"); 00067 } 00068 }
Generated on Tue Jul 12 2022 21:01:11 by 1.7.2