Hello. I am new to programming Arduinos and would like to know how the following lines in "ControlLED.ino" and "SimpleIO" either send or get variables to or from the Ti Calulator
SimpleIO.ino
Code:
// Callback when the CBL2 class notices the attached calculator
// wants to start a Get() exchange. The CBL2 class needs to get
// any data to send before continuing the exchange.
int onSendAsCBL2(uint8_t type, enum Endpoint model, int* headerlen,
int* datalen, data_callback* data_callback)
{
Serial.print("Got request for variable of type ");
Serial.print(type);
Serial.print(" from endpoint of type ");
Serial.println((int)model);
if (type != VarTypes82::VarRList)
return -1;
// Compose the VAR header
*datalen = 2 + TIVar::sizeOfReal(model) * 2;
TIVar::intToSizeWord(*datalen, &header[0]); // Two bytes for the element count, ANALOG_PIN_COUNT Reals
// This sets header[0] and header[1]
header[2] = VarTypes85::VarRList; // RealList (if you're a TI-85. Bleh.)
header[3] = 0x01; // Name length
header[4] = 0x41; // "A", as per "standard" See http://www.cemetech.net/forum/viewtopic.php?p=224739#224739
header[5] = 0x00; // Zero terminator (remainder of header is ignored)
*headerlen = 11;
// Compose the body of the variable
data[0] = 2; // Little-endian word for number of
data[1] = 0; // elements in this list
int offset = 2; // Offset past the count word
// Convert the value, get the length of the inserted data or -1 for failure
int rval;
rval = TIVar::longToReal8x(digitalRead(BUTTON_PIN), &data[offset], model);
if (rval < 0) {
return -1;
}
offset += rval;
rval = TIVar::longToReal8x(digitalRead(SWITCH_PIN), &data[offset], model);
if (rval < 0) {
return -1;
}
offset += rval;
return 0;
}
ControlLed
Code:
// Callback when the CBL2 class notices the attached calculator
// wants to start a Get() exchange. The CBL2 class needs to get
// any data to send before continuing the exchange.
int onSendAsCBL2(uint8_t type, enum Endpoint model, int* headerlen,
int* datalen, data_callback* data_callback)
{
Serial.print("Got request for variable of type ");
Serial.print(type);
Serial.print(" from endpoint of type ");
Serial.println((int)model);
return -1; // -1 means we have no data to send.
}
and
Code:
// Callback when the CBL2 class has successfully received a variable
// from the attached calculator.
int onGetAsCBL2(uint8_t type, enum Endpoint model, int datalen) {
Serial.print("Got variable of type ");
Serial.print(type);
Serial.print(" from endpoint of type ");
Serial.println((int)model);
// We only want to handle lists.
if (type != VarTypes82::VarRList)
return -1;
// Turn the LEDs on or off
uint16_t list_len = TIVar::sizeWordToInt(&(data[0])); // Convert 2-byte size word to int
if (list_len == 1) {
// It is indeed a 1-element list
int value = TIVar::realToLong8x(&data[2], model); // First list element starts after 2-byte size word
Serial.print("Received value ");
Serial.println(value);
for(int i = 0; i < LED_PIN_COUNT; i++) {
digitalWrite(ledPins[i], (value >> i) & 0x01);
}
} else {
Serial.println("Must send a 1-element list!");
}
return 0;
}
Which functions, commands, or lines of code in the above manipulate the variables (and how) that send(VARIABLE) or get(VARIABLE) in Ti-basic use?