Phi_prompt new release teaser - scrolling list items

mowcius:
I'd be interested to have a look at what you wrote for the scrolling text function - got a couple of ideas that I'd like to try with the scroll bar.

mowcius, here they are:

  1. The function that renders "long message", so displaying (including scroll bar) is done here:
void long_msg_lcd(phi_prompt_struct* para)
{
  byte columns=para->step.i/100, rows=para->step.i%100, ch;
  if (para->low.i>=strlen(para->ptr.msg)) ch=0;
  else ch=para->ptr.msg[para->low.i];
  for (byte i=0;i<rows;i++)
  {
    lcd->setCursor(para->col,para->row+i);
    for (byte j=0;j<columns;j++)
    {
      if (ch==0) lcd->write(' ');
      else
      {
        lcd->write(ch);
        ch=para->ptr.msg[para->low.i+i*columns+j+1];
      }
    }
  }
  if (para->option==1)
  {
    byte location=int((((float)para->low.i)/strlen(para->ptr.msg)*(rows*2-2)));
    for (byte i=0;i<rows;i++)
    {
      lcd->setCursor(para->col+columns,para->row+i);
      if (i==0)
      {
        if (location==0) lcd->write(0);
        else lcd->write(1);
      }
      
      else if (i==rows-1)
      {
        if (location==(rows*2-2-1)) lcd->write(5);
        else lcd->write(4);
      }

      else if ((location+1)/2==i)
      {
        if ((location-1)/2*2==location-1) lcd->write(2);
        else lcd->write(3);
      }
      else lcd->write(' ');
      
    }
  }
}
  1. This function interacts with the user (via keypad call wait_on_escape and lcd via the long_message function) so scrolling is done here:
    The reason I called this function text area is to correspond to Java's text area to display text.
int text_area(phi_prompt_struct *para)
{
  byte columns=para->step.i/100, rows=para->step.i%100, ch;
  long_msg_lcd(para);
  while(true)
  {
    byte temp1=wait_on_escape(50);
    switch (temp1)
    {
      case 1:
      if (para->low.i+columns<para->high.i)
      {
        para->low.i+=columns;
        long_msg_lcd(para);
      }
      break;
      
      case 2:
      if (para->low.i-columns>=0)
      {
        para->low.i-=columns;
        long_msg_lcd(para);
      }
      break;
      case 3: // Left is pressed
      return(-3);
      break;
      
      case 4: // Right is pressed
      return(-4);
      break;
      
      case 5: // Enter is pressed
      return(1);
      break;
      
      case 6: // Escape is pressed
      return (-1);
      break;
      
      default:
      break;
    }
  }
}
  1. Here's the struct in case you need it to understand the code:
    It tells you what each field holds besides comments inline with the code.
union buffer_pointer
{
int *i_buffer;
float * f_buffer;
char ** list;
char* msg;
};

union four_bytes
{
int i;
long l;
float f;
byte b;
char c;
};

struct phi_prompt_struct
{
  buffer_pointer ptr;
  four_bytes low; // Lower limit for text panel (.c), integers (.i) and floats (.f) and default item for list (.i)
  four_bytes high; // Upper limit for text panel (.c), integers (.i) and floats (.f) and last item for list (.i)
  four_bytes step;// Step size for integers (.i) and integer/decimal for floats (.i), such as 302 means 3 digits before decimal and 2 digits after.
  byte col; // Which column to display input
  byte row; // Which row to display input
  byte width; // Maximal number of character on integers, floats, a list item, and total allowed input characters for text panel
  int option; // What display options to choose
//  LiquidCrystal *lcd; // Which display to use. Removed in second release
//  phi_buttons **btns; // Which series of buttons to use. Removed in second release
  void (*update_function)(phi_prompt_struct *); // This is not being used in this version but reserved for future releases.
}; //22 bytes