Ejemplo n.º 1
0
// Command handler to add a callback to the named-callbacks list, this is for a callback to the uC
static uint32_t ICACHE_FLASH_ATTR
CMD_AddCallback(CmdPacket *cmd) {
  CmdRequest req;
  CMD_Request(&req, cmd);
#ifdef CMD_DBG
  os_printf("CMD_AddCallback: setup argc=%ld\n", CMD_GetArgc(&req));
#endif
  if (cmd->argc != 1 || cmd->callback == 0)
    return 0;

  char name[16];
  uint16_t len;

  // get the sensor name
  len = CMD_ArgLen(&req);
#ifdef CMD_DBG
  os_printf("CMD_AddCallback: name len=%d\n", len);
#endif
  if (len > 15) return 0; // max size of name is 15 characters
  if (CMD_PopArg(&req, (uint8_t *)name, len)) return 0;
  name[len] = 0;
#ifdef CMD_DBG
  os_printf("CMD_AddCallback: name=%s\n", name);
#endif

  return CMD_AddCb(name, (uint32_t)cmd->callback); // save the sensor callback
}
Ejemplo n.º 2
0
// Command handler for Wifi connect command
static uint32_t ICACHE_FLASH_ATTR
CMD_WifiConnect(CmdPacket *cmd) {
  CmdRequest req;
  CMD_Request(&req, cmd);
	if(cmd->argc != 2 || cmd->callback == 0)
		return 0;

  if (!wifiCbAdded) {
    wifiAddStateChangeCb(CMD_WifiCb);    // register our callback with wifi subsystem
    wifiCbAdded = true;
  }
  CMD_AddCb("wifiCb", (uint32_t)cmd->callback); // save the MCU's callback
  lastWifiStatus = 0xff; // set to invalid value so we immediately send status cb in all cases
  CMD_WifiCb(wifiState);

  return 1;
}