Announcement

Collapse
No announcement yet.

OLED Logic Issues

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • OLED Logic Issues

    I have been having several issues with Goldelox and 4DGL, but the most significant I have come across is that I have if statements that are not working properly. Literally, the code is if(FALSE), which should never run, and yet, every other time I send input via the terminal, the if-statement block executes as if the statement itself is not there at all. I've double checked my syntax and done some other testing; I'm at quite a loss here.

    Thanks.

  • #2
    Hello,

    Welcome to the forum,

    It would be great if you could send us an example of your code that is causing you a problem. A lot of the time it can be a simple error like 'if(a = b)' instead of how it should be, 'if(a == b)'

    Best regards

    Paul

    Comment


    • #3

      Thats what i thought, but i literally typed "if(FALSE)" and the code would still run

      Comment


      • #4
        Hi,

        if(FALSE) should only be true if FALSE is not 0. A negative number would also become true

        When you declare FALSE, 'var FALSE;' do you assign it a value.

        Have you tried printing out FALSE to see what it returns eg.

        print(FALSE);

        Paul

        Comment


        • #5
          So you don't have real booleans in this language? Okay. Not sure why you would have them as keywords if you didn't, but I can roll with it. Here's my main problem. I'm taking binary input from a microcontroller, but I need to concatenate the 2 bytes of data together into a single value, and then convert it to decimal. In reading through every doc I can find, I cannot find anything that allows Goldelox to perform such an action, though it appears possible in Picasso and Diablo. Am I missing something, or is that an accurate assessment?

          Comment


          • #6
            Hi,

            Sorry about that, I tried it with a Diablo as I didn't have a Goldelox to hand but I have tried it now with a Goldelox and if(FALSE) works fine for me. Not sure why it would fail on your display.

            If I understand correctly, you can use this code to concatenate the 2 bytes into 1 single number,

            var num;
            var msb := 1;
            var lsb := 10;
            num := msb << 8 | lsb

            num would equal 266;

            Paul

            Comment


            • #7
              Thanks.
              The code works fine for literals, but for some reason it's having trouble with using array elements instead. for example, this outputs just 00

              var a,b;
              msb := input[0];
              lsb := input[1];
              num := msb << 8 | lsb;
              to(COM0);print([DEC] val);

              Comment


              • #8
                Hi,

                It is just a typo which is making it fail. I have modified your example, you won't need var msb, lsb; if you have already declared them elsewhere

                var a,b;
                var msb, lsb;
                msb := input[0];
                lsb := input[1];
                num := msb << 8 | lsb;
                to(COM0);print([DEC] num);

                Best regards

                Paul

                Comment


                • #9
                  woops, I was freehanding the var names a bit so our code would look more similar and we both could keep vars and things straight. Looks like I forgot to swap everything in my rush. I got it working by writing the BIN values from the array using to(). So i ended up with

                  to(a); print([BIN] input[0]);

                  since just going right from the array to a new var didn't appear to work at all.

                  Thanks for the help
                  Patrick

                  Comment


                  • #10
                    Am I not allowed to use to() on a var that has not been initalized? I want to condense my code and the whole thing breaks when I don't initialize a or b

                    Comment


                    • #11
                      Also, I spoke too early. It's still not returning anything besides 00 to COM0, or its still the wrong output. Just didn't look closely enough originally. Maybe I'm massively wrong here, I'll drop you my code.
                      Given input of 01110114EA1B via the terminal, its looking to pull 14EA from the input, convert it to BIN because that's what the real microcontroller will be sending it as, and then converting it to decimal and outputting it. Now, I know it can pull the values just fine, because when I output them to COM0, it does what it's suppoesed to, every time. It's the conversion part that is really mucking up everything and I have no idea why, as I've tried many different ways, and they seem to work for everyone but me. Maybe you can help here. Thanks for everything.


                      Code:
                      #platform "GOLDELOX"
                      #inherit "4DGL_16bitColours.fnc"
                      #inherit "VisualConst.inc"
                      #inherit "NoName1Const.inc"
                      #inherit "PrintDiskGoldelox.inc"
                      #inherit "LedDigitsDisplayGoldelox.inc"
                      
                      func main()
                          print("Starting\n") ;
                          while(!media_Init())
                              putstr("Drive not mounted...");
                              pause(200);
                              gfx_Cls();
                              pause(200);
                          wend
                          var buffer[48], input;
                          repeat
                              repeat
                              pokeW(TIMER0, 5000);
                                  setbaud(BAUD_9600);
                                  com_Init(buffer, 48, 0);
                                  var input_Data[10];
                                  var value:="";
                                  repeat
                                      while ( (input := serin()) >= 0)
                                          if(input == 0x01) //if 0h01 has been sent to indicate that the input is writing to an object
                                              var count:=0;
                                              while((input:=serin())>=0)
                                                  input_Data[count] := input;
                                                  to(COM0);print([HEX2]input_Data[count]);
                                                  count++;
                                                  if(input==0x1B) break;
                                              wend
                      
                                              switch (input_Data[0])
                                                  case 0x11:
                                                      //txt_MoveCursor(input_Data[1]-1,7);
                                                      txt_MoveCursor(5,0);
                                                      break;
                                                  case 0xA2:
                                                      break;
                                                  case 0xA3:
                                                      break;
                                              endswitch
                                  //Everything up until here works just fine, in terms of itself. Maybe it's interacting weird with this later code
                                              value:=0;
                                              //to(COM0);print([BIN]input_Data[2],[BIN]input_Data[3]); //now we have the whole BIN value concatted together
                                              //The above line woorks when I send it to COM0, but not if I try and use to(value);
                                              txt_MoveCursor(0,0);
                                              //if(TRUE)
                                                  var a,b;
                                                  //a := input_Data[2];
                                                  //b := input_Data[3];
                                                  to(a);print([BIN]input_Data[2]);
                                                  to(b);print([BIN]input_Data[3]);
                                                  value:= a << 8|b;
                                                  to(COM0);print(value);
                                              //endif
                                          endif
                                      wend
                      
                                  until (!peekW(TIMER0));           // loop until TIME_OUT register is 0
                      
                                  if (com_Full()) print("Buffer Full ");
                                  if (com_Error()) print("Comms Error ");
                      
                                  pause(3000);
                              until ( com_Full() || com_Error() );      // reset if error occurred
                          forever
                      endfunc

                      Comment


                      • #12
                        Hi Patrick,

                        Yes this code is the problem,

                        var a,b;
                        //a := input_Data[2];
                        //b := input_Data[3];
                        to(a);print([BIN]input_Data[2]);
                        to(b);print([BIN]input_Data[3]);
                        value:= a << 8|b;

                        This line ' to(a);print([BIN]input_Data[2]);' is trying to create a string of the binary so we can't use 'value:= a << 8|b;' to convert to a value.

                        I will work with this part, when you say the microcontroller is pushing out binary can you explain a bit more how this will arrive at the display.

                        Best regards

                        Paul




                        Comment


                        • #13
                          The input would come from the microcontroller via a UART cable. I must not have mentioned that I am doing all this on a uOLED 96 G2

                          Comment


                          • #14
                            Hi Patrick,

                            Thanks for the information, Yes you did mention the type of display / processor you are using so that is all ok. If binary is being sent as "10101010" (170) as ASCII text then yes we would have to convert this to a real number first. There wont be a built in command to do this but I will do some testing.

                            Best regards

                            Paul

                            Comment


                            • #15
                              No, it's being sent as raw binary. My initial approach was actually to try and treat it as/convert it to a string literal and manipulate that, instead of trying to manipulate the raw binary values, and that did not produce anything viable.

                              Comment

                              Working...
                              X