change pl2303 snippet (add decimal input)

This commit is contained in:
Edward Emelianov
2021-02-09 22:47:26 +03:00
parent ad5e9d5abf
commit bec96d03fa
25 changed files with 1581 additions and 52 deletions

View File

@@ -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);
}
}
}