static void info_reply_rotation(lo_address *to, sosc_state_t *state) { if( monome_get_cols(state->monome) != monome_get_rows(state->monome) ) info_reply_size(to, state); lo_send_from(to, state->server, LO_TT_IMMEDIATE, "/sys/rotation", "i", monome_get_rotation(state->monome) * 90); }
static int proto_series_led_row(monome_t *monome, uint_t x_off, uint_t y, size_t count, const uint8_t *data) { uint16_t sdata; switch( ((monome_get_cols(monome) > 8) << 1) | (count > 1)) { case 0x0: /* 1-byte monome, 1-byte message */ case 0x1: /* 1-byte monome, 2-byte message */ return proto_series_led_col_row_8( monome, PROTO_SERIES_LED_ROW_8, y, data); case 0x2: /* 2-byte monome, 1-byte message */ sdata = *data; return proto_series_led_col_row_16( monome, PROTO_SERIES_LED_ROW_16, y, ((const uint8_t *) &sdata)); case 0x3: /* 2-byte monome, 2-byte message */ return proto_series_led_col_row_16( monome, PROTO_SERIES_LED_ROW_16, y, data); } return -1; }
int main(int argc, char *argv[]) { char c, *device, *sport, *aport, *ahost; monome_rotate_t rotate = MONOME_ROTATE_0; int i; struct option arguments[] = { {"help", no_argument, 0, 'h'}, {"device", required_argument, 0, 'd'}, {"server-port", required_argument, 0, 's'}, {"application-port", required_argument, 0, 'a'}, {"application-host", required_argument, 0, 'o'}, {"rotation", required_argument, 0, 'r'} }; device = DEFAULT_MONOME_DEVICE; sport = DEFAULT_OSC_SERVER_PORT; aport = DEFAULT_OSC_APP_PORT; ahost = DEFAULT_OSC_APP_HOST; while( (c = getopt_long(argc, argv, "hd:s:a:o:r:", arguments, &i)) > 0 ) { switch( c ) { case 'h': usage(argv[0]); return 1; case 'd': device = optarg; break; case 's': if( is_numstr(optarg) ) sport = optarg; else printf("warning: \"%s\" is not a valid server port.\n", optarg); break; case 'a': if( is_numstr(optarg) ) aport = optarg; else printf("warning: \"%s\" is not a valid application port.\n", optarg); break; case 'o': ahost = optarg; break; case 'r': switch(*optarg) { case 'l': case '0': rotate = MONOME_ROTATE_0; break; case 't': case '9': rotate = MONOME_ROTATE_90; break; case 'r': case '1': rotate = MONOME_ROTATE_180; break; case 'b': case '2': rotate = MONOME_ROTATE_270; break; } break; } } if( optind == argc ) state.lo_prefix = m_strdup(DEFAULT_OSC_PREFIX); else state.lo_prefix = m_strdup(argv[optind]); if( !(state.monome = monome_open(device)) ) { printf("failed to open %s\n", device); return EXIT_FAILURE; } if( !(state.server = lo_server_new(sport, lo_error)) ) return EXIT_FAILURE; state.outgoing = lo_address_new(ahost, aport); monome_register_handler(state.monome, MONOME_BUTTON_DOWN, monome_handle_press, state.lo_prefix); monome_register_handler(state.monome, MONOME_BUTTON_UP, monome_handle_press, state.lo_prefix); register_osc_methods(state.lo_prefix, state.monome); monome_set_rotation(state.monome, rotate); monome_led_all(state.monome, 0); printf("monomeserial version %s, yay!\n\n", VERSION); printf("initialized device %s at %s, which is %dx%d\n", monome_get_serial(state.monome), monome_get_devpath(state.monome), monome_get_rows(state.monome), monome_get_cols(state.monome)); printf("running with prefix /%s\n\n", state.lo_prefix); /* main_loop() returns 1 if the monome was disconnected */ if( main_loop() ) printf("%s disconnected, monomeserial exiting.\nsee you later!\n\n", monome_get_devpath(state.monome)); monome_close(state.monome); unregister_osc_methods(state.lo_prefix); m_free(state.lo_prefix); lo_address_free(state.outgoing); lo_server_free(state.server); return EXIT_SUCCESS; }
} #define DECLARE_INFO_HANDLERS(prop)\ OSC_HANDLER_FUNC(sys_info_##prop##_handler) {\ return info_prop_handler(argv, argc, user_data, info_reply_##prop);\ }\ OSC_HANDLER_FUNC(sys_info_##prop##_handler_default) {\ return info_prop_handler_default(user_data, info_reply_##prop);\ } #define DECLARE_INFO_PROP(prop, typetag, ...)\ DECLARE_INFO_REPLY_FUNC(prop, typetag, __VA_ARGS__)\ DECLARE_INFO_HANDLERS(prop) DECLARE_INFO_PROP(id, "s", monome_get_serial(state->monome)) DECLARE_INFO_PROP(size, "ii", monome_get_cols(state->monome), monome_get_rows(state->monome)) DECLARE_INFO_PROP(host, "s", lo_address_get_hostname(state->outgoing)) DECLARE_INFO_PROP(port, "i", atoi(lo_address_get_port(state->outgoing))) DECLARE_INFO_PROP(prefix, "s", state->config.app.osc_prefix) static void info_reply_rotation(lo_address *to, sosc_state_t *state) { if (monome_get_cols(state->monome) != monome_get_rows(state->monome)) info_reply_size(to, state); lo_send_from(to, state->server, LO_TT_IMMEDIATE, "/sys/rotation", "i", monome_get_rotation(state->monome) * 90); }