Subversion Repositories svn.mios32

Rev

Rev 1250 | Rev 1267 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1250 Rev 1264
Line 1... Line 1...
1
// $Id: scs.c 1250 2011-07-13 21:23:17Z tk $
1
// $Id: scs.c 1264 2011-07-19 21:59:04Z tk $
2
//! \defgroup SCS
2
//! \defgroup SCS
3
//!
3
//!
4
//! This code handles the Standard Control Surface (SCS)
4
//! This code handles the Standard Control Surface (SCS)
5
//! with a 2x20 LCD, 5 soft buttons, one rotary encoder and one MENU button
5
//! with a 2x20 LCD, 5 soft buttons, one rotary encoder and one MENU button
6
//!
6
//!
Line 775... Line 775...
775
    } break;
775
    } break;
776
776
777
    /////////////////////////////////////////////////////////////////////////
777
    /////////////////////////////////////////////////////////////////////////
778
    case MENU_STATE_INSIDE_PAGE:
778
    case MENU_STATE_INSIDE_PAGE:
779
    case MENU_STATE_EDIT_ITEM: {
779
    case MENU_STATE_EDIT_ITEM: {
780
      int i;
-
 
781
      scs_menu_item_t *pageItems = NULL;
780
      scs_menu_item_t *pageItems = NULL;
782
      u8 numItems = 0;
781
      u8 numItems = 0;
783
      if( rootTableSelectedPage < rootTableNumItems ) {
782
      if( rootTableSelectedPage < rootTableNumItems ) {
784
    pageItems = (scs_menu_item_t *)rootTable[rootTableSelectedPage].page;
783
    pageItems = (scs_menu_item_t *)rootTable[rootTableSelectedPage].page;
785
    numItems = rootTable[rootTableSelectedPage].numItems;
784
    numItems = rootTable[rootTableSelectedPage].numItems;
786
      }
785
      }
787
786
-
 
787
      if( !pageItems ) {
-
 
788
    SCS_LCD_CursorSet(0, 0);
-
 
789
    SCS_LCD_PrintStringPadded("!! ERROR !!", SCS_LCD_MAX_COLUMNS);
-
 
790
    SCS_LCD_CursorSet(0, 1);
-
 
791
    SCS_LCD_PrintStringPadded("!! INVALID PAGE ITEMS !!", SCS_LCD_MAX_COLUMNS);
-
 
792
      } else {
788
      // check for full screen message
793
    // check for full screen message
789
      u8 printCommonPage = 1;
794
    u8 printCommonPage = 1;
790
      if( scsMenuState == MENU_STATE_EDIT_ITEM ) {
795
    if( scsMenuState == MENU_STATE_EDIT_ITEM ) {
791
    scs_menu_item_t *pageItem = NULL;
796
      scs_menu_item_t *pageItem = NULL;
792
    if( rootTableSelectedItem < numItems )
797
      if( rootTableSelectedItem < numItems )
Line 808... Line 813...
808
      SCS_LCD_PrintStringPadded(line2, SCS_LCD_MAX_COLUMNS);
813
        SCS_LCD_PrintStringPadded(line2, SCS_LCD_MAX_COLUMNS);
809
    }
814
      }
810
      }
815
    }
811
816
812
      if( printCommonPage ) {
817
    if( printCommonPage ) {
-
 
818
      void (*itemsLineFunct)(u8 editMode, char *line) = NULL;
-
 
819
      void (*valuesLineFunct)(u8 editMode, char *line) = NULL;
-
 
820
     
-
 
821
      if( rootTableSelectedPage < rootTableNumItems ) {
-
 
822
        itemsLineFunct = rootTable[rootTableSelectedPage].itemsLineFunct;
-
 
823
        valuesLineFunct = rootTable[rootTableSelectedPage].valuesLineFunct;
-
 
824
      }
-
 
825
-
 
826
      u8 editMode = scsMenuState == MENU_STATE_EDIT_ITEM;
-
 
827
-
 
828
      // first line
-
 
829
      {
813
    SCS_LCD_CursorSet(0, 0);
830
        SCS_LCD_CursorSet(0, 0);
814
    for(i=0; i<SCS_NUM_MENU_ITEMS; ++i) {
831
        char line1[SCS_MAX_STR];
815
      u8 item = displayPageOffset + i;
832
        strcpy(line1, "???");
816
      if( item >= numItems ||
833
        if( itemsLineFunct )
817
          (scsMenuState == MENU_STATE_EDIT_ITEM && item == rootTableSelectedItem && !displayLabelOn ) )
-
 
818
        SCS_LCD_PrintSpaces(SCS_MENU_ITEM_WIDTH);
834
          itemsLineFunct(editMode, line1);
819
      else {
835
        if( line1[0] != 0 )
820
        SCS_LCD_PrintStringPadded(pageItems[item].name, SCS_MENU_ITEM_WIDTH);
836
          SCS_LCD_PrintStringPadded(line1, SCS_LCD_MAX_COLUMNS);
821
      }
-
 
822
    }
837
      }
823
838
-
 
839
      // second line
-
 
840
      {
824
    SCS_LCD_CursorSet(0, 1);
841
        SCS_LCD_CursorSet(0, 1);
825
    for(i=0; i<SCS_NUM_MENU_ITEMS; ++i) {
-
 
826
      u8 item = displayPageOffset + i;
-
 
827
      if( item >= numItems ||
-
 
828
          (scsMenuState == MENU_STATE_EDIT_ITEM && item == rootTableSelectedItem && !displayCursorOn ) )
-
 
829
        SCS_LCD_PrintSpaces(SCS_MENU_ITEM_WIDTH);
-
 
830
      else {
-
 
831
        scs_menu_item_t *pageItem = (scs_menu_item_t *)&pageItems[item];
-
 
832
        char label[SCS_MAX_STR];
842
        char line2[SCS_MAX_STR];
833
        strcpy(label, "??? "); // default
843
        strcpy(line2, "???");
834
        u16 value = pageItem->getFunct(pageItem->ix);
844
        if( valuesLineFunct )
835
        pageItem->stringFunct(pageItem->ix, value, label);
845
          valuesLineFunct(editMode, line2);
-
 
846
        if( line2[0] != 0 )
836
        SCS_LCD_PrintStringPadded(label, SCS_MENU_ITEM_WIDTH);
847
          SCS_LCD_PrintStringPadded(line2, SCS_LCD_MAX_COLUMNS);
837
      }
-
 
838
    }
848
      }
839
849
840
    // print arrow at upper right corner
850
      // print arrow at upper right corner
841
    if( numItems > SCS_NUM_MENU_ITEMS ) {
851
      if( numItems > SCS_NUM_MENU_ITEMS ) {
842
      SCS_LCD_CursorSet(SCS_LCD_MAX_COLUMNS-1, 0);
852
        SCS_LCD_CursorSet(SCS_LCD_MAX_COLUMNS-1, 0);
Line 844... Line 854...
844
        SCS_LCD_PrintChar(1); // right arrow
854
          SCS_LCD_PrintChar(1); // right arrow
845
      else if( displayPageOffset >= (numItems-SCS_NUM_MENU_ITEMS) )
855
        else if( displayPageOffset >= (numItems-SCS_NUM_MENU_ITEMS) )
846
        SCS_LCD_PrintChar(0); // left arrow
856
          SCS_LCD_PrintChar(0); // left arrow
847
      else
857
        else
848
        SCS_LCD_PrintChar(2); // left/right arrow
858
          SCS_LCD_PrintChar(2); // left/right arrow
-
 
859
      }
849
    }
860
    }
850
      }
861
      }
851
    } break;
862
    } break;
852
863
853
    /////////////////////////////////////////////////////////////////////////
864
    /////////////////////////////////////////////////////////////////////////
Line 1011... Line 1022...
1011
1022
1012
  // transfer display changes to LCD if necessary (no force)
1023
  // transfer display changes to LCD if necessary (no force)
1013
  SCS_LCD_Update(0);
1024
  SCS_LCD_Update(0);
1014
1025
1015
  return 0; // no error
1026
  return 0; // no error
-
 
1027
}
-
 
1028
-
 
1029
-
 
1030
/////////////////////////////////////////////////////////////////////////////
-
 
1031
//! Standard function to print the items of a page
-
 
1032
//! \param[in] editMode 0 if page is in scroll mode, 1 if value is edited
-
 
1033
//! \param[out] line copy the line into this string
-
 
1034
/////////////////////////////////////////////////////////////////////////////
-
 
1035
void SCS_StringStandardItems(u8 editMode, char *line)
-
 
1036
{
-
 
1037
  scs_menu_item_t *pageItems = (scs_menu_item_t *)rootTable[rootTableSelectedPage].page;
-
 
1038
  u8 numItems = rootTable[rootTableSelectedPage].numItems;
-
 
1039
-
 
1040
  // TK: the user would put the string into *line
-
 
1041
  // but internally we can also use SCS_LCD_* to simplify the output if line[0] set to 0
-
 
1042
  line[0] = 0;
-
 
1043
-
 
1044
  // (shouldn't be used externally to allow a proper implementation later)
-
 
1045
  int i;
-
 
1046
  for(i=0; i<SCS_NUM_MENU_ITEMS; ++i) {
-
 
1047
    u8 item = displayPageOffset + i;
-
 
1048
    if( item >= numItems ||
-
 
1049
    (editMode && item == rootTableSelectedItem && !displayLabelOn ) )
-
 
1050
      SCS_LCD_PrintSpaces(SCS_MENU_ITEM_WIDTH);
-
 
1051
    else {
-
 
1052
      SCS_LCD_PrintStringPadded(pageItems[item].name, SCS_MENU_ITEM_WIDTH);
-
 
1053
    }
-
 
1054
  }
-
 
1055
}
-
 
1056
-
 
1057
/////////////////////////////////////////////////////////////////////////////
-
 
1058
//! Standard function to print the values of a page
-
 
1059
//! \param[in] editMode 0 if page is in scroll mode, 1 if value is edited
-
 
1060
//! \param[out] line copy the line into this string
-
 
1061
/////////////////////////////////////////////////////////////////////////////
-
 
1062
void SCS_StringStandardValues(u8 editMode, char *line)
-
 
1063
{
-
 
1064
  scs_menu_item_t *pageItems = (scs_menu_item_t *)rootTable[rootTableSelectedPage].page;
-
 
1065
  u8 numItems = rootTable[rootTableSelectedPage].numItems;
-
 
1066
-
 
1067
  // TK: the user would put the string into *line
-
 
1068
  // but internally we can also use SCS_LCD_* to simplify the output if line[0] set to 0
-
 
1069
  line[0] = 0;
-
 
1070
-
 
1071
  // (shouldn't be used externally to allow a proper implementation later)
-
 
1072
  int i;
-
 
1073
  for(i=0; i<SCS_NUM_MENU_ITEMS; ++i) {
-
 
1074
    u8 item = displayPageOffset + i;
-
 
1075
    if( item >= numItems ||
-
 
1076
    (editMode && item == rootTableSelectedItem && !displayCursorOn ) )
-
 
1077
      SCS_LCD_PrintSpaces(SCS_MENU_ITEM_WIDTH);
-
 
1078
    else {
-
 
1079
      scs_menu_item_t *pageItem = (scs_menu_item_t *)&pageItems[item];
-
 
1080
      char label[SCS_MAX_STR];
-
 
1081
      strcpy(label, "??? "); // default
-
 
1082
      u16 value = pageItem->getFunct(pageItem->ix);
-
 
1083
      pageItem->stringFunct(pageItem->ix, value, label);
-
 
1084
      SCS_LCD_PrintStringPadded(label, SCS_MENU_ITEM_WIDTH);
-
 
1085
    }
-
 
1086
  }
1016
}
1087
}
1017
1088
1018
1089
1019
/////////////////////////////////////////////////////////////////////////////
1090
/////////////////////////////////////////////////////////////////////////////
1020
//! Installs a root table
1091
//! Installs a root table
Line 1178... Line 1249...
1178
  memcpy(scsActionString, actionString, SCS_MENU_ITEM_WIDTH);
1249
  memcpy(scsActionString, actionString, SCS_MENU_ITEM_WIDTH);
1179
  scsActionString[SCS_MENU_ITEM_WIDTH] = 0; // ditto.
1250
  scsActionString[SCS_MENU_ITEM_WIDTH] = 0; // ditto.
1180
  scsEditStringMaxChars = maxChars;
1251
  scsEditStringMaxChars = maxChars;
1181
1252
1182
  // set edit pos after last char in string
1253
  // set edit pos after last char in string
-
 
1254
  // search forward for null terminator
-
 
1255
  for(scsEditPos=0; scsEditPos<(maxChars-1); ++scsEditPos)
-
 
1256
    if( scsEditString[scsEditPos] == 0 )
-
 
1257
      break;
-
 
1258
  if( scsEditPos ) {
-
 
1259
    // search backward for last character
1183
  for(scsEditPos=maxChars-1; scsEditPos>0; --scsEditPos)
1260
    for(--scsEditPos; scsEditPos>0; --scsEditPos)
1184
    if( scsEditString[scsEditPos] != ' ' ) {
1261
      if( scsEditString[scsEditPos] != ' ' ) {
1185
      if( scsEditPos < maxChars )
1262
    if( scsEditPos < maxChars )
1186
    ++scsEditPos;
1263
      ++scsEditPos;
1187
      break;
1264
    break;
-
 
1265
      }
1188
    }
1266
  }
1189
1267
1190
  scsEditStringCallback = callback;
1268
  scsEditStringCallback = callback;
1191
  scsMenuState = MENU_STATE_EDIT_STRING;
1269
  scsMenuState = MENU_STATE_EDIT_STRING;
1192
1270