LOCAL int ICACHE_FLASH_ATTR open_door_cmd_json_set(struct jsontree_context *js_ctx, struct jsonparse_state *parser) { int type; while ((type = jsonparse_next(parser)) != 0) { if (type == JSON_TYPE_PAIR_NAME) { char buffer[64]; os_bzero(buffer, 64); if (jsonparse_strcmp_value(parser, "cmd") == 0) { jsonparse_next(parser); jsonparse_next(parser); jsonparse_copy_value(parser, buffer, sizeof(buffer)); if (!strcoll(buffer, "on")) { #ifdef MENJINDEBUG os_printf("JSON: door open \n"); #endif easygpio_outputSet(JIDIANQI_IO, 0); } else if (!strcoll(buffer, "off")) { #ifdef MENJINDEBUG os_printf("JSON: door clease \n"); #endif // OLED_Print(0, 2, " ", 2); OLED_Print(0, 2, " Permission ", 2); // OLED_Print(0, 4, " ", 2); OLED_Print(0, 4, " Denied ", 2); easygpio_outputSet(JIDIANQI_IO, 1); } } } } return 0; }
static void hw_timer_cb(void) { static uint8 groupBitCount = 0; static uint8 groupBits; static uint32 word; groupBitCount = sendGroup(groupBitCount, groupBits); if (groupBitCount == 0) { switch (wordBitCount) { case 0: easygpio_outputSet(LED, 0); return; case 34: easygpio_outputSet(LED, 1); groupBits = groupStart; word = xmit.word; groupBitCount = GROUP_BITS; break; case 1: groupBits = groupEnd; groupBitCount = GROUP_BITS; break; default: if (word & (1 << 31)) groupBits = groupBit1; else groupBits = groupBit0; word <<= 1; groupBitCount = GROUP_BITS; break; } wordBitCount--; } }
static void ICACHE_FLASH_ATTR showLargeChar(const uint8 *c, uint8 charCol, uint8 charRow) { const uint8 w = 15; uint8 pxCol; gotoXY(charRow * (w + 1), 2 * (2 - charCol)); easygpio_outputSet(LCD_D_C, 1); if ('0' <= *c && *c <= '?') { for (pxCol = 0; pxCol < w; pxCol++) { spi(NUMERIC[(int) (*c - '0')][pxCol][1]); } spi(0); gotoXY(charRow * (w + 1), 2 * (2 - charCol) + 1); easygpio_outputSet(LCD_D_C, 1); for (pxCol = 0; pxCol < w; pxCol++) { spi(NUMERIC[(int) (*c - '0')][pxCol][0]); } spi(0); } else { // Space as default for (pxCol = 0; pxCol <= w; pxCol++) { spi(0); } gotoXY(charRow * (w + 1), 2 * (2 - charCol) + 1); easygpio_outputSet(LCD_D_C, 1); for (pxCol = 0; pxCol <= w; pxCol++) { spi(0); } } }
uint8 ICACHE_FLASH_ATTR showLargeNumString(uint8 xPosn, uint8 yPosn, char *s) { easygpio_outputSet(LCD_SCE, 0); while (*s && xPosn < 3) { showLargeChar(s++, xPosn, yPosn); xPosn++; } easygpio_outputSet(LCD_SCE, 1); return xPosn; }
void ICACHE_FLASH_ATTR clearLcd() { int res; easygpio_outputSet(LCD_SCE, 0); spi(0x40); // Y=0 spi(0x80); // X=0 easygpio_outputSet(LCD_D_C, 1); for(res=0; res<504; res++) { spi(0x00); } easygpio_outputSet(LCD_SCE, 1); }
void ICACHE_FLASH_ATTR showChar(const char *c, uint8 charCol, uint8 charRow) { const uint8 w = 5; uint8 pxCol; easygpio_outputSet(LCD_SCE, 0); easygpio_outputSet(LCD_D_C, 1); gotoXY(charCol*(w+1), charRow); for (pxCol=0; pxCol<w; pxCol++) { spi(ASCII[(int)(*c - ' ')][pxCol]); } spi(0); easygpio_outputSet(LCD_SCE, 1); }
uint8 ICACHE_FLASH_ATTR showInvertedString(uint8 xPosn, uint8 yPosn, char *s) { const uint8 w = 5; easygpio_outputSet(LCD_SCE, 0); gotoXY(xPosn*(w+1), yPosn); easygpio_outputSet(LCD_D_C, 1); while (*s && xPosn < 16) { showNextInvertedChar(s++, w); xPosn++; } easygpio_outputSet(LCD_SCE, 1); return xPosn; }
void ICACHE_FLASH_ATTR overrideClearOutput(uint8 id) { if (id < OUTPUTS) { outputOverrides[id] = false; easygpio_outputSet(outputMap[id], currentOutputs[id]); TESTP("o/p %d(%d)x->%d\n", id, outputMap[id], currentOutputs[id]); } }
void ICACHE_FLASH_ATTR overrideSetOutput(uint8 id, bool set) { // Sets override if (id < OUTPUTS) { outputOverrides[id] = true; easygpio_outputSet(outputMap[id], set); TESTP("o/p %d(%d)-->%d\n", id, outputMap[id], set); } }
void ICACHE_FLASH_ATTR initOutputs(void) { int id; for (id = 0; id < OUTPUTS; id++) { easygpio_pinMode(outputMap[id], EASYGPIO_NOPULL, EASYGPIO_OUTPUT); easygpio_outputSet(outputMap[id], 0); } }
void ICACHE_FLASH_ATTR checkSetOutput(uint8 op, bool newSetting) { if (op < OUTPUTS) { if (currentOutputs[op] != newSetting) { publishOutput(op, newSetting); currentOutputs[op] = newSetting; } switch (outputOverrides[op]) { case OR_NOT_SET: easygpio_outputSet(PUMP, !newSetting); break; case OR_OFF: easygpio_outputSet(PUMP, true); break; case OR_ON: easygpio_outputSet(PUMP, false); break; } return; } publishError(92, op); // Invalid Output ID return; }
void ICACHE_FLASH_ATTR check_door_status_cb(void *arg) { os_timer_disarm(&check_door_status_timer); if (!easygpio_inputGet(DOOR_STATUS_IO)) { easygpio_outputSet(JIDIANQI_IO, 1); } os_timer_arm(&check_door_status_timer, CHECK_DOOR_DELAY, 1); }
void ICACHE_FLASH_ATTR overrideClearOutput(uint8 op) { if (op < OUTPUTS) { outputOverrides[op] = OR_NOT_SET; easygpio_outputSet(PUMP, !currentOutputs[op]); printOutput(op); } }
void ICACHE_FLASH_ATTR overrideSetOutput(uint8 op, uint8 set) { if (op < OUTPUTS) { outputOverrides[op] = set ? OR_ON : OR_OFF; easygpio_outputSet(PUMP, !set); printOutput(op); } }
void ICACHE_FLASH_ATTR setOutput(uint8 id, bool set) { if (id < OUTPUTS) { currentOutputs[id] = set; if (!outputOverrides[id]) { easygpio_outputSet(outputMap[id], set); } } }
void ICACHE_FLASH_ATTR initIO(void) { easygpio_pinMode(LED, EASYGPIO_NOPULL, EASYGPIO_OUTPUT); easygpio_outputSet(LED, 1); easygpio_pinMode(ACTION_LED, EASYGPIO_NOPULL, EASYGPIO_OUTPUT); easygpio_outputSet(ACTION_LED, 0); easygpio_pinMode(PUMP, EASYGPIO_NOPULL, EASYGPIO_OUTPUT); easygpio_outputSet(PUMP, 1); // Inverted easygpio_pinMode(ANALOGUE_SELECT, EASYGPIO_NOPULL, EASYGPIO_OUTPUT); easygpio_outputSet(ANALOGUE_SELECT, 0); easygpio_pinMode(FLOW_SENSOR, EASYGPIO_PULLUP, EASYGPIO_INPUT); easygpio_outputDisable(FLOW_SENSOR); easygpio_pinMode(SWITCH, EASYGPIO_PULLUP, EASYGPIO_INPUT); easygpio_outputDisable(SWITCH); easygpio_pinMode(TOGGLE, EASYGPIO_PULLUP, EASYGPIO_INPUT); easygpio_outputDisable(TOGGLE); }
void ICACHE_FLASH_ATTR door_switch_init() { easygpio_pinMode(JIDIANQI_IO, EASYGPIO_NOPULL, EASYGPIO_OUTPUT); easygpio_pinMode(DOOR_STATUS_IO, EASYGPIO_NOPULL, EASYGPIO_INPUT); easygpio_outputSet(JIDIANQI_IO, 1); os_timer_disarm(&check_door_status_timer); os_timer_setfn(&check_door_status_timer, (os_timer_func_t *) check_door_status_cb, (void *) 0); os_timer_arm(&check_door_status_timer, CHECK_DOOR_DELAY, 1); }
void ICACHE_FLASH_ATTR user_init(void) { uart_init(115200, 115200); // stdout_init(); gpio_init(); wifi_station_set_auto_connect(false); // Needs to be in user_init to apply to this session savedLastAction = lastAction; easygpio_pinMode(LED, EASYGPIO_PULLUP, EASYGPIO_OUTPUT); easygpio_outputSet(LED, 1); system_init_done_cb(&startUp); }
static uint8 sendGroup(uint8 count, uint8 bits) { static uint8 group; switch (count) { case 0: easygpio_outputSet(XMIT, 1); os_delay_us(1); easygpio_outputSet(XMIT, 0); return 0; case GROUP_BITS: group = bits; //No break default: if (group & (1 << 5)) { easygpio_outputSet(XMIT, 1); os_delay_us(2); easygpio_outputSet(XMIT, 0); } group <<= 1; return count-1; } }
void ICACHE_FLASH_ATTR processPump(void) { // Every 100mS updatePressure(); checkLevel(); switch (pumpState()) { case MANUAL_OFF: easygpio_outputSet(PUMP, 0); pumpOnCount = 0; checkNotFlowing(); break; case MANUAL_ON: if (secondsNotFlowing() > 30) { pumpState_OffManual(); easygpio_outputSet(PUMP, 0); sounderAlarm(3); // No flow for 30S in Manual } else { easygpio_outputSet(PUMP, 1); } break; case AUTO_OFF: if (getCurrentPressure() < sysCfg.settings[SET_PUMP_ON]) { startCheckIsFlowing(); pumpState_OnAuto(); easygpio_outputSet(PUMP, 1); } else { easygpio_outputSet(PUMP, 0); pumpOnCount = 0; checkNotFlowing(); } sounderClear(); break; case AUTO_ON: if (getCurrentPressure() > sysCfg.settings[SET_PUMP_OFF]) { pumpState_OffAuto(); easygpio_outputSet(PUMP, 0); } else { if (secondsNotFlowing() > sysCfg.settings[SET_NO_FLOW_AUTO_ERROR]) { publishAlarm(1, flowAverageReading()); // No flow for SET_NO_FLOW_AUTO_ERROR (10S) in Auto sounderAlarm(1); publishAlarm(6, secondsNotFlowing()); // No flow for SET_NO_FLOW_AUTO_ERROR (10S) in Auto pumpState_OffManual(); } else { pumpOnCount++; if (pumpOnCount >= sysCfg.settings[SET_MAX_PUMP_ON_WARNING] && getCurrentPressure() < sysCfg.settings[SET_LOW_PRESSURE_WARNING]) { publishError(3, getCurrentPressure()); // Low pressure and Pump On > SET_MAX_PUMP_ON_WARNING } if (pumpOnCount >= sysCfg.settings[SET_MAX_PUMP_ON_WARNING]) { // 1 minute publishError(1, sysCfg.settings[SET_MAX_PUMP_ON_WARNING]); } else if (pumpOnCount == sysCfg.settings[SET_MAX_PUMP_ON_ERROR]) { // 5 minutes publishAlarm(2, pumpOnCount); // Running for SET_MAX_PUMP_ON_ERROR (5 Minutes) in Auto sounderAlarm(2); } else if (pumpOnCount > sysCfg.settings[SET_MAX_PUMP_ON_ERROR]) { pumpOnCount = sysCfg.settings[SET_MAX_PUMP_ON_ERROR] + 1; } } } break; } }
static void ICACHE_FLASH_ATTR flashCb(void) { os_timer_disarm(&flash_timer); switch (flashState) { case OFF: easygpio_outputSet(LED, LED_OFF); break; case FLASHING_ON: easygpio_outputSet(LED, LED_OFF); os_timer_arm(&flash_timer, flashOnTime, false); flashState = FLASHING_OFF; break; case FLASHING_OFF: flashCounter--; if (flashCounter > 0) { easygpio_outputSet(LED, LED_ON); os_timer_arm(&flash_timer, flashOnTime, false); flashState = FLASHING_ON; } else { easygpio_outputSet(LED, LED_OFF); os_timer_arm(&flash_timer, patternOffTime, false); flashState = WAIT; } break; case WAIT: if (patternRepeatCount > 0) patternRepeatCount--; if (patternRepeatCount == 0) { stopFlash(); if (flashFinishedCb) flashFinishedCb(); } else { // if -ve will keep going easygpio_outputSet(LED, LED_ON); flashCounter = flashCount; os_timer_arm(&flash_timer, flashOnTime, false); flashState = FLASHING_ON; } break; } }
void ICACHE_FLASH_ATTR lcdInit() { easygpio_pinMode(LCD_Light, EASYGPIO_NOPULL, EASYGPIO_OUTPUT); easygpio_outputEnable(LCD_Light, 1); easygpio_pinMode(LCD_SCE, EASYGPIO_NOPULL, EASYGPIO_OUTPUT); easygpio_outputEnable(LCD_SCE, 1); easygpio_pinMode(LCD_clk, EASYGPIO_NOPULL, EASYGPIO_OUTPUT); easygpio_outputEnable(LCD_clk, 0); easygpio_pinMode(LCD_Data, EASYGPIO_NOPULL, EASYGPIO_OUTPUT); easygpio_outputEnable(LCD_Data, 0); easygpio_pinMode(LCD_D_C, EASYGPIO_NOPULL, EASYGPIO_OUTPUT); easygpio_outputEnable(LCD_D_C, 0); // easygpio_pinMode(LCD_RST, EASYGPIO_NOPULL, EASYGPIO_OUTPUT); easygpio_outputSet(LCD_clk, 1); easygpio_outputSet(LCD_clk, 0); easygpio_outputEnable(LCD_SCE, 0); spi(0x21); // Extended Mode spi(0xC0); // Vop = 0x10 spi(0x06); // TC=2 spi(0x13); // Bias = 3 spi(0x20); // Basic mode, H addr spi(0x0c); // Normal mode clearLcd(); }
void ICACHE_FLASH_ATTR stopFlash(void) { easygpio_outputSet(LED, LED_OFF); flashState = OFF; os_timer_disarm(&flash_timer); }
void ICACHE_FLASH_ATTR stopActionFlash(void) { easygpio_outputSet(ACTION_LED, LED_OFF); flashActionState = OFF; os_timer_disarm(&flashA_timer); }
void ICACHE_FLASH_ATTR lightOff(void) { easygpio_outputSet(LCD_Light, 1); lightCount = 0; }
static void ICACHE_FLASH_ATTR gotoXY(uint8 x, uint8 y) { easygpio_outputSet(LCD_D_C, 0); spi(y|0x40); spi(x|0x80); }
void ICACHE_FLASH_ATTR lcdLight(bool on) { easygpio_outputSet(LCD_Light, on); }
void ICACHE_FLASH_ATTR lightOn(void) { easygpio_outputSet(LCD_Light, 0); lightCount = 100; // 10 secs }