예제 #1
0
파일: MCP.cpp 프로젝트: Hukuma23/WS
void MCP::init(MQTT &mqtt) {
	DEBUG1_PRINTLN("MCP.init");
	delay(50);
	Wire.pins(4, 5);
	MCP23017::begin(0);

	pinMode(appSettings.m_int, INPUT);

	this->mqtt = &mqtt;

	for (byte i = 0; i < appSettings.msw_cnt; i++) {
		//DEBUG4_PRINTLN("MCP.2");
		MCP23017::pinMode(appSettings.msw[i], OUTPUT);
		MCP23017::digitalWrite(appSettings.msw[i], actStates.msw[i]);
	}

	pullup(appSettings.m_int);

	MCP23017::setupInterrupts(false, false, LOW);

	for (byte i = 0; i < appSettings.min_cnt; i++) {
		MCP23017::pinMode(appSettings.min[i], INPUT);
		MCP23017::pullUp(appSettings.min[i], HIGH);
		MCP23017::setupInterruptPin(appSettings.min[i], FALLING);
	}


	attachInterrupt(appSettings.m_int, Delegate<void()>(&MCP::interruptCallback, this), FALLING);
	//timer.initializeMs(30 * 1000, TimerDelegate(&MCP::publish, this)).start(); // every 25 seconds
	interruptReset();
}
예제 #2
0
/*
 * Return the next sensor structure from a sensor message
 */
msg_sensor_data_t* hmtl_next_sensor(msg_hdr_t *msg, msg_sensor_data_t *current) {
  byte* next = NULL;

  if (current) {
    next = (byte *)current + sizeof (msg_sensor_data_t) + current->data_len;
    if (next >= (byte *)msg + msg->length) {
      next = NULL;
    }
  } else {
    if (msg->length >= sizeof (msg_hdr_t) + sizeof (msg_sensor_data_t)) {
      next = (byte *)(msg + 1);
    }
  }

  DEBUG1_COMMAND(
    if (msg->type != MSG_TYPE_SENSOR) {
      DEBUG1_VALUELN("Not a sensor msg:", msg->type);
      next = NULL;
    }

    if (next) {
      if (next + sizeof (msg_sensor_data_t) + ((msg_sensor_data_t*)next)->data_len > (byte *)msg + msg->length) {
        DEBUG1_PRINTLN("Invalid sensor message");
        next = NULL;
      }
    }
                 );
예제 #3
0
파일: MCP.cpp 프로젝트: Hukuma23/WS
void MCP::interruptReset() {
	DEBUG1_PRINT("MCP.interruptReset");
	uint8_t pin = MCP23017::getLastInterruptPin();
	uint8_t last_state = MCP23017::getLastInterruptPinValue();

	DEBUG1_PRINTF("interrupt pin= %d, state=%d", pin, last_state);
	String msg = "interrupt pin= " + String(pin) + ", state= " + String(last_state);
	mqtt->publish("log_mcp_rst", OUT, msg);

	DEBUG1_PRINTLN();
}
예제 #4
0
파일: MCP.cpp 프로젝트: Hukuma23/WS
void MCP::longtimeHandler() {
	DEBUG4_PRINTLN("MCP.ltH");
	uint8_t act_state = MCP23017::digitalRead(pin);
	while (!(MCP23017::digitalRead(pin)));
	DEBUG4_PRINTF("push pin=%d state=%d. ", pin, act_state);

	byte num = appSettings.getMInNumByPin(pin);
	bool isLong = false;

	if (act_state == LOW) {
		//if (mqtt)
		//	mqtt->publish(appSettings.topMIN_L, num+1, OUT, (actStates.msw[num]?"ON":"OFF"));
		isLong = true;
		DEBUG1_PRINTLN("*-long-*");
	}
	else {
		isLong = false;
		DEBUG1_PRINTLN("*-short-*");
	}

	publish(num, actStates.msw[num], isLong);

	attachInterrupt(appSettings.m_int, Delegate<void()>(&MCP::interruptCallback, this), FALLING);
}
예제 #5
0
파일: MCP.cpp 프로젝트: Hukuma23/WS
void MCP::publish() {
	DEBUG4_PRINT("MCP.publish");

	for (byte i = 0; i < appSettings.msw_cnt; i++) {
		MCP23017::digitalWrite(appSettings.msw[i], actStates.getMsw(i));
		String strState = (actStates.getMsw(i)?"ON":"OFF");
		if (mqtt)
			mqtt->publish(appSettings.topMSW,i+1, OUT, strState);

		DEBUG1_PRINTF("sw[%d]=", i);
		DEBUG1_PRINT(strState);
		DEBUG1_PRINTLN();
	}
	PRINT_MEM();
	DEBUG4_PRINTLN();

	interruptReset();

}