Shop OBEX P1 Docs P2 Docs Learn Events
PST input - Timer that expires with no entry — Parallax Forums

PST input - Timer that expires with no entry

Hello,

I think there are a bunch of ways to do this, but currently I'm drawing a blank
I'm using spin,

I have a PST loop as below:

Hex_value := $FFFFFFFF PST.Str(string("Enter the hex value to be used - max FFFFFFFF ")) ' get entry from the keyboard on pst start repeat Hex_value := PST.HexIn ' wait for character to be typed PST.Str(string("Value entered: ")) PST.Hex(Hex_Value,8) PST.NewLine quit

I would like the repeat loop to expire after maybe 10 seconds, in case there is no input, or there is no PST connected, so that the program can continue using the default values.

Hex_value := $FFFFFFFF PST.Str(string("Enter the hex value to be used - max FFFFFFFF ")) ' get entry from the keyboard on pst start repeat ' until timer expires Hex_value := PST.HexIn ' wait for character to be typed PST.Str(string("Value entered: ")) PST.Hex(Hex_Value,8) PST.NewLine quit

I searched the forum and I didn't find anything,

any help would be appreciated

regards

Jeff

Comments

  • JonnyMacJonnyMac Posts: 8,926
    edited 2022-05-10 22:57

    You're going to need a customized entry method with a timeout. Have a look at .rxtime() in fullduplexserial.spin to see how you can add a time-out to an input. This feature is not part of the simple PST object.

    This works:

    pub hex_entry(p_prompt, toms, digits, default) | c, d, n
    
      term.str(p_prompt)
    
      c := term.rxtime(toms)                                        ' wait for 1st char
      if (c < 0)                                                    ' if timeout
        return default                                              '  return default value
    
      d := to_hex(c)                                                ' convert to hex
      if (d < 0)                                                    ' if not hex
        return default                                              '  abort with default
      else
        term.tx(c)                                                  ' update termina.
        result := d                                                 ' set initial result
        n := 1                                                      ' set digits count
    
      repeat
        c := term.rx                                                ' get a character
        case c
          8 :                                                       ' Backspace
            if n > 0                                                ' digits to erase?
              term.tx(8)                                            ' clear from terminal
              result >>= 4                                          ' remove last digit from result
              n -= 1                                                ' update digit count
    
          13 :                                                      ' Enter
            return result
    
          other :
            d := to_hex(c)                                          ' convert to hex
            if (d => 0)                                             ' if valid hex
              term.tx(c)                                            '  display
              result := (result << 4) | d                           '  update result
              n += 1                                                '  bump digit count
    
    
    
    pub to_hex(c)
    
      if (c => "a") and (c =< "z")
        c -= 32                                                     ' make uppercase
    
      result := lookdown(c : "0123456789ABCDEF") - 1
    
  • I was trying to stay with PST, and this feature is not super important, more of a diag work, so I just used a pin to enable or disable the feature.

  • Jeffrey KaneJeffrey Kane Posts: 48
    edited 2022-05-12 14:01

    results, works great :)

    if you wait for the time to expire you get the default which is 00000000

    thanks

    Jeff

Sign In or Register to comment.