frederic blanc
/
HMA_HelloWord
test
main.cpp
- Committer:
- fblanc
- Date:
- 2014-05-14
- Revision:
- 0:92dd9611bf80
- Child:
- 1:16fae309f85e
File content as of revision 0:92dd9611bf80:
#include "mbed.h" Serial pc(USBTX, USBRX); DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); AnalogIn adc_hma(p17); uint16_t T_hma_u16[2][4096]; uint16_t index_hma_write=0; uint16_t index_hma_read=0; bool t_write=0; char str[256]; uint8_t start_str=0; bool flag_write_USB=0; Ticker flipperADC; void flipADC() { led4=1; T_hma_u16[t_write][index_hma_write++]=adc_hma.read_u16(); //read ADC //T_hma_u16[t_write][index_hma_write++]=0x00FF; if(index_hma_write>1000) { flag_write_USB=1; t_write=!t_write; //toggel buffer index_hma_read=--index_hma_write; index_hma_write=0; } led4=0; } Ticker flipperUSB; void flipUSB() { flag_write_USB=1; } void pc_rx(void) { for(; pc.readable()==true; ++start_str) { str[start_str]=pc.getc(); } if( strcmp(str,"*IDN?\r")==0 || strcmp(str,"*ID?")==0) { pc.printf("HMA\r"); start_str=0; for(int i=0; i<256; ++i) { str[i]='\0'; } led4=1; led2=0; led3=0; } else if( strcmp(str,"MEASure")==0 || strcmp(str,"MEAS")==0 || strcmp(str,"measure")==0) { for(int i=0; i<256; ++i) { str[i]='\0'; } flipperADC.attach_us(&flipADC, 1000); //500us led4=0; led2=1; led3=0; } else if( strcmp(str,"ABORt")==0 || strcmp(str,"ABOR")==0 || strcmp(str,"ABORT")==0) { for(int i=0; i<256; ++i) { str[i]='\0'; } flipperADC.detach(); t_write=0; index_hma_read=0; index_hma_write=0; led4=0; led2=0; led3=1; } for(int i=0; i<start_str; ++i) { if(str[i]=='\r') { for(int j=0; j<256; ++j) { str[j]='\0'; } start_str=0; } } } int main() { pc.baud(460800); for(int i=0; i<256; ++i) { str[i]='\0'; } //RUN ADC // flipperADC.attach_us(&flipADC, 500); //500us // flipperUSB.attach(&flipUSB,0.5); //500ms while(1) { led1=0; if (pc.readable()) { pc_rx(); } if(flag_write_USB==1) { flag_write_USB=0; led1=1; pc.printf("%04d\0",index_hma_read); char* ptr=(char*)&T_hma_u16[!t_write][0]; for(uint16_t i=0; i<index_hma_read; ++i) { pc.putc(*ptr++); pc.putc(*ptr++); } } } }