static int wifi_setup_A2_power(void *i2c,bool enable){ int rv; uint16_t temp_data = 0; uint16_t chip_id = 0,rf_version = 0; rv = sendI2cWord(i2c,PAGE_REG,0x0001); if(rv){ warning("select page 0x0001 failed"); goto failed; } if(enable){ temp_data = recvI2cWord(i2c,0x22); message("*** 0xA2 readback value enable : 0x%X",temp_data); temp_data |= 0x0200; /*! enable reg4_page bit !*/ #ifdef WLAN_USE_CRYSTAL temp_data &= ~(1 << 14); /*! disable xen_out !*/ #endif rv = sendI2cWord(i2c,0x22,temp_data); if(rv){ warning("reset value enable failed"); goto failed; } rv = readChip(i2c,&chip_id,&rf_version); if(rv) warning("read chip id and rf version failed"); else message("*** chip id : %04X,rf version : %04X",chip_id,rf_version); pmu.wlan_version = rf_version; pmu.chip_id = chip_id; }else{ temp_data = recvI2cWord(i2c,0x28); if(temp_data & 0x8000){ warning("disenable wifi failed,bluetooth is on"); rv = -1; goto failed; } temp_data = recvI2cWord(i2c,0x22); temp_data &= 0xfdff; rv = sendI2cWord(i2c,0x22,temp_data); if(rv){ warning("disenable wifi failed,can't send command!"); goto failed; } pmu.wlan_version = 0; pmu.chip_id = 0; } rv = sendI2cWord(i2c,PAGE_REG,0x0000); if(rv){ warning("can't select page"); } message("*** wifi setup A2 power succeed!"); return 0; failed: warning("wifi setup A2 power failed!"); return rv; }
void loop() { if(deviceStatus == STOPPED) { if(LCD.getTouchActivity() == TOUCH_UP) { LCD.getTouchXY(x, y); if(oneMinuteButton.isClicked(x, y)) { pumpEndMillis = millis() + 300; digitalWrite(VALVE_CONTROL1, LOW); digitalWrite(VALVE_CONTROL2, HIGH); initializePolling(); } else if(fiveMinuteButton.isClicked(x, y)) { pumpEndMillis = millis() + 300000; digitalWrite(VALVE_CONTROL1, LOW); digitalWrite(VALVE_CONTROL2, HIGH) initializePolling(); } else if(tenMinuteButton.isClicked(x, y)) { pumpEndMillis = millis() + 600000; digitalWrite(VALVE_CONTROL1, LOW); digitalWrite(VALVE_CONTROL2, HIGH); initializePolling(); } } } else if(deviceStatus != STOPPED) { checkInput(); readGPS(); checkInput(); readChip(); checkInput(); readTempHumid(); checkInput(); if(viewOptions) { drawOptions(); } checkTime(); } }
int writeHex(char *nomeArq, int totMem) { int cnt, totP; unsigned char dados[totMem]; unsigned char check[totMem]; if(readHex(nomeArq, dados, totMem) < 0) return 10; chipErase(); totP = writeChip(totMem, dados); readChip(totMem, check); for(cnt=0; cnt < totMem; cnt++) if(dados[cnt] != check[cnt]) { printf("Erro! Endereço %d leu 0x%.2X, mas era para ser 0x%.2X\n", cnt, check[cnt], dados[cnt]); return 0; } return totP; }