Пример #1
0
LOCAL void ICACHE_FLASH_ATTR buttonTask(void *pvParameters)
{
	static uint32_t messageId = 0;
	uint8_t 	loopIndex;
	uint8_t 	currentValue;
	uint8_t 	remoteRequest[50] = {0};
	uint32_t 	remoteRequestLength;

	DBGINF(("Button task initiated"));
	vTaskDelay(100);
	DBGINF(("Button task running"));

	for (loopIndex = 0; loopIndex < CTNC_MAX_NUMBER_OF_RESOURCE; loopIndex++) {
		if (CTNC_RES_TYPE_BINARY_INPUT == fResource[loopIndex].type) {
			PIN_FUNC_SELECT(fResource[loopIndex].gpioName, fResource[loopIndex].gpioFunc);
			PIN_PULLUP_EN(fResource[loopIndex].gpioName);

			//GPIO_DIS_OUTPUT(GPIO_ID_PIN(fResource[loopIndex].gpioNumber));
			gpio_output_set(0, BIT(GPIO_ID_PIN(fResource[loopIndex].gpioNumber)), 0,0);
		}
	}
	DBGINF(("All resource output set to current values."));

	while (1) {
		for (loopIndex = 0; loopIndex < CTNC_MAX_NUMBER_OF_RESOURCE; loopIndex++) {
			fResource[loopIndex].lacheValue++;
			currentValue = GPIO_READ(fResource[loopIndex].gpioNumber);
			if ( (currentValue != fResource[loopIndex].value) ||
				 (fResource[loopIndex].lacheValue >= 5000) ) {
				fResource[loopIndex].value = currentValue;
				fResource[loopIndex].lacheValue = 0;

				messageId++;
				remoteRequestLength = snprintf(
										&remoteRequest[0], 50, "/%d/%s/%s/uresval/%d/%d",
										messageId,
										MESH_getNodeID(),
										MESH_getNodeID(),
										fResource[loopIndex].id, fResource[loopIndex].value);

				for (loopIndex = 0; loopIndex < 4; loopIndex++) {
					sendUDPData(remoteRequest, remoteRequestLength);
					vTaskDelay(50);
				}

				break;
			}
		}

		vTaskDelay(CTNC_BTN_TASK_SLEEP);
	}

    DBGERR(("QUITING BUTTON TASK, This is never expected"));
    vTaskDelete(NULL);
}
Пример #2
0
void sendUDPMessage(char msg[64])
{
	UdpData data;
	data.length = 0;
	while(msg[data.length] != '\0' && data.length < 63)
	{
		data.msg[data.length] = (uint8_t)msg[data.length];
		data.length++;
	}
	sendUDPData(data);
}
Пример #3
0
void sendUDPMessageWithValue(char msg[64], uint16_t value)
{

	UdpData msgData = getMsgData(msg);
	UdpData valData = getValueData(value);
	UdpData result;
	result.length = (msgData.length + valData.length);
	for(int i=0;i<msgData.length;i++)
	{
		result.msg[i] = msgData.msg[i];
	}
	for(int j=msgData.length;j<result.length;j++)
	{
		result.msg[j] = valData.msg[j-msgData.length];
	}
	sendUDPData(result);
}
Пример #4
0
void sendUDPValue(uint16_t value)
{
	UdpData data = getValueData(value);
	sendUDPData(data);

}