Exemple #1
0
int
fifo_num_rem(struct fifo_list *f, unsigned num, TYPE **data)
{
	unsigned	count, pos, start, end;
	TYPE		**ldata;

	if (num == 0)
		return fifo_pop(f, data);

	count = FIFO_COUNT(f);
	if (num > count) {
		errno = ENOENT;
		return -1;
	}

	pos = (num + f->fifo_start) % f->fifo_size;
	start = f->fifo_start;
	end = f->fifo_end;
	ldata = f->fifo_data;
	
	if (start < pos) {
		(void)memmove(ldata + start + 1, ldata + start,
			FIFO_DATA_SIZE(pos - start));
		f->fifo_start++;
	} else {
		(void)memmove(ldata + pos, ldata + pos + 1, FIFO_DATA_SIZE(end - pos));
		f->fifo_end--;
	}
	if (FIFO_COUNT(f) < (f->fifo_size / 2))
		fifo_decr(f);
	return 0;
}
Exemple #2
0
static void
fifo_decr(struct fifo_list *f)
{
	void		**p;
	unsigned	start, end, size;

	if (f->fifo_size == FIFO_CHUNK)
		return;
	start = f->fifo_start; end = f->fifo_end; size = f->fifo_size / 2;
	if ((p = malloc(FIFO_DATA_SIZE(size))) == NULL)
		return;
	if (f->fifo_start < f->fifo_end) {
		/* copy from start to end */
		(void)memcpy(p, f->fifo_data + start, FIFO_DATA_SIZE(end - start));

	} else if (f->fifo_start > f->fifo_end) {
		/* copy from start to end of buffer */
		(void)memcpy(p, f->fifo_data + start, FIFO_DATA_SIZE(size - start));

		/* copy from beginning of buffer to end */
		(void)memcpy(p + size - start, f->fifo_data, FIFO_DATA_SIZE(end));
	}
	start = 0; end = FIFO_COUNT(f);
	free(f->fifo_data);
	f->fifo_data = p; f->fifo_start = start;
	f->fifo_end = end; f->fifo_size = size;
}
Exemple #3
0
uint16_t get_pitch_event(void) {
	if (FIFO_COUNT(pitch_events) != 0) {
		uint16_t event = FIFO_FRONT(pitch_events);
		FIFO_POP(pitch_events);
		return event + 1;
	} else {
		return 0;
	}
}
Exemple #4
0
uint16_t get_slider_event(void) {
	if (FIFO_COUNT(sliders_events) != 0) {
		uint16_t event = FIFO_FRONT(sliders_events);
		FIFO_POP(sliders_events);
		//event maybe = 0, so this is for correct sending
		return event + 1;
	} else {
		return 0;
	}
}
Exemple #5
0
int
fifo_push(struct fifo_list *f, TYPE *data)
{
	if (FIFO_COUNT(f) == (f->fifo_size - 1))
		if (fifo_incr(f) < 0)
			return -1;

	f->fifo_data[f->fifo_end] = data;
	f->fifo_end = (f->fifo_end + 1) % f->fifo_size;
	return 0;
}
void usb_midi_refresh(void){
	uint32_t buf[128];
	uint8_t count=FIFO_COUNT(USB_midi_packets_in);
	if (count && USB_transferPossible){
	    for (uint8_t i=0; i<count; i++){
	    	buf[i]=FIFO_FRONT(USB_midi_packets_in);
	    	FIFO_POP(USB_midi_packets_in);
	    }
		DCD_EP_Tx(&USB_OTG_dev, MIDI_IN_EP, (uint8_t*)buf, count<<2);
	}
}
Exemple #7
0
int
fifo_pop(struct fifo_list *f, TYPE **data)
{
	if (f == NULL || f->fifo_start == f->fifo_end) {
		errno = ENOENT;
		return -1;
	}
	*data = f->fifo_data[f->fifo_start];
	f->fifo_start = (f->fifo_start + 1) % f->fifo_size;
	if (FIFO_COUNT(f) < ((f->fifo_size - 1) / 2))
		fifo_decr(f);
	return 0;
}
Exemple #8
0
int
fifo_num_peek(struct fifo_list *f, unsigned num, TYPE **data)
{
	unsigned	count;

	count = FIFO_COUNT(f);
	if (num > count) {
		errno = ENOENT;
		return -1;
	}
	if (data != NULL)
		*data = f->fifo_data[(num + f->fifo_start) % f->fifo_size];
	return 0;
}
Exemple #9
0
/* XXX the following four functions are not tested, may not work */
int
fifo_find_peek(struct fifo_list *f, TYPE **data, unsigned *num,
	fifo_find_f find_fun, TYPE *comp_obj)
{
	unsigned	i, j, count;

	count = FIFO_COUNT(f);
	for (i = j = 0; j < count; j++, i = (i + 1) % f->fifo_size) {
		if (find_fun(f->fifo_data[i], comp_obj)) {
			if (data != NULL)
				*data = f->fifo_data[i];
			if (num != NULL)
				*num = j;
			return 0;
		}
	}
	errno = ENOENT;
	return -1;
}
Exemple #10
0
void checkButtons_events(Button_type* buttons, uint8_t analog) {
	uint8_t event;

	if (FIFO_COUNT(control_events) == 0)
		return; //No events

	event = FIFO_FRONT(control_events);
	FIFO_POP(control_events);

	uint8_t btn_num = event & 0x7F;

	//messages has number > ENCODER_LEFT1
	//so messages sends to menu_btns_n_msg_handler
	if (btn_num == BUTTON_PANIC) {
		if (!(event & 0x80))
			sendPanic(analog);
	} else if (btn_num <= BUTTON_RIGHT || btn_num >= ENCODER_LEFT1 || buttonsToMenu) {
		if (!(event & 0x80))
		   menu_btns_n_msg_handler(event);
	} else {
		button_midi_send(event, buttons, analog);
	}
}
Exemple #11
0
unsigned
fifo_count(struct fifo_list *f)
{
	return FIFO_COUNT(f);
}