/* Come out of standby mode. */ void lb_on(void) { CPRINTS("LB_on"); i2c_lock(I2C_PORT_LIGHTBAR, 1); controller_write(0, 0x01, 0x20); controller_write(1, 0x01, 0x20); i2c_lock(I2C_PORT_LIGHTBAR, 0); }
static void set_from_array(const struct initdata_s *data, int count) { int i; for (i = 0; i < count; i++) { controller_write(0, data[i].reg, data[i].val); controller_write(1, data[i].reg, data[i].val); } }
/* Helper function to set one LED color and remember it for later */ static void setrgb(int led, int red, int green, int blue) { int ctrl, bank; current[led][0] = red; current[led][1] = green; current[led][2] = blue; ctrl = led_to_ctrl[led]; bank = led_to_isc[led]; controller_write(ctrl, bank, scale(blue, MAX_BLUE)); controller_write(ctrl, bank+1, scale(red, MAX_RED)); controller_write(ctrl, bank+2, scale(green, MAX_GREEN)); }
/* Initialize the controller ICs after reset */ void lb_init(int use_lock) { int i; CPRINTF("[%T LB_init_vals "); for (i = 0; i < ARRAY_SIZE(init_vals); i++) { CPRINTF("%c", '0' + i % 10); if (use_lock) i2c_lock(I2C_PORT_LIGHTBAR, 1); controller_write(0, init_vals[i].reg, init_vals[i].val); controller_write(1, init_vals[i].reg, init_vals[i].val); if (use_lock) i2c_lock(I2C_PORT_LIGHTBAR, 0); } CPRINTF("]\n"); memset(current, 0, sizeof(current)); }
/* * This sets up the auto-cycling features of the controllers to make a * semi-random pattern of slowly fading colors. This is interesting only * because it doesn't require any effort from the EC. */ void lb_start_builtin_cycle(void) { int r = scale(255, MAX_RED); int g = scale(255, MAX_BLUE); int b = scale(255, MAX_GREEN); struct initdata_s pulse_vals[] = { {0x11, 0xce}, {0x12, 0x67}, {0x13, 0xef}, {0x15, b}, {0x16, r}, {0x17, g}, {0x18, b}, {0x19, r}, {0x1a, g}, }; set_from_array(pulse_vals, ARRAY_SIZE(pulse_vals)); controller_write(1, 0x13, 0xcd); /* this one's different */ }
void *do_chld(void *arg) { int client_socket = (int) arg; // the socket to the server if we are the controller int backend_socket = -1; int len = 0; int flag = 1; printf("Child thread: Socket number = %d\n", client_socket); while (flag) { struct op_hdr get_hdr; /* Read the header*/ printf("\t\t\tfirst read\n"); READ_SOC(len, client_socket, &get_hdr, HDR_SIZE); printf("***HDR***: op: %d, p1: %d, p2: %d, p3: %d\n", get_hdr.op, get_hdr.p1, get_hdr.p2, get_hdr.p3); /* ACT */ switch (get_hdr.op) { case OP_OPEN: controller_open(&backend_socket, client_socket, get_hdr); break; case OP_READ: controller_read(&backend_socket, client_socket, get_hdr); break; case OP_WRITE: controller_write(&backend_socket, client_socket, get_hdr); break; case OP_SEEK: controller_seek(&backend_socket, client_socket, get_hdr); break; case OP_SCANDIR: controller_scandir(&backend_socket, client_socket, get_hdr); break; case OP_CLOSE: controller_close(&backend_socket, client_socket, get_hdr); break; case OP_END: flag = 0; WRITE_SOC(len, backend_socket, &get_hdr, HDR_SIZE); break; default: /* ERROR! */ /* Since we are the server, we dont know how to handle errors on the client */ get_hdr.op = -1; WRITE_SOC(len, client_socket, &get_hdr, HDR_SIZE); printf("Bad opcode: %d\n", get_hdr.op); break; } } printf("Child: Done Processing...\n"); /* close the socket and exit this thread */ close(client_socket); pthread_exit((void *)NULL); /* never reached */ return(NULL); }
/* Helper for host command to write controller registers directly */ void lb_hc_cmd_reg(const struct ec_params_lightbar *in) { i2c_lock(I2C_PORT_LIGHTBAR, 1); controller_write(in->reg.ctrl, in->reg.reg, in->reg.value); i2c_lock(I2C_PORT_LIGHTBAR, 0); }
/* Helper for host command to write controller registers directly */ void lb_hc_cmd_reg(const struct ec_params_lightbar *in) { controller_write(in->reg.ctrl, in->reg.reg, in->reg.value); }
/* Come out of standby mode. */ void lb_on(void) { CPRINTS("LB_on"); controller_write(0, 0x01, 0x20); controller_write(1, 0x01, 0x20); }
/* Just go into standby mode. No register values should change. */ void lb_off(void) { CPRINTS("LB_off"); controller_write(0, 0x01, 0x00); controller_write(1, 0x01, 0x00); }