Last active
July 29, 2018 17:13
-
-
Save sticilface/594a910c259e62455aefab8b2f12cd66 to your computer and use it in GitHub Desktop.
Transmitter_speed_sketch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//#define USE_SERIAL | |
//#define USE_ACK | |
#define SERIAL_METHOD ThroughAsyncSerial // ThroughSerial or ThroughAsyncSerial | |
#define SERIAL_SPEED 115200 | |
#define SWBB_PIN 2 // use 2 for arduino, 5 for ESP8266 | |
#if defined (USE_SERIAL) && defined (ESP32) | |
#define SERIAL_PORT Serial2 | |
#elif defined (USE_SERIAL) | |
#define SERIAL_PORT Serial1 | |
#endif | |
#ifndef USE_SERIAL // THIS IS A SWBB DEVICE.. on segment 0 | |
#define USE_SWBB | |
#define PJON_INCLUDE_SWBB | |
#define PJON_BUS_ID 5 // | |
#define PJON_SEND_TO_ID 155 | |
#else // THIS IS A Serial DEVICE.. on segment 1 | |
#define PJON_INCLUDE_TAS | |
#define PJON_INCLUDE_TS | |
#define PJON_BUS_ID 155 | |
#define PJON_SEND_TO_ID 5 | |
#endif | |
// Uncomment to run SoftwareBitBang in MODE 2 | |
// #define SWBB_MODE 2 | |
// Uncomment to run SoftwareBitBang in MODE 3 | |
// #define SWBB_MODE 3 | |
/* Acknowledge Latency maximum duration (1000 microseconds default). | |
Can be necessary to higher SWBB_RESPONSE_TIMEOUT to leave enough time to | |
receiver to compute the CRC and to respond with a synchronous acknowledgement | |
SWBB_RESPONSE_TIMEOUT can be reduced to higher communication speed if | |
devices are near and able to compute CRC fast enough. */ | |
//#define SWBB_RESPONSE_TIMEOUT 1000 | |
#include <PJON.h> | |
#ifdef USE_SWBB | |
// <Strategy name> bus(selected device id) | |
PJON<SoftwareBitBang> bus(PJON_BUS_ID); | |
#else | |
PJON<SERIAL_METHOD> bus(PJON_BUS_ID); | |
#endif | |
char content[] = "01234567890123456789"; | |
// 0 1 2 END ESC START 2 1 0 | |
uint8_t withEscape[] = { 0x30,0x31,0x32,0xea,0xBB,0x95,0x32,0x31,0x30 }; | |
void setup() { | |
#ifdef USE_SWBB | |
bus.strategy.set_pin(SWBB_PIN); | |
#else | |
SERIAL_PORT.begin(SERIAL_SPEED); // PJON | |
bus.strategy.set_serial(&SERIAL_PORT); | |
#endif | |
bus.set_error(error_handler); | |
bus.begin(); | |
Serial.begin(115200); | |
} | |
void error_handler(uint8_t code, uint16_t data, void *custom_pointer) { | |
if(code == PJON_CONNECTION_LOST) { | |
// Serial.print("Connection lost with device id "); | |
// Serial.println(bus.packets[data].content[0], DEC); | |
} | |
}; | |
uint32_t timer = 0; | |
void loop() { | |
//auto result = bus.send_packet_blocking(44, content, 20); | |
// if (result != PJON_ACK) { | |
// Serial.print("Send FAIL... "); | |
// Serial.println(result, HEX); | |
// } | |
// if (millis() - timer > 50) { | |
// //bus.send(44, content, 20); | |
// bus.send_packet_blocking(44, content, 20); | |
// timer = millis(); | |
// } | |
// | |
// bus.update(); | |
if (!bus.update()) { | |
bus.send(PJON_SEND_TO_ID, content, 20); | |
} | |
//// | |
// bus.receive(); // this is needed to flush the serial buffer!!! | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment