Commit c48c1d43 authored by ryukoposting's avatar ryukoposting

UNO framework

parent f8228a9d
......@@ -21,11 +21,49 @@
#include "../pcgpio_mcu.h"
enum PCGPIO_Status PCGPIO_Start() {
Serial.begin(115200);
}
enum PCGPIO_Status PCGPIO_TransmitCallback(struct PCGPIO_Callback *callback) {
uint8_t buffer[16] = {0xA5, callback->callback_type, };
int length = 0;
switch(callback->callback_type) {
case PCGPIO_CALLBACKTYPE_MCUIDENTITY:
length = 6;
buffer[2] = (((callback->callback.mcu_identity.mcu_identifier) >> 8) & 0xFF);
buffer[3] = ((callback->callback.mcu_identity.mcu_identifier) & 0xFF);
buffer[4] = ((callback->callback_type + buffer[2] + buffer[3]) & 0xFF);
buffer[5] = 0x0A;
break;
case PCGPIO_CALLBACKTYPE_READDIGITAL:
length = 6;
buffer[2] = callback->callback.read_digital.pin;
buffer[3] = callback->callback.read_digital.value;
buffer[4] = ((callback->callback_type + buffer[2] + buffer[3]) & 0xFF);
buffer[5] = 0x0A;
break;
case PCGPIO_CALLBACKTYPE_READANALOG:
length = 9;
buffer[2] = callback->callback.read_analog.pin;
buffer[3] = ((callback->callback.read_analog.value >> 24) & 0xFF);
buffer[4] = ((callback->callback.read_analog.value >> 16) & 0xFF);
buffer[5] = ((callback->callback.read_analog.value >> 8) & 0xFF);
buffer[6] = callback->callback.read_analog.value & 0xFF;
buffer[7] = ((buffer[1] + buffer[2] + buffer[3] + buffer[4] + buffer[5] + buffer[6]) & 0xFF);
buffer[8] = 0x0A;
break;
case PCGPIO_CALLBACKTYPE_GETPINCONFIG:
length = 6;
buffer[2] = callback->callback.get_pin_config.pin;
buffer[3] = callback->callback.get_pin_config.conf;
buffer[4] = ((callback->callback_type + buffer[2] + buffer[3]) & 0xFF);
buffer[5] = 0x0A;
break;
default:
return PCGPIO_STATUS_INVALID_CALLBACK;
}
Serial.write(buffer, length);
return PCGPIO_STATUS_OK;
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment