/* main entry point */ int main(int argc, char *argv[]) { int ret; /* init the default settings */ struct settings_t settings; settings.gpio_base = 55; settings.gpio_count = MAX_GPIO_COUNT; settings.loop = 0; settings.poll = 0; settings.poll_timeout = -1; print_info(); /* parse the cmdline arguments */ handle_parameters(argc, argv, &settings); /* initialize the gpio file names */ init_gpio_filenames(settings.gpio_base, settings.gpio_count, settings.gpio_filenames); /* read the gpios */ read_gpios(settings.gpio_count, settings.gpio_states, settings.gpio_filenames); /* print the states of the gpios */ printf("initial values:\n"); print_gpios(settings.gpio_base, settings.gpio_count, settings.gpio_states); printf("\n"); /* keep reading gpios cpu intensive in a tight loop */ if (settings.loop) enter_read_gpios_loop(settings.gpio_base, settings.gpio_count, settings.gpio_states, settings.gpio_filenames); /* poll the gpios once */ if (settings.poll) { init_gpio_edges(settings.gpio_base, settings.gpio_count, settings.gpio_edge_filenames); if (read_edges(settings.gpio_count, settings.gpio_edge_values, settings.gpio_edge_filenames)) if (validate_edges(settings.gpio_base, settings.gpio_count, settings.gpio_edge_values)) enter_poll_gpios(settings.gpio_base, settings.gpio_count, settings.poll_timeout, settings.gpio_states, settings.gpio_filenames); } }
static void _generate_edges(uint8_t * edgesOut, int cornerParity) { Perm * p = rand_perm(12); if (perm_parity(p) != cornerParity) { rand_change_parity(p); } uint16_t edgeOrientations = 0; int i; for (i = 0; i < 12; i++) { int piece = p->map[i]; int s1, s2; cube_perm_edge_symmetries(piece, i, &s1, &s2); int sym = rand() % 2 == 0 ? s1 : s2; edgesOut[i] = piece | (sym << 4); if (i == 11) { if (!validate_edges(edgesOut)) { int newSym = sym == s1 ? s2 : s1; edgesOut[i] = piece | (newSym << 4); } } } perm_free(p); }