static uint8_t PrintStatus(const CLS1_StdIOType *io) { uint8_t buf[64], buf2[16]; QuadTime_t timing; int i; CLS1_SendStatusStr((unsigned char*)"quadcalib", (unsigned char*)"\r\n", io->stdOut); for(i=0; i<NOF_SIGNALS; i++) { if (Measure(i, &timing)==ERR_OK) { buf[0] = '\0'; UTIL1_strcatNum8u(buf, sizeof(buf), timing.lowPercent); UTIL1_strcat(buf, sizeof(buf), (uint8_t*)"% to "); UTIL1_strcatNum8u(buf, sizeof(buf), timing.highPercent); UTIL1_strcat(buf, sizeof(buf), (uint8_t*)"%, "); UTIL1_strcat(buf, sizeof(buf), (uint8_t*)"high: "); UTIL1_strcatNum32u(buf, sizeof(buf), timing.highTicks); UTIL1_strcat(buf, sizeof(buf), (uint8_t*)" ticks, low: "); UTIL1_strcatNum32u(buf, sizeof(buf), timing.lowTicks); UTIL1_strcat(buf, sizeof(buf), (uint8_t*)" ticks\r\n"); } else { UTIL1_strcpy(buf, sizeof(buf), (uint8_t*)"TIMEOUT\r\n"); } if (i==0) { UTIL1_strcpy(buf2, sizeof(buf2), (uint8_t*)" Right A,C0"); } else if (i==1) { UTIL1_strcpy(buf2, sizeof(buf2), (uint8_t*)" Right B,C1"); } else if (i==2) { UTIL1_strcpy(buf2, sizeof(buf2), (uint8_t*)" Left C,C2"); } else { UTIL1_strcpy(buf2, sizeof(buf2), (uint8_t*)" Left D,C3"); } CLS1_SendStatusStr(buf2, buf, io->stdOut); } return ERR_OK; }
void APP_Run(void) { int i; uint32_t val = 0; unsigned char buf[16]; for(;;) { while(CDC1_App_Task(cdc_buffer, sizeof(cdc_buffer))==ERR_BUSOFF) { /* device not enumerated */ LED1_Neg(); LED2_Off(); WAIT1_Waitms(10); } LED2_Off(); LED1_Neg(); if (CDC1_GetCharsInRxBuf()!=0) { i = 0; while( i<sizeof(in_buffer)-1 && CDC1_GetChar(&in_buffer[i])==ERR_OK ) { i++; } in_buffer[i] = '\0'; (void)CDC1_SendString((unsigned char*)"echo: "); (void)CDC1_SendString(in_buffer); UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)"val: "); UTIL1_strcatNum32u(buf, sizeof(buf), val); UTIL1_strcat(buf, sizeof(buf), (unsigned char*)"\r\n"); (void)CDC1_SendString(buf); val++; } else { WAIT1_Waitms(10); } } }
static void CDC_Run(void) { int i, cnt = 0; uint32_t val = 0; unsigned char buf[16]; (void)CDC1_SendString((unsigned char*)"Hello world from the KL25Z with USB CDC\r\n"); for(;;) { while(CDC1_App_Task(cdc_buffer, sizeof(cdc_buffer))==ERR_BUSOFF) { /* device not enumerated */ LED1_Neg(); LED2_Off(); WAIT1_Waitms(10); cnt++; if (cnt==100) { LED3_Neg(); cnt = 0; } } LED1_Off(); LED2_Neg(); LED3_Off(); if (CDC1_GetCharsInRxBuf()!=0) { i = 0; while( i<sizeof(in_buffer)-1 && CDC1_GetChar(&in_buffer[i])==ERR_OK ) { i++; } in_buffer[i] = '\0'; (void)CDC1_SendString((unsigned char*)"echo: "); (void)CDC1_SendString(in_buffer); UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)"val: "); UTIL1_strcatNum32u(buf, sizeof(buf), val); UTIL1_strcat(buf, sizeof(buf), (unsigned char*)"\r\n"); (void)CDC1_SendString(buf); val++; } else { WAIT1_Waitms(10); cnt++; if ((cnt%1024)==0) { /* from time to time, write some text */ (void)CDC1_SendString((unsigned char*)"Type some text and it will echo.\r\n"); } } } }
static void CDC_Run(void) { unsigned char buf[32]; for(;;) { while(CDC1_App_Task(cdc_buffer, sizeof(cdc_buffer))==ERR_BUSOFF) { /* device not enumerated */ LEDR_Neg(); LEDG_Off(); WAIT1_Waitms(10); } LEDR_Off(); LEDG_Neg(); if (CDC1_GetCharsInRxBuf()!=0) { CDC1_ClearRxBuffer(); /* discard incoming buffer */ UTIL1_strcpy(buf, sizeof(buf), (unsigned char*)"time on hours: "); UTIL1_strcatNum32u(buf, sizeof(buf), Time_On_Hours); UTIL1_strcat(buf, sizeof(buf), (unsigned char*)"\r\n"); (void)CDC1_SendString(buf); Time_On_Hours++; } else { WAIT1_Waitms(10); } } }