linux screen tool for communication with microcontroller

Go To Last Post
62 posts / 0 new

Pages

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I cannot believe anyone really writes C code that looks like that! Is it the case that when you put it through whatever process that colorizes it that at that same time the indentation tabs are being lost? 

 

Anyway the start of the code seems to be:

void experiment_handler(char command){
	static uint8_t p5, o1, o2, o3;
	static int16_t p1, p2, p3;
	static uint16_t u1, u2, u3, u4;
	static int16_t pcv1, pcv2;
	static uint16_t pct1, pct2;
	static uint32_t cv;
	static int32_t cc;
	static uint32_t cd, ci;
	uint16_t tcs_data[] = {0,0,0,0};
	uint16_t tcs_data1[] = {0,0,0,0};
	switch (command){
		case 'A': //ADS Buffer/rate/PGA values from ads1255.h
		scanf("%hhx%hhx%hhx",&o1,&o2,&o3);
		printf("#A: %x %x %x\n",o1,o2,o3);
		ads1255_setup(o1, o2, o3);
		break;
		case 'G': //Gain
		scanf("%u%hhu",&g_gain, &g_short);
		printf("#G: %u %u\n", g_gain, g_short);
		pot_set_gain(); //uses global g_gain, so no params
		break;

so if 'E' triggers it to this routine I guess it's the 'G' processing here you expect to execute next?

 

I have no idea why you think this would cause it to print "30K" ? On receiving E then G the next thing is does is a scanf() waiting to receive the gain values. It then echoes them back after "#G:". So the dialog you showed previously:

          c------------------#

           k------------------twi master enabled

           !------------------- c

           EG----------------- 30K

is surely much more like:

          c------------------#

           k------------------twi master enabled

           !------------------- C

           EG-----------------
           123

           456---------------  #G: 123 456

or something like that isn't it?

 

It does not help that your cyclomatic complexity is about 10 times where it should be! 

 

Break this code into smaller functions and smaller files and it would be much easier to follow and to debug.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

I cannot believe anyone really writes C code that looks like that! Is it the case that when you put it through whatever process that colorizes it that at that same time the indentation tabs are being lost? 

 

Anyway the start of the code seems to be:

void experiment_handler(char command){
	static uint8_t p5, o1, o2, o3;
	static int16_t p1, p2, p3;
	static uint16_t u1, u2, u3, u4;
	static int16_t pcv1, pcv2;
	static uint16_t pct1, pct2;
	static uint32_t cv;
	static int32_t cc;
	static uint32_t cd, ci;
	uint16_t tcs_data[] = {0,0,0,0};
	uint16_t tcs_data1[] = {0,0,0,0};
	switch (command){
		case 'A': //ADS Buffer/rate/PGA values from ads1255.h
		scanf("%hhx%hhx%hhx",&o1,&o2,&o3);
		printf("#A: %x %x %x\n",o1,o2,o3);
		ads1255_setup(o1, o2, o3);
		break;
		case 'G': //Gain
		scanf("%u%hhu",&g_gain, &g_short);
		printf("#G: %u %u\n", g_gain, g_short);
		pot_set_gain(); //uses global g_gain, so no params
		break;

so if 'E' triggers it to this routine I guess it's the 'G' processing here you expect to execute next?

 

I have no idea why you think this would cause it to print "30K" ? On receiving E then G the next thing is does is a scanf() waiting to receive the gain values. It then echoes them back after "#G:". So the dialog you showed previously:

          c------------------#

           k------------------twi master enabled

           !------------------- c

           EG----------------- 30K

is surely much more like:

          c------------------#

           k------------------twi master enabled

           !------------------- C

           EG-----------------
           123

           456---------------  #G: 123 456

or something like that isn't it?

 

It does not help that your cyclomatic complexity is about 10 times where it should be! 

 

Break this code into smaller functions and smaller files and it would be much easier to follow and to debug.

 

when i type in just EG, nothing is shown on the terminal till i type in ! (which releases 30k)

autogain_enable = 0;

g_gain = POT_GAIN_30k;<---- this 30k from the main.c

pot_set_gain();

settings_read_eeprom();

 

    while(1){

        while(getchar() != 'c');

        putchar('#');

        while(getchar() != 'k');

        printf("\n\r");

        break;

    }

 

    tcs_init();

    

    program_loop:

        while(getchar() != '!');

        printf ("C\n");

        command_handler(getchar());

    goto program_loop;

}

 

 

 

is there a way the 30k can just display on the terminal without the need to input !

 

also how do i input any of tHe gain values below with the EG. if for example gain 100k, how do i do that based on the scanf statement and why is gshort equal to zero

uint8_t g_short = 0;

scanf("%u%hhu",&g_gain, &g_short);

printf("#G: %u %u\n", g_gain, g_short);

 

 

 

example of a gain value

case POT_GAIN_100M:

ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, 0);

ioport_set_port_level(IOPORT_PORTD, PIN4_bm, 0);

printf("#INFO: 100M\n");

break;

 

 

 

thank you

Josh

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

when i type in just EG, nothing is shown on the terminal till i type

But the code is behaving as YOU wrote it? Like I say, if you follow the path of 'E' then 'G' the next thing you hit is:

scanf("%u%hhu",&g_gain, &g_short);

So that's going to sit and wait for you to type in the numbers isn't it?

Last Edited: Thu. Jul 11, 2019 - 04:30 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

when i type in just EG, nothing is shown on the terminal till i type

But the code is behaving as YOU wrote it? Like I say, if you follow the path of 'E' then 'G' the next thing you hit is:

scanf("%u%hhu",&g_gain, &g_short);

So that's going to sit and wait for you to type in the numbers isn't it?


Alright bro. Thank you so much

Josh

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK so as I say you would type:

 

E

G

123 456

 

then it will respond with 

 

#G 123 456

 

I've no idea where "30K" might be expected to come from.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But %hhu is unsigned character. Can i type
E
G

30k

Josh

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No. What do you think "k" would mean in this?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
No. What do you think "k" would mean in this?

I mean K like;
case POT_GAIN_100K:

Josh

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Who's" on first, "What's" on second, "I don't know's" on third!!!  cheeky

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you mean 30000 then type 30000. scanf does not know SI multipliers like K, M etc

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

working perfectly guys. thank you so much @clawson @curvtm

learnt alot in this fews days honestly

Josh

Pages