コード例 #1
0
void viewTransaction(Transaction* tx) {
  textArea text;
  if(tx->credit) {
    text.title = (char*)"Credit information";
  } else {
    text.title = (char*)"Debit information";
  }
  text.allowLeft = 1;
  
  textElement elem[15];
  text.elements = elem;
  text.numelements = 0; //we will use this as element cursor
  
  elem[text.numelements].text = (char*)"Description:";
  elem[text.numelements].color=COLOR_LIGHTGRAY;
  elem[text.numelements].spaceAtEnd=1;
  text.numelements++;
  
  elem[text.numelements].text = tx->description;
  text.numelements++;
    
  elem[text.numelements].text = (char*)"Date & time:";
  elem[text.numelements].newLine = 1;
  elem[text.numelements].spaceAtEnd=1;
  elem[text.numelements].color=COLOR_LIGHTGRAY; 
  text.numelements++;
  
  char date[50];
  dateToString(date, tx->date.year, tx->date.month, tx->date.day);
  strcat(date, (char*)" ");
  // timeToString concatenates
  timeToString(date, tx->time.hour, tx->time.minute, tx->time.second);
  
  elem[text.numelements].text = date;
  text.numelements++;
  
  char amount[20];
  currencyToString(amount, &tx->amount);

  elem[text.numelements].text = (char*)"Amount:";
  elem[text.numelements].newLine = 1;
  elem[text.numelements].spaceAtEnd=1;
  elem[text.numelements].color=COLOR_LIGHTGRAY;
  text.numelements++;
  
  elem[text.numelements].text = amount;
  text.numelements++;

  doTextArea(&text);
}
コード例 #2
0
ファイル: main.cpp プロジェクト: ComputerNerd/eigenmath
void select_strip_script() {
  if(!is_running_in_strip()) {
    printf("This function is only available\n");
    printf("when running as an eActivity\n");
    printf("strip.\n");
    return;
  }
  
  textArea text;

  textElement elem[10];
  text.elements = elem;
  
  elem[0].text = (char*)"This function lets you run a script when this eActivity strip is opened.";
  elem[1].newLine = 1;
  elem[1].text = (char*)"When sharing the eActivity file, it will not be necessary to share any other files - the script is included in the eActivity.";
  elem[2].newLine = 1;
  elem[2].text = (char*)"You will be informed if the script is too big to fit inside the eActivity file.";
  elem[3].newLine = 1;
  elem[3].text = (char*)"Press EXIT now to continue and select a script.";
  text.numelements = 4;
  doTextArea(&text);
  
  char filename[MAX_FILENAME_SIZE+1] = "";
  if(fileBrowser(filename, (unsigned char*)"*.txt", "Scripts")) {
    // get the size of the selected script on SMEM.
    // get free size on the "MCS" of the strip we're running on and see if the script fits
    unsigned short pFile[MAX_FILENAME_SIZE+1];
    Bfile_StrToName_ncpy(pFile, (unsigned char*)filename, strlen(filename)+1); 
    int hFile = Bfile_OpenFile_OS(pFile, READWRITE, 0); // Get handle
    if(hFile >= 0) // Check if it opened
    { //opened
      unsigned int filesize = Bfile_GetFileSize_OS(hFile);  
      //get free size of MCS
      int MCSmaxspace; int MCScurrentload; int MCSfreespace;  
      MCS_GetState( &MCSmaxspace, &MCScurrentload, &MCSfreespace );
      if((int)filesize < MCSfreespace - 50) { // 50 bytes for any headers and the like
        // fits, copy selected script to MCS
        unsigned char* scontents = (unsigned char*)alloca(filesize);
        memset(scontents, filesize, 0);
        int rsize = Bfile_ReadFile_OS(hFile, scontents, filesize, 0);
        scontents[rsize]='\0';
        // script is now in buffer scontents
        // write it to the "MCS"
        int createResult = MCS_CreateDirectory( DIRNAME );
        if(createResult != 0) // Check directory existence
        { // directory already exists, so delete the exiting file that may be there
          MCSDelVar2(DIRNAME, SCRIPTFILE);
        }
        MCSPutVar2(DIRNAME, SCRIPTFILE, rsize, scontents);
        printf("Script set successfully.\n");
      } else {
        printf("The script is too big to be\n");
        printf("included in the eActivity.\n");
      }
      Bfile_CloseFile_OS(hFile);
      return; // don't get to the error message
    }
  }
  printf("There was a problem setting the script for this strip.\n");
}
コード例 #3
0
void passwordGenerator() {
  Menu menu;
  menu.type = MENUTYPE_FKEYS;
  menu.title = (char*)"Password Generator";
  menu.height = 7;
  MenuItem items[6];
  int length = 10;
  int seed = RTC_GetTicks() * (GetMainBatteryVoltage(1) % 100);
  char lstr[10];
  items[1].text = (char*)"Include symbols";
  items[1].type = MENUITEM_CHECKBOX;
  items[2].text = (char*)"Include numbers";
  items[2].type = MENUITEM_CHECKBOX;
  items[2].value = MENUITEM_VALUE_CHECKED;
  items[3].text = (char*)"Include uppercase";
  items[3].type = MENUITEM_CHECKBOX;
  items[3].value = MENUITEM_VALUE_CHECKED;
  items[4].text = (char*)"Include confusable";
  items[4].type = MENUITEM_CHECKBOX;
  items[4].value = MENUITEM_VALUE_CHECKED;
  items[5].text = (char*)"Memorable vowel mix";
  items[5].type = MENUITEM_CHECKBOX;
  menu.numitems = 6;
  menu.items = items;
  while(1) {
    drawFkeyLabels(0x03B3, 0, 0, 0, 0, 0x0184); // FILE, EXE (white)
    itoa(length, (unsigned char*)lstr);
    char t[20];
    strcpy(t, "Length: ");
    strcat(t, lstr);
    items[0].text = t;
    switch(doMenu(&menu)) {
      case MENU_RETURN_EXIT:
        return;
      case MENU_RETURN_SELECTION:
        if(menu.selection > 1) items[menu.selection-1].value = !items[menu.selection-1].value;
        else {
          Selector sel;
          sel.min = 6;
          sel.value = length;
          sel.max = 30;
          sel.cycle = 1;
          sel.title = (char*)"Password Generator";
          sel.subtitle = (char*)"Length";
          if(doSelector(&sel) == SELECTOR_RETURN_SELECTION) {
            length = sel.value;
          }
        }
        break;
      case KEY_CTRL_F1:
      {
        Selector sel;
        sel.min = 1;
        sel.value = 10;
        sel.max = 1000;
        sel.cycle = 1;
        sel.title = (char*)"Generate to file";
        sel.subtitle = (char*)"Number of passwords";
        if(doSelector(&sel) != SELECTOR_RETURN_SELECTION) break;

        SetBackGround(10);
        drawScreenTitle("Generate to file", "Filename:");
        char newname[MAX_NAME_SIZE];
        newname[0] = 0;
        textInput input;
        input.forcetext=1;
        input.symbols = 0;
        input.charlimit=MAX_NAME_SIZE;
        input.buffer = (char*)newname;
        int inscreen = 1;
        while(inscreen) {
          input.key=0;
          int res = doTextInput(&input);
          if (res==INPUT_RETURN_EXIT) break; // user aborted
          else if (res==INPUT_RETURN_CONFIRM) {
            inscreen = 0;
          }
        }
        if(inscreen) break;
        char newfilename[MAX_FILENAME_SIZE];
        strcpy(newfilename, SMEM_PREFIX);
        strcat(newfilename, newname);
        strcat(newfilename, ".txt");
        unsigned short pFile[0x10A];
        Bfile_StrToName_ncpy(pFile, newfilename, 0x10A);
        unsigned int size = 1;
        int ntry = 0;
        while(ntry < 2) {
          ntry++;
          int BCEres = Bfile_CreateEntry_OS(pFile, CREATEMODE_FILE, &size);
          if(BCEres >= 0) {
            int hFile = Bfile_OpenFile_OS(pFile, READWRITE, 0); // Get handle
            if(hFile >= 0) {
              char password[35];
              char line[37];
              for(int i = 0; i < sel.value; i++) {
                generateRandomString(password, length, items[1].value, items[2].value,
                                     items[3].value, items[4].value, items[5].value, &seed);
                sprintf(line, "%s\r\n", password);
                Bfile_WriteFile_OS(hFile, line, length+2);
              }
              Bfile_CloseFile_OS(hFile);
            } else AUX_DisplayErrorMessage(0x2B);
            break;
          } else if(ntry < 2) {
            // File creation probably failed due to the presence of a file with the same name
            if(overwriteFilePrompt(newfilename))
              Bfile_DeleteEntry(pFile);
            else
              break;
          } else AUX_DisplayErrorMessage(0x2B);
        }
        break;
      }
      case KEY_CTRL_F6:
        int inscreen = 1;
        while(inscreen) {
          Bdisp_AllClr_VRAM();
          drawScreenTitle("Password Generator", "Generated passwords:");
          textArea text;
          text.type = TEXTAREATYPE_INSTANT_RETURN;
          text.scrollbar = 0;
          text.y = 48+3;
          text.lineHeight = 20;
          textElement e[5];
          char passwords[5][35];
          for(int i = 0; i < 5; i++) {
            generateRandomString(passwords[i], length, items[1].value, items[2].value,
                                 items[3].value, items[4].value, items[5].value, &seed);
            e[i].text = passwords[i];
            if(i) e[i].newLine = 1;
          }
          text.elements = e;
          text.numelements = 5;
          doTextArea(&text);
          drawFkeyLabels(0x036F, 0, 0, 0, 0, 0x02B9); // <, REPEAT (white)
          while(1) {
            int key;
            mGetKey(&key);
            if(key == KEY_CTRL_F6) break;
            if(key == KEY_CTRL_F1 || key == KEY_CTRL_EXIT) {
              inscreen = 0;
              break;
            }
          }
        }
        break;
    }
  }
}