Exemplo n.º 1
0
static
void
handle_client(int client_socket) {
	uint8_t cmd;

	double bright;

	pos_t pos;
	col_t col;

	col_t pixels[64];
	
	int x, y;

	while (true) {
		recv_or_return(client_socket, &cmd, sizeof(char), 0);

		switch (cmd) {
			case UNICORND_CMD_SET_BRIGHTNESS:

				recv_or_return(client_socket, &bright, sizeof(double), 0);

				setBrightness(bright);
				break;

			case UNICORND_CMD_SET_PIXEL:

				recv_or_return(client_socket, &pos, sizeof(pos_t), 0);
				recv_or_return(client_socket, &col, sizeof(col_t), 0);

				setPixelColor(get_pixel_pos(pos.x, pos.y), col.r, col.g, col.b);
				break;

			case UNICORND_CMD_SET_ALL_PIXELS:
				recv_or_return(client_socket, &pixels, 64 * sizeof(col_t), 0);

				for (x = 0; x < 8; x++) {
					for (y = 0; y < 8; y++) {
						col_t *col = &pixels[x * 8 + y];
						setPixelColor(get_pixel_pos(x, y), col->r, col->g, col->b);
					}
				}

				break;

			case UNICORND_CMD_SHOW:

				show();
				break;

			default:

				close(client_socket);
				return;
		}
	}
}
Exemplo n.º 2
0
void matrix_set(int x, int y, ws2811_led_t colour) {
  if (x >= 0 && x < WIDTH && y >= 0 && y < WIDTH) {
    leds.channel[0].leds[get_pixel_pos(x,y)] = colour;
  }
}