Skip to content

Commit

Permalink
Merge pull request #3 from osudrl/working-as-intended
Browse files Browse the repository at this point in the history
Fixed "Random Thousands" Bug
  • Loading branch information
kkevlar authored Aug 29, 2017
2 parents ff2d294 + b7a2110 commit cd01728
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 120 deletions.
15 changes: 7 additions & 8 deletions joy/joy.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

//#define JOY_SEND_DEBUG_ASCII //uncomment for some debugging information printed
// #define JOY_SEND_DEBUG_ASCII

#include "jt-constants.h"

Expand Down Expand Up @@ -79,10 +79,6 @@ void sport_flushInputBuffer(void)
{
while (Serial3.available())
Serial3.read();
usb_wasEscaped = false;
usb_currIndex = -1;
usb_lsbSet = false;
usb_lsb = 0;
}

void sport_setRX()
Expand Down Expand Up @@ -270,7 +266,8 @@ void sport_telemetry()
{
#ifdef JOY_SEND_DEBUG_ASCII
Serial.print("Gotten Behind by ");
Serial.print(((uint16_t) updateStoreIndex- updateSentIndex));
int printdiff = ((uint16_t) updateStoreIndex- updateSentIndex);
Serial.print(printdiff);
Serial.print(" and curr index is ");
#endif

Expand All @@ -294,8 +291,10 @@ void sport_setup()
pinMode(13, OUTPUT);
digitalWrite(13,LOW);
sport_hdInit();
Serial.begin(9600);
Serial.println("INIT");
Serial.begin(9600); //will actually be at 1.2M baud or something see Teensy site
#ifdef JOY_SEND_DEBUG_ASCII
Serial.println("INIT");
#endif
}

void sport_loop()
Expand Down
50 changes: 0 additions & 50 deletions serial/others/send-escaped.c

This file was deleted.

58 changes: 0 additions & 58 deletions serial/others/send-sqares.c

This file was deleted.

152 changes: 148 additions & 4 deletions serial/serial-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include <pthread.h>
#include "../joy/jt-constants.h"

#define SERIAL_TEST_COUNTING
// #define SERIAL_TEST_ESCAPING
// #define SERIAL_TEST_SQAURES

void* serial_read()
{
FILE* input;
Expand All @@ -30,9 +34,12 @@ void* serial_read()
}
}

FILE* output;

#ifdef SERIAL_TEST_COUNTING

int16_t sourceInts[tele_DATA_COUNT];
uint8_t printBuffer[tele_MAX_BUF];
FILE* output;
int build_escaped_buffer(int16_t* source, uint8_t* result)
{
int buildIndex = 0;
Expand Down Expand Up @@ -70,7 +77,9 @@ void sendBuffer(uint8_t* buf, int filled)

void* serial_write()
{

printf("The Counting Serial Test\n");
#warning "The Counting Serial Test"

output = fopen("/dev/ttyACM1", "w"); //open the terminal screen
if ( output == NULL )
{
Expand All @@ -79,10 +88,10 @@ void* serial_write()
if (output == NULL)
{
printf("ACM0 is also NULL. Exiting.\n");
return 1;
return (void*) 1;
}
}
cpSleep(2000);
cpSleep(100);
while(true)
{
for(int i = 0; i < tele_DATA_COUNT; i+=1 )
Expand All @@ -109,6 +118,141 @@ void* serial_write()
fclose(output);
}

#elif SERIAL_TEST_ESCAPING

void* serial_write()
{
printf("Escaped Serial Test\n");
#warning "Escaped Serial Test"
output = fopen("/dev/ttyACM1", "w"); //open the terminal screen
if ( output == NULL )
{
printf("ACM1 is NULL, trying ACM0.\n");
output = fopen("/dev/ttyACM0", "w");
if (output == NULL)
{
printf("ACM0 is also NULL. Exiting.\n");
return (void*) 1;
}
}

cpSleep(100);
fprintf(output,"%c",0xfe);
fprintf(output,"%c",0x88);

//the rest are numbers
fprintf(output,"%c",0x00);
fprintf(output,"%c",0x00);
fprintf(output,"%c",0x01);
fprintf(output,"%c",0x00);
fprintf(output,"%c",0x04);
fprintf(output,"%c",0x00);
fprintf(output,"%c",0x09);
fprintf(output,"%c",0x00);
fprintf(output,"%c",0x10);
fprintf(output,"%c",0x00);
fprintf(output,"%c",0x19);
fprintf(output,"%c",0x00);

//modified value 6
//fprintf(output,"%c",0x24);
fprintf(output,"%c",0xFE); // escape byte
fprintf(output,"%c",0xFE); // tells teensy the value actually is 254
fprintf(output,"%c",0x00);

fprintf(output,"%c",0x31);
fprintf(output,"%c",0x00);
fprintf(output,"%c",0x40);
fprintf(output,"%c",0x00);
fprintf(output,"%c",0x51);
fprintf(output,"%c",0x00);
fprintf(output,"%c",0x64);
fprintf(output,"%c",0x00);
fprintf(output,"%c",0x79);
fprintf(output,"%c",0x00);
fprintf(output,"%c",0x90);
fprintf(output,"%c",0x00);
fprintf(output,"%c",0xA9);
fprintf(output,"%c",0x00);

fflush(output);
fclose(output);

}

#else

int main()
{
printf("Squares Serial Test\n");
#warning "Squares Serial Test"
output = fopen("/dev/ttyACM1", "w"); //open the terminal screen
if ( output == NULL )
{
printf("ACM1 is NULL, trying ACM0.\n");
output = fopen("/dev/ttyACM0", "w");
if (output == NULL)
{
printf("ACM0 is also NULL. Exiting.\n");
return (void*) 1;
}
}

cpSleep(100);

//header bytes
fprintf(output,"%c",0xfe);
fprintf(output,"%c",0x88);

//the rest are numbers
fprintf(output,"%c",0x00);
fprintf(output,"%c",0x00);

fprintf(output,"%c",0x01);
fprintf(output,"%c",0x00);

fprintf(output,"%c",0x04);
fprintf(output,"%c",0x00);

fprintf(output,"%c",0x09);
fprintf(output,"%c",0x00);

fprintf(output,"%c",0x10);
fprintf(output,"%c",0x00);

fprintf(output,"%c",0x19);
fprintf(output,"%c",0x00);

fprintf(output,"%c",0x24);
fprintf(output,"%c",0x00);

fprintf(output,"%c",0x31);
fprintf(output,"%c",0x00);

fprintf(output,"%c",0x40);
fprintf(output,"%c",0x00);

fprintf(output,"%c",0x51);
fprintf(output,"%c",0x00);

fprintf(output,"%c",0x64);
fprintf(output,"%c",0x00);

fprintf(output,"%c",0x79);
fprintf(output,"%c",0x00);

fprintf(output,"%c",0x90);
fprintf(output,"%c",0x00);

fprintf(output,"%c",0xA9);
fprintf(output,"%c",0x00);

fflush(output);
fclose(output);
}

#endif

int main()
{
pthread_t sreader;
Expand Down

0 comments on commit cd01728

Please sign in to comment.