void buttonTimerCb(void *arg) { int buttonsPressed=io_get_inputs()&INPUT_BUTTONMASK; // os_printf("Buttons: %x\n", buttonsPressed); timeSinceButtonPressed+=BUTTON_CHECK_INTERVAL_MS; if (timeSinceButtonPressed>=LONGPRESS_TIME_MS) { //Detected a long press. Handle accordingly. os_printf("Longpress %x\n", buttonsPressedCum); led_pattern(LED_PATTERN_SOFTAP); //A fixed key value for pairing. os_printf("pressed: %02x , pcum: %02x \r\n",buttonsPressed,buttonsPressedCum); if (buttonsPressed==(INPUT_BTN1|INPUT_BTN3)) { os_printf("PAIR START\r\n"); buttonSimplePairStart(NULL); } else { //switch_EspnowChnSyncStart(); switch_EspnowSendCmd( (buttonsPressedCum&INPUT_BUTTONMASK)|0xff00); } buttonsPressedCum=0; } else if (buttonsPressed==0) { if (!io_battery_is_lo()) { led_pattern(LED_PATTERN_PACKETSENT); } else { led_pattern(LED_PATTERN_PACKETSENT_BATLO); } //Buttons have been released. os_printf("Shortpress %x\n", buttonsPressedCum); switch_EspnowSendCmd(buttonsPressedCum&INPUT_BUTTONMASK); } else { //Buttons are still pressed. Check again in a while. buttonsPressedCum|=buttonsPressed; os_timer_arm(&buttonTimer, BUTTON_CHECK_INTERVAL_MS, 0); } }
static void handle_args(char *args, chanend led_svr, chanend page_svr) { if (strncmp(args,"pattern=",8) == 0) { switch (*(args+8)) { case '1': led_pattern(led_svr, 1); break; case '2': led_pattern(led_svr, 2); break; } } if (strncmp(args,"ipconfig=0",9) == 0) { // Set to dynamic config // printstr("Set to Dynamic\n"); page_server_set_ipconfig(page_svr, 0); } if (strncmp(args,"ipaddr=",7) == 0) { // Set to static config with ip addr char *nextargpos; unsigned int ipaddr; unsigned int netmask; nextargpos = strchr(args, '&'); if (nextargpos != NULL) { *nextargpos=0; if (strncmp(nextargpos+1,"netmask=",8)==0) { // printstr("Set to Static\n"); ipaddr = parse_ip(args+7); netmask = parse_ip(nextargpos+9); if (ipaddr != 0) { page_server_set_ipconfig(page_svr, 1); // set_default_ip_config(config_ch,1); page_server_set_ipaddr(page_svr, ipaddr); page_server_set_netmask(page_svr, netmask); // set_default_ip_addr(config_ch, ipaddr); // set_default_netmask(config_ch, netmask); // commit_config(config_ch); // default_ip_config_cache = 1; //httpd_set_ip_addr_string(ipaddr, DEFAULT_IPADDR_STRING_NUM); //httpd_set_ip_addr_string(netmask, NETMASK_STRING_NUM); } } } } }
//ToDo: This should also enable the buttons; people may want to use the thing while it is charging. void chargeTimerCb(void *arg) { int input=io_get_inputs(); os_printf("Inputs: %x\n", input); if ((input&INPUT_CHRG)==0) { //USB cable was unplugged. Kill power. os_timer_disarm(&chargeTimer); io_powerkeep_release(); //charge power release } if (input&INPUT_CHRGDONE) { led_pattern(LED_PATTERN_FULL); } else { led_pattern(LED_PATTERN_CHARGING); } }