static int proto_tinycyst_next_event(monome_t *monome, monome_event_t *e) { uint8_t buf[2] = {0, 0}; if( monome_platform_read(monome, buf, sizeof(buf)) < sizeof(buf) ) return 0; //outputHex((const uint8_t*) &buf, (ssize_t) 2); switch( buf[0] ) { case PROTO_TINYCYST_BUTTON_DOWN: case PROTO_TINYCYST_BUTTON_UP: e->event_type = (buf[0] == PROTO_TINYCYST_BUTTON_DOWN) ? MONOME_BUTTON_DOWN : MONOME_BUTTON_UP; e->grid.x = buf[1] >> 4; e->grid.y = buf[1] & 0x0F; UNROTATE_COORDS(monome, e->grid.x, e->grid.y); return 1; case PROTO_TINYCYST_KNOB: e->event_type = MONOME_ADC_CHANGE; e->adc.number = buf[0] & 0x0F; e->adc.value = buf[1]; return 1; } return 0; }
static ssize_t mext_read_msg(monome_t *monome, mext_msg_t *msg) { size_t payload_length; monome_platform_read(monome, &msg->header, 1); msg->addr = msg->header >> 4; msg->cmd = msg->header & 0xF; payload_length = incoming_payload_lengths[msg->addr][msg->cmd]; if( !payload_length ) return 1; if( monome_platform_read(monome, (uint8_t *) &msg->payload, payload_length) != payload_length ) return 0; return 1 + payload_length; }
static int proto_chronome_next_event(monome_t *monome, monome_event_t *e) { uint8_t buf[3] = {0, 0, 0}; if( monome_platform_read(monome, buf, sizeof(buf)) != sizeof(buf) ) return 0; //outputHex((const uint8_t*) &buf, (ssize_t) 2); switch( buf[0] & 0xF0 ) { case PROTO_CHRONOME_PRESSURE: e->event_type = MONOME_PRESSURE; e->pressure.x = buf[0] & 0x0F; e->pressure.y = buf[1] >> 4; e->pressure.value = ((buf[1] & 0x03) << 8) | buf[2]; UNROTATE_COORDS(monome, e->pressure.x, e->pressure.y); // **** // lets also send out button Down/Up as we cross over zero // **** //TODO: Maybe this could be better? Possibly a schmidt trigger // would be cleaner? // set current button state if(e->pressure.value >= MONOME_CHRONOME_T(monome)->threshold && MONOME_CHRONOME_T(monome)->button_current[e->pressure.x][e->pressure.y] != 1) { //fprintf(stderr, "press Down\n"); MONOME_CHRONOME_T(monome)->button_current[e->pressure.x][e->pressure.y] = 1; e->event_type = MONOME_BUTTON_DOWN; e->grid.x = e->pressure.x; e->grid.y = e->pressure.y; } else if (e->pressure.value < MONOME_CHRONOME_T(monome)->threshold && MONOME_CHRONOME_T(monome)->button_current[e->pressure.x][e->pressure.y] != 0) { //fprintf(stderr, "press Up\n"); MONOME_CHRONOME_T(monome)->button_current[e->pressure.x][e->pressure.y] = 0; e->event_type = MONOME_BUTTON_UP; e->grid.x = e->pressure.x; e->grid.y = e->pressure.y; } return 1; } return 0; }
static int proto_series_next_event(monome_t *monome, monome_event_t *e) { uint8_t buf[2] = {0, 0}; if( monome_platform_read(monome, buf, sizeof(buf)) != sizeof(buf) ) return 0; switch( buf[0] ) { case PROTO_SERIES_BUTTON_DOWN: case PROTO_SERIES_BUTTON_UP: e->event_type = (buf[0] == PROTO_SERIES_BUTTON_DOWN) ? MONOME_BUTTON_DOWN : MONOME_BUTTON_UP; e->grid.x = buf[1] >> 4; e->grid.y = buf[1] & 0x0F; UNROTATE_COORDS(monome, e->grid.x, e->grid.y); return 1; case PROTO_SERIES_TILT: SERIES_T(monome)->tilt.x = buf[1]; goto tilt_common; /* shut up okay */ case PROTO_SERIES_TILT + 1: SERIES_T(monome)->tilt.y = buf[1]; tilt_common: /* I SAID SHUT UP */ e->event_type = MONOME_TILT; e->tilt.sensor = 0; e->tilt.x = SERIES_T(monome)->tilt.x; e->tilt.y = SERIES_T(monome)->tilt.y; e->tilt.z = 0; return 1; case PROTO_SERIES_AUX_INPUT: /* soon */ return 0; } return 0; }
static int proto_series_next_event(monome_t *monome, monome_event_t *e) { uint8_t buf[2] = {0, 0}; if( monome_platform_read(monome, buf, sizeof(buf)) < sizeof(buf) ) return 0; switch( buf[0] ) { case PROTO_SERIES_BUTTON_DOWN: case PROTO_SERIES_BUTTON_UP: e->event_type = (buf[0] == PROTO_SERIES_BUTTON_DOWN) ? MONOME_BUTTON_DOWN : MONOME_BUTTON_UP; e->x = buf[1] >> 4; e->y = buf[1] & 0x0F; UNROTATE_COORDS(monome, e->x, e->y); return 1; case PROTO_SERIES_AUX_INPUT: /* soon */ return 0; } return 0; }