Example #1
0
int test_config(void) {
	printf("\n\tTouch in the mouse\n\n");
	unsigned long data, res;
	unsigned char a[3];
	mouse_subscribe();
	mouse_write(MOUSE_STATUS);
	mouse_read(&data);
	while (1) {
		mouse_read(&data);
		if ((BIT(7) & data) && (BIT(3) & res))
			break;
	}
	a[0] = data;
	while (1) {
		mouse_read(&data);
		if (data <= 3)
			break;
	}
	a[1] = data;
	tickdelay(micros_to_ticks(DELAY_US));
	if (mouse_read(&data) != 0)
		return -1;
	a[2] = data;
	printf("\n\tCONFIGURATION\n");
	printf(
			"\tMode: %s\n\tEnable: %d\n\tScaling: %s\n\tLB: %d\n\tMB: %d\n\tRB: %d\n\tResolution: %d count/mm\n\tSample Rate: %d\n",
			MODE(a[0]) ? "Remote" : "Stream", ENABLE(a[0]),
			SCALING(a[0]) ? "1:1" : "2:1", LEFT(a[0]), MIDDLE(a[0]),
			RIGHT(a[0]), RESOLUTION(a[1]), RATE(a[2]));
	mouse_unsubscribe();
	printf("\n\tpress ANY KEY to continue\n");
	mouse_read(&res); /* clear out buffer */
}
void ternary_sift_down(void *base,
                       size_t start,
                       size_t size,
                       size_t max_index,
                       compare_fun3 compare,
                       void *arg) {
  size_t root = start;
  while (TRUE) {
    size_t left_child = LEFT(root);
    if (left_child > max_index) {
      break;
    }
    void *root_ptr = POINTER(base, root, size);
    size_t swap = root;
    void *swap_ptr = root_ptr;
    void *left_child_ptr = POINTER(base, left_child, size);
    if (compare(swap_ptr, left_child_ptr, arg) < 0) {
      swap = left_child;
      swap_ptr = left_child_ptr;
    }
    size_t middle_child = MIDDLE(root);
    size_t right_child = RIGHT(root);
    if (middle_child <= max_index) {
      void *middle_child_ptr = POINTER(base, middle_child, size);
      if (compare(swap_ptr, middle_child_ptr, arg) < 0) {
        swap = middle_child;
        swap_ptr = middle_child_ptr;
      }
      if (right_child <= max_index) {
        void *right_child_ptr = POINTER(base, right_child, size);
        if (compare(swap_ptr, right_child_ptr, arg) < 0) {
          swap = right_child;
          swap_ptr = right_child_ptr;
        }
      }
    }

    if (swap != root) {
      swap_elements(root_ptr, swap_ptr, size);
      root = swap;
      root_ptr = swap_ptr;
    } else {
      return;
    }
  }
}