You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
989 B
54 lines
989 B
#include "buffer.h"
|
|
|
|
uint8_t buff_empty=1;
|
|
static uint8_t buff_start;
|
|
static uint8_t buff_end;
|
|
|
|
static uint8_t buffer[BUFFER_SIZE];
|
|
|
|
uint8_t readBuffer(void){
|
|
uint8_t ret;
|
|
if(buff_empty){
|
|
return 0;
|
|
}
|
|
ret=buffer[buff_end];
|
|
buff_end++;
|
|
if(buff_end==BUFFER_SIZE){
|
|
buff_end=0;
|
|
}
|
|
if(buff_end==buff_start){
|
|
buff_empty=1;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
void writeToBuffer(uint8_t data){
|
|
if(buff_start==buff_end && !buff_empty){
|
|
/*overrun*/
|
|
return;
|
|
}
|
|
buffer[buff_start]=data;
|
|
buff_start++;
|
|
if(buff_start==BUFFER_SIZE){
|
|
buff_start=0;
|
|
}
|
|
buff_empty=0;
|
|
}
|
|
|
|
void buffer_unum(uint32_t num){
|
|
uint8_t text[8] = {0,0,0,0,0,0,0,0};
|
|
uint8_t i;
|
|
|
|
for(i=1;i<=8;i++){
|
|
/*calculate scancode from digit*/
|
|
text[8-i] = USB_KEY_1-1+((num)%10);
|
|
if(text[8-i]==USB_KEY_1-1){
|
|
text[8-i]=USB_KEY_0;
|
|
}
|
|
num/=10;
|
|
}
|
|
for(i=0;i<8;i++){
|
|
writeToBuffer(text[i]);
|
|
}
|
|
}
|
|
|
|
|