예제 #1
0
static int proto_series_led_set(monome_t *monome, uint_t x, uint_t y, uint_t on) {
	uint8_t buf[2];

	ROTATE_COORDS(monome, x, y);

	buf[0] = PROTO_SERIES_LED_ON + (!on << 4);
	buf[1] = (x << 4) | y;

	return monome_write(monome, buf, sizeof(buf));
}
예제 #2
0
static int proto_chronome_led_set(monome_t *monome, uint_t x, uint_t y, uint_t on) {
    uint8_t buf[2];

	ROTATE_COORDS(monome, x, y);

    x &= 0x7;
	y &= 0x7;

	buf[0] = 0x80 | (PROTO_CHRONOME_LED_ON + !on);
	buf[1] = 0x7F & ((x << 4) | y);

	return monome_write(monome, buf, sizeof(buf));
}
예제 #3
0
static int proto_series_led_col_row_8(monome_t *monome,
                                      proto_series_message_t mode,
                                      uint_t address, const uint8_t *data) {
	uint8_t buf[2] = {0, 0};
	uint_t xaddress = address;

	/* I guess this is a bit of a hack...but damn does it work well!

	   treating the address as a coordinate pair with itself lets us calculate
	   the row/col translation in one call using the existing rotation code
	   then we just pick whether we want the x coord (row) or y coord (col)
	   depending on what sort of message it is. */

	ROTATE_COORDS(monome, xaddress, address);

	switch( mode ) {
	case PROTO_SERIES_LED_ROW_8:
		if( ROTSPEC(monome).flags & ROW_COL_SWAP )
			address = xaddress;

		if( ROTSPEC(monome).flags & ROW_REVBITS )
			buf[1] = REVERSE_BYTE(*data);
		else
			buf[1] = *data;

		break;

	case PROTO_SERIES_LED_COL_8:
		if( !(ROTSPEC(monome).flags & ROW_COL_SWAP) )
			address = xaddress;

		if( ROTSPEC(monome).flags & COL_REVBITS )
			buf[1] = REVERSE_BYTE(*data);
		else
			buf[1] = *data;

		break;

	default:
		return -1;
	}

	if( ROTSPEC(monome).flags & ROW_COL_SWAP )
		mode = (!(mode - PROTO_SERIES_LED_ROW_8) << 4) + PROTO_SERIES_LED_ROW_8;

	buf[0] = mode | (address & 0x0F );

	return monome_write(monome, buf, sizeof(buf));
}
예제 #4
0
static int proto_chronome_led_color_set(monome_t *monome, uint_t x, uint_t y,
		uint_t r, uint_t g, uint_t b)
{

    ROTATE_COORDS(monome, x, y);

	uint8_t buf[5];

	buf[0] = 0x80 | PROTO_CHRONOME_LED_COLOR;
	buf[1] = 0x7F & ((x << 4) | y);

	buf[2] = 0x7F & (uint8_t)r;
	buf[3] = 0x7F & (uint8_t)g;
	buf[4] = 0x7F & (uint8_t)b;

	return monome_write(monome, buf, sizeof(buf));
}
예제 #5
0
파일: series.c 프로젝트: dext3r/wifi_monome
static int proto_series_led_col_row_16(monome_t *monome, proto_series_message_t mode, uint_t address, const uint8_t *data) {
	uint8_t buf[3] = {0, 0, 0};
	uint_t xaddress = address;

	ROTATE_COORDS(monome, xaddress, address);

	switch( mode ) {
	case PROTO_SERIES_LED_ROW_16:
		address = xaddress;

		if( ROTSPEC(monome).flags & ROW_REVBITS ) {
			buf[1] = REVERSE_BYTE(data[1]);
			buf[2] = REVERSE_BYTE(data[0]);
		} else {
			buf[1] = data[0];
			buf[2] = data[1];
		}

		break;

	case PROTO_SERIES_LED_COL_16:
		if( ROTSPEC(monome).flags & COL_REVBITS ) {
			buf[1] = REVERSE_BYTE(data[1]);
			buf[2] = REVERSE_BYTE(data[0]);
		} else {
			buf[1] = data[0];
			buf[2] = data[1];
		}

		break;

	default:
		return -1;
	}

	if( ROTSPEC(monome).flags & ROW_COL_SWAP )
		mode = (!(mode - PROTO_SERIES_LED_ROW_16) << 4) + PROTO_SERIES_LED_ROW_16;

	buf[0] = mode | (address & 0x0F );

	return monome_write(monome, buf, sizeof(buf));
}
예제 #6
0
static int proto_series_led_map(monome_t *monome, uint_t x_off, uint_t y_off,
                                const uint8_t *data) {
	uint8_t buf[9];
	uint_t quadrant;

	/* by treating data as a bigger integer, we can copy it in
	   one or two operations (instead of 8) */
#ifdef __LP64__
	*((uint64_t *) &buf[1]) = *((uint64_t *) data);
#else
	*((uint32_t *) &buf[1]) = *((uint32_t *) data);
	*((uint32_t *) &buf[5]) = *(((uint32_t *) data) + 1);
#endif

	ROTSPEC(monome).map_cb(monome, &buf[1]);

	ROTATE_COORDS(monome, x_off, y_off);
	quadrant = (x_off / 8) + ((y_off / 8) * 2);

	buf[0] = PROTO_SERIES_LED_FRAME | (quadrant & 0x03);

	return monome_write(monome, buf, sizeof(buf));
}
예제 #7
0
static int proto_chronome_led_col_row(monome_t *monome, proto_chronome_message_t mode, uint_t address, const uint8_t *data) {
	uint8_t buf[2];
	uint_t xaddress = address;

    ROTATE_COORDS(monome, xaddress, address);

    switch( mode ) {
        case PROTO_CHRONOME_LED_ROW:
            address = xaddress;

            if( ROTSPEC(monome).flags & ROW_REVBITS )
                buf[1] = REVERSE_BYTE(*data);
            else
                buf[1] = *data;

            break;

        case PROTO_CHRONOME_LED_COL:

            if( ROTSPEC(monome).flags & COL_REVBITS )
                buf[1] = REVERSE_BYTE(*data);
            else
                buf[1] = *data;

            break;

        default:
            return -1;
	}

    if( ROTSPEC(monome).flags & ROW_COL_SWAP )
        mode = !(mode - PROTO_CHRONOME_LED_ROW) + PROTO_CHRONOME_LED_ROW;

	buf[0] = 0x80 | ((address & 0x7 ) << 4) | mode;

    return monome_write(monome, buf, sizeof(buf));
}