Peter Cooper / Mbed 2 deprecated Dome

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "main.h"
00003 #include "cmd.h"
00004 #include "i2c.h"
00005 #include "serial.h"
00006 #include "scripting.h"
00007 #include "breakup.h"
00008 #include "local_defines.h"
00009 
00010 Serial pc(USBTX, USBRX); // tx, rx
00011 
00012 int sys_state = 0;
00013 int var[MAX_VAR];
00014 
00015 int main() 
00016 {
00017     char    buf[0x20];    /* input buffer */
00018     int     r;            /* general int */
00019     
00020     sys_state = TO_RS232;
00021     
00022     exec_profile();
00023     
00024 //    relay_operate(0);
00025 //    init_pca9685(0xb8);
00026 //    init_pca9685(0xba);
00027     
00028     pc.printf("\n\rDome Controler\n\n\r\r");
00029     rs232_opener();
00030     pc.printf("\n\rCMD > ");
00031     while(1){             /* Command Loop */
00032         r = 0;
00033         while(r==0){
00034             if(pc.readable()){
00035                 sys_state = TO_USB;
00036                 r = usb_gets(buf,sizeof(buf));
00037             } else if(rs232_readable()){
00038                 sys_state = TO_RS232;
00039                 r = rs232_gets(buf,sizeof(buf));
00040             }
00041         }
00042         if(r>2){
00043             find_cmd(buf);
00044         }
00045         if (sys_state & TO_USB)
00046             pc_output_string("\n\rCMD > ");
00047         if (sys_state & TO_RS232)
00048             rs232_output_string("\n\rCMD > ");
00049         sys_state = 0;
00050     }
00051 }
00052 
00053 int usb_gets(char *s,int len) 
00054 {
00055     char   c;
00056     int    cnt=0;
00057 
00058     while ((c = pc.getc()) != 0) {
00059         if ((c == 0x0a) || (c==0x0d)) {
00060             pc.printf("\n\r");
00061             *s++ = '\0';
00062             return(cnt);    /* Return length */
00063         } else if (c==0x7f) {  /* Delete */
00064             pc.putc(0x08);
00065             pc.putc(0x20);
00066             pc.putc(0x08);
00067             cnt--;
00068             *s--;
00069         } else if (c==0x08) {  /* BS */
00070             pc.putc(0x08);
00071             pc.putc(0x20);
00072             pc.putc(0x08);
00073             cnt--;
00074             *s--;
00075         } else if (c==025) {  /* CTRL-U */
00076             while (cnt!=0) {
00077                 pc.putc(0x08);
00078                 pc.putc(0x20);
00079                 pc.putc(0x08);
00080                 cnt--;
00081                 *s--;
00082             }
00083         } else {
00084             *s++ = c;
00085             pc.putc(c);
00086             cnt++;
00087         }
00088     }
00089     return(cnt);
00090 }
00091 
00092 void pc_output_string(char *buf)
00093 {
00094     int a = 0;
00095     while(a != strlen(buf)){
00096         pc.putc(buf[a]);
00097         if(buf[a]=='\n')
00098             pc.putc('\r');
00099         a++;
00100     }
00101 }
00102 
00103 void exec_profile(void)
00104 {
00105     char    *a[2] = {"exec","profile.cmd"};
00106     exec_file(2,a);
00107 }
00108