mirror of
https://github.com/eddyem/stm32samples.git
synced 2026-03-22 01:31:21 +03:00
change pl2303 snippet (add decimal input)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* This file is part of the pl2303 project.
|
||||
* This file is part of the si7005 project.
|
||||
* Copyright 2020 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
@@ -21,6 +21,8 @@
|
||||
#include "usb.h"
|
||||
#include "usb_lib.h"
|
||||
|
||||
#define USBBUFSZ 127
|
||||
|
||||
volatile uint32_t Tms = 0;
|
||||
|
||||
/* Called when systick fires */
|
||||
@@ -30,20 +32,21 @@ void sys_tick_handler(void){
|
||||
|
||||
// usb getline
|
||||
char *get_USB(){
|
||||
static char tmpbuf[512], *curptr = tmpbuf;
|
||||
static int rest = 511;
|
||||
uint8_t x = USB_receive((uint8_t*)curptr);
|
||||
static char tmpbuf[USBBUFSZ+1], *curptr = tmpbuf;
|
||||
static int rest = USBBUFSZ;
|
||||
int x = USB_receive(curptr);
|
||||
curptr[x] = 0;
|
||||
if(!x) return NULL;
|
||||
if(curptr[x-1] == '\n'){
|
||||
curptr = tmpbuf;
|
||||
rest = 511;
|
||||
rest = USBBUFSZ;
|
||||
return tmpbuf;
|
||||
}
|
||||
curptr += x; rest -= x;
|
||||
if(rest <= 0){ // buffer overflow
|
||||
curptr = tmpbuf;
|
||||
rest = 511;
|
||||
rest = USBBUFSZ;
|
||||
USB_send("USB buffer overflow\n");
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -76,7 +79,7 @@ int main(void){
|
||||
if(ans){
|
||||
uint16_t l = 0; char *p = ans;
|
||||
while(*p++) l++;
|
||||
USB_send((uint8_t*)ans, l);
|
||||
USB_send(ans);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user