void configLoadStd(void) { LCD_BACKLIGHT=125; LCD_CONTRAST=16; BAUDRATE=115200; MAX_POWER=25; POWER=10; DEBUG_MODE=0; CURRENT=1000; WAVELENGTH=491.0; CHECK_LASERCONNECTED=1; #ifdef TWO_LASERS MAX_POWER2=25; POWER2=10; CURRENT2=1000; WAVELENGTH2=491.0; #endif EXTERNAL_INTENSITY_MODE=0; EXTERNAL_ONOFF_MODE=0; EXTINTENSITY_MIN=100; EXTINTENSITY_MAX=2500; configCalc(); configSave(); }
int ICACHE_FLASH_ATTR ajaxConsoleFormat(HttpdConnData *connData) { if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. char buff[16]; int len, status = 400; len = httpdFindArg(connData->getArgs, "fmt", buff, sizeof(buff)); if (len >= 3) { int c = buff[0]; if (c >= '5' && c <= '8') flashConfig.data_bits = c - '5' + FIVE_BITS; if (buff[1] == 'N') flashConfig.parity = NONE_BITS; if (buff[1] == 'E') flashConfig.parity = EVEN_BITS; if (buff[1] == 'O') flashConfig.parity = ODD_BITS; if (buff[2] == '1') flashConfig.stop_bits = ONE_STOP_BIT; if (buff[2] == '2') flashConfig.stop_bits = TWO_STOP_BIT; uart0_config(flashConfig.data_bits, flashConfig.parity, flashConfig.stop_bits); status = configSave() ? 200 : 400; } else if (connData->requestType == HTTPD_METHOD_GET) { status = 200; } jsonHeader(connData, status); os_sprintf(buff, "{\"fmt\": \"%c%c%c\"}", flashConfig.data_bits + '5', flashConfig.parity ? 'E' : 'N', flashConfig.stop_bits ? '2': '1'); httpdSend(connData, buff, -1); return HTTPD_CGI_DONE; }
int ICACHE_FLASH_ATTR ajaxLogDbg(HttpdConnData *connData) { if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. char buff[512]; int len, status = 400; len = httpdFindArg(connData->getArgs, "mode", buff, sizeof(buff)); if (len > 0) { int8_t mode = -1; if (os_strcmp(buff, "auto") == 0) mode = LOG_MODE_AUTO; if (os_strcmp(buff, "off") == 0) mode = LOG_MODE_OFF; if (os_strcmp(buff, "on0") == 0) mode = LOG_MODE_ON0; if (os_strcmp(buff, "on1") == 0) mode = LOG_MODE_ON1; if (mode >= 0) { flashConfig.log_mode = mode; if (mode != LOG_MODE_AUTO) log_uart(mode >= LOG_MODE_ON0); status = configSave() ? 200 : 400; } } else if (connData->requestType == HTTPD_METHOD_GET) { status = 200; } jsonHeader(connData, status); os_sprintf(buff, "{\"mode\": \"%s\"}", dbg_mode[flashConfig.log_mode]); httpdSend(connData, buff, -1); return HTTPD_CGI_DONE; }
static void _hStickCentering() { if (KEYINIT) { if ((RX_good & 0x0F) != 0x0F) { lcdWriteString_P(scrRadioCal1); elementIndex = 1; writeSoftkeys(_skBACK); } else lcdWriteString_P(scrRadioCal0); } if (elementIndex == 0) { if (KEY4) { lcdClear(); if (rxCalibrate()) { configSave(); lcdSetPos(3, 0); lcdWriteString_P(strCalSucc); } else lcdWriteString_P(scrRadioCal2); writeSoftkeys(NULL); elementIndex = 1; } } else if (KEY4) loadPage(PAGE_MENU); }
static void _hSensorCalibration() { if (elementIndex == 0) { if (KEY4) { elementIndex = 1; lcdClear(); lcdSetPos(3, 18); lcdWriteString_P(strWait); lcdSetPos(3, 78); lcdWriteString_P(strSec); writeSoftkeys(_skCANCEL); _tStart = millis(); } } else if (elementIndex == 1) { lcdSetPos(3, 66); uint8_t sec = (millis() - _tStart) / 1000; lcdWriteChar((5-sec) + 48); if (sec >= 5) { sensorsCalibrate(); configSave(); lcdSetPos(3, 0); lcdWriteString_P(strCalSucc); writeSoftkeys(NULL); elementIndex = 2; } } else if (KEY4) loadPage(PAGE_MENU); }
// Change special settings int ICACHE_FLASH_ATTR cgiWiFiSpecial(HttpdConnData *connData) { char dhcp[8]; char staticip[20]; char netmask[20]; char gateway[20]; if (connData->conn==NULL) return HTTPD_CGI_DONE; // get args and their string lengths int dl = httpdFindArg(connData->getArgs, "dhcp", dhcp, sizeof(dhcp)); int sl = httpdFindArg(connData->getArgs, "staticip", staticip, sizeof(staticip)); int nl = httpdFindArg(connData->getArgs, "netmask", netmask, sizeof(netmask)); int gl = httpdFindArg(connData->getArgs, "gateway", gateway, sizeof(gateway)); if (!(dl > 0 && sl >= 0 && nl >= 0 && gl >= 0)) { jsonHeader(connData, 400); httpdSend(connData, "Request is missing fields", -1); return HTTPD_CGI_DONE; } char url[64]; // redirect URL if (os_strcmp(dhcp, "off") == 0) { // parse static IP params struct ip_info ipi; bool ok = parse_ip(staticip, &ipi.ip); if (nl > 0) ok = ok && parse_ip(netmask, &ipi.netmask); else IP4_ADDR(&ipi.netmask, 255, 255, 255, 0); if (gl > 0) ok = ok && parse_ip(gateway, &ipi.gw); else ipi.gw.addr = 0; if (!ok) { jsonHeader(connData, 400); httpdSend(connData, "Cannot parse static IP config", -1); return HTTPD_CGI_DONE; } // save the params in flash flashConfig.staticip = ipi.ip.addr; flashConfig.netmask = ipi.netmask.addr; flashConfig.gateway = ipi.gw.addr; // construct redirect URL os_sprintf(url, "{\"url\": \"http://%d.%d.%d.%d\"}", IP2STR(&ipi.ip)); } else { // dynamic IP flashConfig.staticip = 0; os_sprintf(url, "{\"url\": \"http://%s\"}", flashConfig.hostname); } configSave(); // ignore error... // schedule change-over os_timer_disarm(&reassTimer); os_timer_setfn(&reassTimer, configWifiIP, NULL); os_timer_arm(&reassTimer, 1000, 0); // 1 second for the response of this request to make it // return redirect info jsonHeader(connData, 200); httpdSend(connData, url, -1); return HTTPD_CGI_DONE; }
void editor_quit(void) { if (editor_count_ACCEPT == EDITOR_BUTTON_FIRSTHIT) { editor_enabled=0; // wait some time (1 sec) fprintf(editor_LCD, "\fsaving ... \n "); editor_changed=1; configSave(); _delay_ms(500); } }
void UART4_IRQHandler()//UART4 Interrupt handler implementation { int eeRreg; uint8_t data; ConfigMode=1; while ( USART_GetFlagStatus(UART4, USART_FLAG_RXNE) == RESET); UART4_DATA=USART_ReceiveData(UART4); LEDon; if(UART4_DATA==103) { //if "g" Delay_ms(100); sprintf (buff, "x"); USART_PutString(buff); for(eeRreg=0; eeRreg<configDataSize;eeRreg++) { data = ReadFromEEPROM(eeRreg); Delay_ms(1); sprintf (buff, "%c", data); USART_PutString(buff); } } if(enable_writing==1) { configData[w]=(int)UART4_DATA; w++; if(w>=configDataSize) { w=0; enable_writing=0; //saveData(); configSave(); } } if(UART4_DATA==104) { // if h (write to eeprom) enable_writing=1; } if(UART4_DATA==105) { ConfigMode=1; } if(UART4_DATA==106) { ConfigMode=0; } }
static void _hFactoryReset() { if (KEYINIT) { lcdSetPos(3, 18); lcdWriteString_P(strAreYouSure); } else if (KEY4) // Yes { configReset(); configSave(); // force reset by enabling watchdog and enter endless loop cli(); wdt_enable(WDTO_15MS); for(;;); } }
int ICACHE_FLASH_ATTR cgiNFCSet(HttpdConnData *connData) { if (connData->conn==NULL) return HTTPD_CGI_DONE; // handle NFC server settings int8_t nfc_server = 0; // accumulator for changes/errors nfc_server |= getStringArg(connData, "nfc-url", flashConfig.nfc_url, sizeof(flashConfig.nfc_url)); if (nfc_server < 0) return HTTPD_CGI_DONE; nfc_server |= getStringArg(connData, "nfc-device-id", flashConfig.nfc_device_id, sizeof(flashConfig.nfc_device_id)); if (nfc_server < 0) return HTTPD_CGI_DONE; nfc_server |= getStringArg(connData, "nfc-device-secret", flashConfig.nfc_device_secret, sizeof(flashConfig.nfc_device_secret)); if (nfc_server < 0) return HTTPD_CGI_DONE; char buff[16]; // handle nfc counter if (httpdFindArg(connData->getArgs, "nfc-counter", buff, sizeof(buff)) > 0) { uint32_t counter = atoi(buff); if (counter > 0 && counter < 4294967295) { flashConfig.nfc_counter = counter; nfc_server |= 1; } else { errorResponse(connData, 400, "Invalid NFC counter!"); return HTTPD_CGI_DONE; } } DBG("Saving config\n"); if (configSave()) { httpdStartResponse(connData, 200); httpdEndHeaders(connData); } else { httpdStartResponse(connData, 500); httpdEndHeaders(connData); httpdSend(connData, "Failed to save config", -1); } return HTTPD_CGI_DONE; }
int ICACHE_FLASH_ATTR ajaxConsoleBaud(HttpdConnData *connData) { if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. char buff[512]; int len, status = 400; len = httpdFindArg(connData->getArgs, "rate", buff, sizeof(buff)); if (len > 0) { int rate = atoi(buff); if (rate >= 9600 && rate <= 1000000) { uart0_baud(rate); flashConfig.baud_rate = rate; status = configSave() ? 200 : 400; } } else if (connData->requestType == HTTPD_METHOD_GET) { status = 200; } jsonHeader(connData, status); os_sprintf(buff, "{\"rate\": %ld}", flashConfig.baud_rate); httpdSend(connData, buff, -1); return HTTPD_CGI_DONE; }
void menuLoop() { if (keys == 0) keys = keyboardRead(); if (KEY1 && !editMode) // BACK { if (menuPage > PAGE_MENU) loadPage(PAGE_MENU); else if (menuPage == PAGE_MENU) { configSave(); loadPage(PAGE_START); } } if (KEYMENU) keys = KEY_INIT; defaultHandler(); keys &= KEY_MENU; }
// Cgi to change choice of pin assignments int ICACHE_FLASH_ATTR cgiTcpSet(HttpdConnData *connData) { if (connData->conn==NULL) return HTTPD_CGI_DONE; // Handle tcp_enable flag char buff[128]; int len = httpdFindArg(connData->getArgs, "tcp_enable", buff, sizeof(buff)); if (len <= 0) { jsonHeader(connData, 400); return HTTPD_CGI_DONE; } flashConfig.tcp_enable = os_strcmp(buff, "true") == 0; // Handle rssi_enable flag len = httpdFindArg(connData->getArgs, "rssi_enable", buff, sizeof(buff)); if (len <= 0) { jsonHeader(connData, 400); return HTTPD_CGI_DONE; } flashConfig.rssi_enable = os_strcmp(buff, "true") == 0; // Handle api_key flag len = httpdFindArg(connData->getArgs, "api_key", buff, sizeof(buff)); if (len < 0) { jsonHeader(connData, 400); return HTTPD_CGI_DONE; } buff[sizeof(flashConfig.api_key)-1] = 0; // ensure we don't get an overrun os_strcpy(flashConfig.api_key, buff); if (configSave()) { httpdStartResponse(connData, 200); httpdEndHeaders(connData); } else { httpdStartResponse(connData, 500); httpdEndHeaders(connData); httpdSend(connData, "Failed to save config", -1); } return HTTPD_CGI_DONE; }
void handleNotification(SCNotification *notifyCode) { static bool do_newline = false; NotifyHeader nh = notifyCode->nmhdr; int ch = notifyCode->ch; switch(nh.code) { case SCN_UPDATEUI: // Now is when we can check to see if we do the commenting if(do_newline) { do_newline = false; if(!updateScintilla()) return; doxyItNewLine(); } break; case SCN_CHARADDED: // Set a flag so that all line endings can trigger the commenting if((ch == '\r' || ch == '\n') && do_active_commenting) do_newline = true; break; case NPPN_READY: InitializeParsers(); configLoad(); getCurrentParser(true); break; case NPPN_SHUTDOWN: configSave(); CleanUpParsers(); break; case NPPN_BUFFERACTIVATED: case NPPN_LANGCHANGED: // Don't actually need the parser here, but this forces it to updates the current reference getCurrentParser(true); break; } return; }
// Cgi to change choice of pin assignments int ICACHE_FLASH_ATTR cgiPinsSet(HttpdConnData *connData) { if (connData->conn==NULL) { return HTTPD_CGI_DONE; // Connection aborted } int8_t ok = 0; int8_t reset, isp, conn, ser; bool swap, rxpup; ok |= getInt8Arg(connData, "reset", &reset); ok |= getInt8Arg(connData, "isp", &isp); ok |= getInt8Arg(connData, "conn", &conn); ok |= getInt8Arg(connData, "ser", &ser); ok |= getBoolArg(connData, "swap", &swap); ok |= getBoolArg(connData, "rxpup", &rxpup); if (ok < 0) return HTTPD_CGI_DONE; char *coll; if (ok > 0) { // check whether two pins collide uint16_t pins = 0; if (reset >= 0) pins = 1 << reset; if (isp >= 0) { if (pins & (1<<isp)) { coll = "ISP/Flash"; goto collision; } pins |= 1 << isp; } if (conn >= 0) { if (pins & (1<<conn)) { coll = "Conn LED"; goto collision; } pins |= 1 << conn; } if (ser >= 0) { if (pins & (1<<ser)) { coll = "Serial LED"; goto collision; } pins |= 1 << ser; } if (swap) { if (pins & (1<<15)) { coll = "Uart TX"; goto collision; } if (pins & (1<<13)) { coll = "Uart RX"; goto collision; } } else { if (pins & (1<<1)) { coll = "Uart TX"; goto collision; } if (pins & (1<<3)) { coll = "Uart RX"; goto collision; } } // we're good, set flashconfig flashConfig.reset_pin = reset; flashConfig.isp_pin = isp; flashConfig.conn_led_pin = conn; flashConfig.ser_led_pin = ser; flashConfig.swap_uart = swap; flashConfig.rx_pullup = rxpup; os_printf("Pins changed: reset=%d isp=%d conn=%d ser=%d swap=%d rx-pup=%d\n", reset, isp, conn, ser, swap, rxpup); // apply the changes serbridgeInitPins(); serledInit(); statusInit(); // save to flash if (configSave()) { httpdStartResponse(connData, 204); httpdEndHeaders(connData); } else { httpdStartResponse(connData, 500); httpdEndHeaders(connData); httpdSend(connData, "Failed to save config", -1); } } return HTTPD_CGI_DONE; collision: { char buff[128]; os_sprintf(buff, "Pin assignment for %s collides with another assignment", coll); errorResponse(connData, 400, buff); return HTTPD_CGI_DONE; } }
void CommHandler(void) //UART4 Interrupt handler implementation { int c = GetChar(); if (c >= 0) { //ConfigMode = 1; LEDon(); //print("got char %02X\r\n", c); switch (c) { case 'b': print("rebooting into boot loader ...\r\n"); Delay_ms(1000); bootloader(); break; case 'c': debugCnt ^= 1; print("counter messages %s\r\n", debugCnt ? "on" : "off"); break; case 'd': debugPrint ^= 1; print("debug messages %s\r\n", debugPrint ? "on" : "off"); break; case 'g': Delay_ms(100); PutChar('x'); for (int i = 0; i < CONFIGDATASIZE; i++) { uint8_t data = configData[i]; PutChar(data); } break; case 'G': printConfig(); break; #if 0 case 'H': if (CharAvailable() >= CONFIGDATASIZE) { for (int i = 0; i < CONFIGDATASIZE; i++) { uint8_t data = GetChar(); if (data <= LARGEST_CONFIGDATA) { configData[i] = data; } } configSave(); } else { UnGetChar(c); // try again in next loop } break; #endif case 'h': for (int i = 0; i < CONFIGDATASIZE; i++) { int data; while ((data = GetChar()) < 0) ; if (data <= LARGEST_CONFIGDATA) { configData[i] = data; } } configSave(); break; case 'i': ConfigMode = 1; break; case 'j': ConfigMode = 0; break; case 'o': debugOrient ^= 1; print("Orientation messages %s\r\n", debugOrient ? "on" : "off"); break; case 'p': debugPerf ^= 1; print("performance messages %s\r\n", debugPerf ? "on" : "off"); break; case 'r': debugRC ^= 1; print("RC messages %s\r\n", debugRC ? "on" : "off"); break; case 'R': print("rebooting...\r\n"); Delay_ms(1000); reboot(); break; case 's': debugSense ^= 1; print("Sensor messages %s\r\n", debugSense ? "on" : "off"); break; case 'u': { extern int bDeviceState; printUSART("\r\nYY bDeviceState %3d VCPConnectMode %d\r\n", bDeviceState, GetVCPConnectMode()); break; } case '+': testPhase += 0.1; print("test phase output %5.1f\r\n", testPhase); break; case '-': testPhase -= 0.1; print("test phase output %5.1f\r\n", testPhase); break; default: // TODO break; } } }
void CommHandler(void) //UART4 Interrupt handler implementation { int c = GetChar(); if (c >= 0) { LEDon(); switch (c) { case 'a': debugAutoPan ^= 1; print("Autopan messages %s\r\n", debugAutoPan ? "on" : "off"); break; case 'b': print("rebooting into boot loader ...\r\n"); Delay_ms(1000); bootloader(); break; case 'c': debugCnt ^= 1; print("counter messages %s\r\n", debugCnt ? "on" : "off"); break; case 'd': debugPrint ^= 1; print("debug messages %s\r\n", debugPrint ? "on" : "off"); break; case 'g': Delay_ms(100); PutChar('x'); for (int i = 0; i < CONFIGDATASIZE; i++) { uint8_t data = configData[i]; PutChar(data); } break; case 'G': printConfig(); break; #if 0 case 'H': if (CharAvailable() >= CONFIGDATASIZE) { for (int i = 0; i < CONFIGDATASIZE; i++) { uint8_t data = GetChar(); if (data <= LARGEST_CONFIGDATA) { configData[i] = data; } } configSave(); } else { UnGetChar(c); // try again in next loop } break; #endif case 'h': for (int i = 0; i < CONFIGDATASIZE; i++) { int data; while ((data = GetChar()) < 0) ; if (data <= LARGEST_CONFIGDATA) { configData[i] = data; } } configSave(); break; case 'i': ConfigMode = 1; break; case 'j': ConfigMode = 0; break; case 'o': debugOrient ^= 1; print("Orientation messages %s\r\n", debugOrient ? "on" : "off"); break; case 'O': debugGravityVector ^= 1; print("GVector messages %s\r\n", debugGravityVector ? "on" : "off"); break; case 'S': debugSetpoints ^= 1; print("Setpoints messages %s\r\n", debugSetpoints ? "on" : "off"); break; case 'p': debugPerf ^= 1; print("performance messages %s\r\n", debugPerf ? "on" : "off"); break; case 'r': debugRC ^= 1; print("RC messages %s\r\n", debugRC ? "on" : "off"); break; case 'R': print("rebooting...\r\n"); Delay_ms(1000); reboot(); break; case 's': debugSense ^= 1; print("Sensor messages %s\r\n", debugSense ? "on" : "off"); break; case 'u': { extern int bDeviceState; printUSART("\r\nYY bDeviceState %3d VCPConnectMode %d\r\n", bDeviceState, GetVCPConnectMode()); break; } case 'v': print("Version: %s\r\n", __EV_VERSION); break; case '+': testPhase += 0.1; print("test phase output %5.1f\r\n", testPhase); break; case '-': testPhase -= 0.1; print("test phase output %5.1f\r\n", testPhase); break; /* case '?': print("CLI documentation\r\n"); // print("\t'+' test phase output increase (now %5.1f)\r\n", testPhase); //print("\t'-' test phase output decrease (now %5.1f)\r\n", testPhase); print("\t'a' autopan messages display (now %s)\r\n", debugAutoPan ? "on" : "off"); print("\t'b' reboot into bootloader\r\n"); print("\t'c' counter messages display (now %s)\r\n", debugCnt ? "on" : "off"); print("\t'd' debug messages display (now %s)\r\n", debugPrint ? "on" : "off"); print("\t'g' dump configuration (binary)\r\n"); print("\t'G' dump configuration (hexadecimal)\r\n"); // print("\t'h' write and save config array\r\n"); print("\t'i' enter config mode (now %s)\r\n", ConfigMode ? "on" : "off"); print("\t'j' leave config mode (now %s)\r\n", ConfigMode ? "on" : "off"); print("\t'o' orientation messages display (now %s)\r\n", debugOrient ? "on" : "off"); print("\t'p' performance messages display (now %s)\r\n", debugPerf ? "on" : "off"); print("\t'r' RC messages display (now %s)\r\n", debugRC ? "on" : "off"); print("\t'R' reboot\r\n"); print("\t's' toggle sensor messages display (now %s)\r\n", debugSense ? "on" : "off"); print("\t'u' print USB state (bDeviceState %3d VCPConnectMode %d)\r\n", bDeviceState, GetVCPConnectMode()); print("\t'v' print version (%s)\r\n", __EV_VERSION); break; */ default: // TODO break; } } }