int CCAMMenuHandler::exec(CMenuTarget* parent, const std::string &actionkey)
{
	std::string::size_type loc;
	int slot;

	printf("CCAMMenuHandler::exec: actionkey %s\n", actionkey.c_str());
        if (parent)
                parent->hide();

	if ((loc = actionkey.find("ca_ci_reset", 0)) != std::string::npos) {
		slot = actionkey.at(11) - '0';

		if(ca && ca->ModulePresent(CA_SLOT_TYPE_CI, slot))
			ca->ModuleReset(CA_SLOT_TYPE_CI, slot);
	} else if ((loc = actionkey.find("ca_ci", 0)) != std::string::npos) {
		slot = actionkey.at(5) - '0';
		printf("CCAMMenuHandler::exec: actionkey %s for slot %d\n", actionkey.c_str(), slot);
		return doMenu(slot, CA_SLOT_TYPE_CI);
	} else if ((loc = actionkey.find("ca_sc_reset", 0)) != std::string::npos) {
		slot = actionkey.at(11) - '0';

		if(ca && ca->ModulePresent(CA_SLOT_TYPE_SMARTCARD, slot))
			ca->ModuleReset(CA_SLOT_TYPE_SMARTCARD, slot);
	} else if ((loc = actionkey.find("ca_sc", 0)) != std::string::npos) {
		slot = actionkey.at(5) - '0';
		printf("CCAMMenuHandler::exec: actionkey %s for slot %d\n", actionkey.c_str(), slot);
		return doMenu(slot, CA_SLOT_TYPE_SMARTCARD);
	}

	if(!parent)
		return 0;

	return doMainMenu();
}
Ejemplo n.º 2
0
int CCAMMenuHandler::exec(CMenuTarget* parent, const std::string &actionkey)
{
printf("CCAMMenuHandler::exec: actionkey %s\n", actionkey.c_str());
        if (parent)
                parent->hide();

	if(actionkey == "cam1") {
		return doMenu(0);
	} else if(actionkey == "cam2") {
		return doMenu(1);
	}

	return doMainMenu ();
}
Ejemplo n.º 3
0
int CHDDMenuHandler::exec(CMenuTarget* parent, const std::string &actionkey)
{
	if (parent)
		parent->hide();

	return doMenu ();
}
Ejemplo n.º 4
0
int CAudioSelectMenuHandler::exec(CMenuTarget* parent, const std::string &actionkey)
{
	int sel= atoi(actionkey.c_str());
	if(sel >= 0) {
#ifdef EVOLUX
		if (g_RemoteControl->current_PIDs.PIDs.selected_apid != (unsigned int) sel )
		{
			g_Zapit->setVolumePercent((unsigned int) g_settings.current_volume_percent);
			g_RemoteControl->setAPID(sel);
			g_Zapit->getVolumePercent((unsigned int *) &g_settings.current_volume_percent);
			audioDecoder->setPercent(g_settings.current_volume_percent);
		}
#else
		if (g_RemoteControl->current_PIDs.PIDs.selected_apid!= (unsigned int) sel )
		{
			g_RemoteControl->setAPID(sel);
		}
#endif
		return menu_return::RETURN_EXIT;
	}

	if (parent) 
		parent->hide();

	return doMenu ();
}
Ejemplo n.º 5
0
// 0 on exit, 1 on success
int doCatalogMenu(char* insertText, char* title, int category) {
  MenuItem* menuitems = (MenuItem*)alloca(sizeof(MenuItem)*CAT_COMPLETE_COUNT);
  int cur = 0; int curmi = 0;
  while(cur<CAT_COMPLETE_COUNT) {
    if(completeCat[cur].category == category || category == CAT_CATEGORY_ALL) {
      menuitems[curmi].type = MENUITEM_NORMAL;
      menuitems[curmi].color = TEXT_COLOR_BLACK;
      menuitems[curmi].isfolder = cur; // little hack: store index of the command in the full list in the isfolder property (unused by the menu system in this case)
      menuitems[curmi].text = completeCat[cur].name;
      curmi++;
    }
    cur++;
  }
  
  Menu menu;
  menu.items=menuitems;
  menu.numitems=curmi;
  menu.scrollbar=1;
  menu.scrollout=1;
  menu.selection=1;
  menu.scroll=0;
  menu.title = title;
  int sres = doMenu(&menu);
  if(sres == MENU_RETURN_SELECTION) {
    strcpy(insertText, completeCat[menuitems[menu.selection-1].isfolder].insert);
    return 1;
  }
  return 0;
}
Ejemplo n.º 6
0
void totpClient() {
  RTCunadjustedWizard(1);
  if(isRTCunadjusted()) {
    mMsgBoxPush(6);
    multiPrintXY(3, 2, "The OATH TOTP\nauthenticator\ncan't work with\nthe clock\nunadjusted.",
                 TEXT_MODE_TRANSPARENT_BACKGROUND, TEXT_COLOR_BLACK);
    closeMsgBox(0, 7);
    return;
  }
  totp ts[MAX_DAY_EVENTS];
  Menu menu;
  menu.type = MENUTYPE_FKEYS;
  MenuItem items[MAX_DAY_EVENTS];
  menu.items = items;
  reload:
  menu.numitems = loadTOTPs(ts);
  for(int i = 0; i < menu.numitems; i++) {
    items[i].text = ts[i].name;
  }
  menu.title = (char*)"TOTP authenticator";
  menu.scrollout = 1;
  menu.height = 7;
  menu.nodatamsg = (char*)"No tokens - press F2";
  menu.returnOnRight = 1;
  while(1) {
    drawFkeyLabels(0, 0x0186, 0, 0, 0, 0x012A); // NEW, TIME
    if(menu.numitems) {
      drawFkeyLabels(0x0235, -1, 0x0188, 0x0038); // FACTOR, RENAME, DELETE
    }
    int res = doMenu(&menu);
    switch(res) {
      case MENU_RETURN_EXIT:
        return;
      case KEY_CTRL_F1:
        if(!menu.numitems) break;
      case MENU_RETURN_SELECTION:
        viewTOTPcode(&ts[menu.selection-1]);
        break;
      case KEY_CTRL_F2:
        if(menu.numitems >= MAX_DAY_EVENTS) {
          AUX_DisplayErrorMessage(0x2E);
        } else {
          if(addTOTPwizard()) goto reload;
        }
        break;
      case KEY_CTRL_F3:
        if(menu.numitems && renameTOTPscreen(menu.selection-1, ts[menu.selection-1].name))
          goto reload;
        break;
      case KEY_CTRL_F4:
      case KEY_CTRL_DEL:
        if(menu.numitems && deleteTOTPprompt(menu.selection-1)) goto reload;
        break;
      case KEY_CTRL_F6:
        setTimezone();
        break;
    }
  }
}
Ejemplo n.º 7
0
void masterControl() {
    MenuItem menuitems[10];
    menuitems[0].text = (char*)"SS";
    menuitems[1].text = (char*)"LS";
    menuitems[2].text = (char*)"Lk0";
    menuitems[3].text = (char*)"Lk1";
#ifdef ENABLE_DEBUG
    menuitems[4].text = (char*)"Dbg0";
    menuitems[5].text = (char*)"Dbg1";
    menuitems[6].text = (char*)"Ac0";
    menuitems[7].text = (char*)"Ac1";
    menuitems[8].text = (char*)"Rst";
#endif

    Menu menu;
    menu.items=menuitems;
#ifdef ENABLE_DEBUG
    menu.numitems=9;
#else
    menu.numitems=4;
#endif
    menu.scrollout=1;
#ifdef ENABLE_DEBUG
    menu.title = (char*)"CTRL";
#endif
    while(1) {
        int res = doMenu(&menu);
        if(res == MENU_RETURN_EXIT) return;
        else if(res == MENU_RETURN_SELECTION) {
            switch(menu.selection) {
            case 1:
                saveSettings();
                break;
            case 2:
                loadSettings();
                break;
            case 3:
            case 4:
                // do not autosave, to allow full control of the operator
                setSetting(SETTING_ENABLE_LOCK, menu.selection-3, 0);
                break;
#ifdef ENABLE_DEBUG
            case 5:
            case 6:
                setDebugMode(menu.selection-5);
                break;
            case 7:
            case 8:
                // do not autosave, to allow full control of the operator
                setSetting(SETTING_ACTIVATION_STATUS, menu.selection-7, 0);
                break;
            case 9:
                Restart();
                break;
#endif
            }
        }
    }
}
Ejemplo n.º 8
0
int CAudioSelectMenuHandler::exec(CMenuTarget * parent, const std::string &/*actionKey*/)
{
	int res = menu_return::RETURN_REPAINT;

	if (parent) 
		parent->hide();

	doMenu();

	return res;
}
Ejemplo n.º 9
0
int CAudioSelectMenuHandler::exec(CMenuTarget* parent, const std::string &actionkey)
{
	int sel = -1;
	if (AudioSelector) {
		sel = AudioSelector->getSelected();
		sel -= apid_offset;
		if (sel < 0 || sel >= p_count)
			return menu_return::RETURN_NONE;
	}

	if (actionkey == "-" || actionkey == "+") {
		if (actionkey == "-") {
			if (perc_val[sel] == 0)
				return menu_return::RETURN_NONE;
			perc_val[sel]--;
		} else {
			if (perc_val[sel] == 999)
				return menu_return::RETURN_NONE;
			perc_val[sel]++;
		}
		perc_str[sel] = to_string(perc_val[sel]) + "%";

#if !HAVE_SPARK_HARDWARE && !HAVE_DUCKBOX_HARDWARE
		int vol =  CZapit::getInstance()->GetVolume();
		/* keep resulting volume = (vol * percent)/100 not more than 115 */
		if (vol * perc_val[sel] > 11500)
			perc_val[sel] = 11500 / vol;
#endif
		CZapit::getInstance()->SetPidVolume(chan, apid[sel], perc_val[sel]);
		if (sel == sel_apid)
			CZapit::getInstance()->SetVolumePercent(perc_val[sel]);

		return menu_return::RETURN_REPAINT;
	}

	if (actionkey == "s") {
		if (mp->Playing()) {
			mp->setAPID(sel);
		} else if (g_RemoteControl->current_PIDs.PIDs.selected_apid != (unsigned int) sel ) {
			g_RemoteControl->setAPID(sel);
		}
		return menu_return::RETURN_EXIT;
	}
	if (actionkey == "x")
		return menu_return::RETURN_EXIT;

	if (mp->Playing())
		playback = mp->getPlayback();
	if (parent)
		parent->hide();

	return doMenu ();
}
Ejemplo n.º 10
0
int CEPGMenuHandler::exec(CMenuTarget* parent, const std::string &)
{
    int           res = menu_return::RETURN_EXIT_ALL;


    if (parent) {
        parent->hide();
    }

    doMenu ();
    return res;
}
Ejemplo n.º 11
0
int CAudioSelectMenuHandler::exec(CMenuTarget* parent, const std::string &actionkey)
{
	int           res = menu_return::RETURN_EXIT_ALL;


	if (parent) {
		parent->hide();
	}

	doMenu ();
	return res;
}
int CAudioSelectMenuHandler::exec(CMenuTarget* parent, const std::string &actionkey)
{
	int sel= atoi(actionkey.c_str());
	if(sel >= 0) {
		if (g_RemoteControl->current_PIDs.PIDs.selected_apid!= (unsigned int) sel )
		{
			g_RemoteControl->setAPID(sel);
		}
		return menu_return::RETURN_EXIT;
	}

	if (parent)
		parent->hide();

	return doMenu ();
}
Ejemplo n.º 13
0
int CSubChannelSelectMenu::exec(CMenuTarget* parent, const std::string &actionKey)
{
    int res = menu_return::RETURN_EXIT_ALL;

    if (parent)
        parent->hide();

    if (actionKey != "-1")
    {
        unsigned sel = atoi(actionKey.c_str());
        g_RemoteControl->setSubChannel(sel);
        g_InfoViewer->showSubchan();
        return res;
    }

    res = doMenu();
    return res;
}
Ejemplo n.º 14
0
static void _hLoadModelLayout()
{
	if (KEYINIT)
		mnuMLayout.marked = Config.MixerIndex;

	if (elementIndex == 0)
	{
		if (doMenu(&mnuMLayout))
		{
			lcdClear();
			lcdSetPos(3, 18);
			lcdWriteString_P(strAreYouSure);
			writeSoftkeys(_skCANCELYES);
			elementIndex = 1;
		}
	}		
	else if (KEY4)		// YES
	{
		mixerLoadModel(mnuMLayout.marked);
		//configSave();
		loadPage(PAGE_SHOW_LAYOUT);
	}
}
Ejemplo n.º 15
0
int main( int argc, char *argv[] )
{
	time_t startTime, stopTime;
	clock_t startCPU, stopCPU;
	double elapsedCPUsecs;
	int capacity = INITIAL_CAPACITY;
	int count =0;
	char **dictionary = malloc( capacity * sizeof(char *) );
	if (dictionary == NULL )
	{
		printf("Initial malloc of dictionary failed. Program exiting\n");
		return EXIT_FAILURE; /* EXIT_FAILURE defined as non zero in stdlib.h */
	}

	if (argc < 3 )
	{
		printf("usage: ./%s <infileName> <outFilename>\n",argv[0]); /* you gotta put in & out file names on cmd line! */
		return EXIT_FAILURE;
	}

	startTime = time( NULL );
	printf("\nStarting load of %s at %s", argv[1], ctime( &startTime) );
	printf("each '*' represents 10,000 words loaded into dictionary\n");
	startCPU = clock();
	loadDictionary( argv[1], &dictionary, &count, & capacity );
	stopCPU = clock();
	stopTime = time( NULL );
	printf("\nFinished load of %s at %s", argv[1], ctime( &stopTime) );
	printf("%d words loaded in %lu seconds\n", count, stopTime-startTime );
	elapsedCPUsecs = ((double)(stopCPU-startCPU)) / CLOCKS_PER_SEC;
	printf("Elapsed CPU seconds: %f\n",  elapsedCPUsecs );
	doMenu( argv[2], &dictionary, &count, &capacity );
	freeAllMemory( dictionary, count );

	return EXIT_SUCCESS; /* EXIT_SUCCESS defined as 0 in stdlib.h */
}
Ejemplo n.º 16
0
int fileBrowserSub(char* browserbasepath, char* filename, char* filter, char* filter2, char* title) {
  Menu menu;
  MenuItemIcon icontable[12];
  buildIconTable(icontable);
  
  // first get file count so we know how much to alloc
  GetFiles(NULL, NULL, browserbasepath, &menu.numitems, filter, filter2);
  MenuItem* menuitems = NULL;
  File* files = NULL;
  if(menu.numitems > 0) {
    menuitems = (MenuItem*)alloca(menu.numitems*sizeof(MenuItem));
    files = (File*)alloca(menu.numitems*sizeof(File));
    // populate arrays
    GetFiles(files, menuitems, browserbasepath, &menu.numitems, filter, filter2);
    menu.items = menuitems;
  }
  
  char titleBuffer[120];
  char titleBufferBuf[120];
  int smemfree;
  unsigned short smemMedia[10]={'\\','\\','f','l','s','0',0};
  Bfile_GetMediaFree_OS( smemMedia, &smemfree );
  
  char friendlypath[MAX_FILENAME_SIZE];
  strcpy(friendlypath, browserbasepath+6);
  friendlypath[strlen(friendlypath)-1] = '\0'; //remove ending slash like OS does
  // test to see if friendlypath is too big
  int jump4=0;
  while(1) {
    int temptextX=7*18+10; // px length of menu title + 10, like menuGUI goes.
    int temptextY=0;
    PrintMini(&temptextX, &temptextY, (char*)friendlypath, 0, 0xFFFFFFFF, 0, 0, COLOR_BLACK, COLOR_WHITE, 0, 0); // fake draw
    if(temptextX>LCD_WIDTH_PX-6) {
      char newfriendlypath[MAX_FILENAME_SIZE];
      shortenDisplayPath(friendlypath, newfriendlypath, (jump4 ? 4 : 1));
      if(strlen(friendlypath) > strlen(newfriendlypath) && strlen(newfriendlypath) > 3) { // check if len > 3 because shortenDisplayPath may return just "..." when the folder name is too big
        // shortenDisplayPath still managed to shorten, copy and continue
        jump4 = 1; //it has been shortened already, so next time jump the first four characters
        strcpy(friendlypath, newfriendlypath);
      } else {
        // shortenDisplayPath can't shorten any more even if it still
        // doesn't fit in the screen, so give up.
        break;
      }
    } else break;
  }
  menu.subtitle = friendlypath;
  menu.type = MENUTYPE_MULTISELECT;
  menu.scrollout=1;
  menu.nodatamsg = (char*)"No Data";
  menu.title = title;
  menu.height=7;
  while(1) {
    Bdisp_AllClr_VRAM();
    drawFkeyLabels((menu.numitems ? 0x03B1 : 0), -1, -1, -1, -1, 0x03DF); // OPEN, VERSION
    itoa(smemfree, (unsigned char*)titleBuffer);
    LocalizeMessage1( 340, titleBufferBuf ); //"bytes free"
    strncat((char*)titleBuffer, (char*)titleBufferBuf, 65);
    menu.statusText = (char*)titleBuffer;
    int res = doMenu(&menu, icontable);
    switch(res) {
      case MENU_RETURN_EXIT:
        if(!strcmp(browserbasepath,"\\\\fls0\\")) { //check that we aren't already in the root folder
          //we are, return 0 so we exit
          //return 0; // in this add-in, the file browser shouldn't return
        } else {
          int i=strlen(browserbasepath)-2;
          while (i>=0 && browserbasepath[i] != '\\')
                  i--;
          if (browserbasepath[i] == '\\') {
            char tmp[MAX_FILENAME_SIZE] = "";
            memcpy(tmp,browserbasepath,i+1);
            tmp[i+1] = '\0';
            strcpy(browserbasepath, tmp);
          }
          return 1; //reload at new folder
        }
        break;
      case KEY_CTRL_F1:
      case MENU_RETURN_SELECTION:
        if(!menu.numitems) break;
        if(menuitems[menu.selection-1].isfolder) {
          strcpy(browserbasepath, files[menu.selection-1].filename); //switch to selected folder
          strcat(browserbasepath, "\\");
          return 1; //reload at new folder
        } else {
          strcpy(filename,files[menu.selection-1].filename);
          return 2;
        }
        break;
      case KEY_CTRL_F6:
        showAbout();
        break;
    }
  }
  return 1;
}
Ejemplo n.º 17
0
int main( void )
{
	long	result = 0;
	
	// initialize for carbon & QuickTime
	InitCursor();
	if ( IsQuickTimeInstalled() )
		EnterMovies();
	else
		goto bail;
		
	GetQDGlobalsScreenBits( &screenBits );
	
	Gestalt(gestaltMenuMgrAttr, &result);
	if (result & gestaltMenuMgrAquaLayoutMask) {
		// Mmmmmm...X
		SetMenuBar(GetNewMBar(129));
		if (AEInstallEventHandler( kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(doAEQuit), 0, false))
			goto bail;
	} else {
		SetMenuBar(GetNewMBar(128));
	}
	DrawMenuBar();
	
	while (gDone == false) {
		EventRecord theEvent;
		WindowPtr pWhichWindow;		
		short windowPart;
        Boolean SIOUXHandledEvent = false;
		
		WaitNextEvent(everyEvent, &theEvent, 0, NULL);
		
        #ifndef __MACH__
            SIOUXHandledEvent = SIOUXHandleOneEvent(&theEvent);
        #endif
        
		if ( !SIOUXHandledEvent ) {
		
			switch (theEvent.what) {
				case updateEvt:
					pWhichWindow = (WindowPtr)theEvent.message;
					
					// we don't do anything for this simple sample
					BeginUpdate(pWhichWindow);
					EndUpdate(pWhichWindow);
					break;
				
				case keyDown:
					if (theEvent.modifiers & cmdKey) {
						doMenu(MenuKey(theEvent.message & charCodeMask));
					}
					break;
				
				case mouseDown:
					windowPart = FindWindow(theEvent.where, &pWhichWindow);

					switch (windowPart) {
						case inDrag:
							DragWindow(pWhichWindow, theEvent.where, &screenBits.bounds);
							break;

						case inGoAway:
							if (TrackGoAway(pWhichWindow, theEvent.where))
								DisposeWindow( pWhichWindow );
								//gDone = true;
							break;

						case inContent:
							SelectWindow(pWhichWindow);
							break;

						case inMenuBar:
							doMenu(MenuSelect(theEvent.where));
							break;
					}
					break;
			}
		}
	}
	
bail:

	return 0;	
}
/* bShowChannelList default to true, returns new bouquet or -1/-2 */
int CBouquetList::show(bool bShowChannelList)
{
	neutrino_msg_t      msg;
	neutrino_msg_data_t data;
	int res = CHANLIST_CANCEL;
	int icol_w, icol_h;
	int w_max_text = 0;
	int w_max_icon = 0;
	int h_max_icon = 0;
	favonly = !bShowChannelList;

	for(unsigned int count = 0; count < sizeof(CBouquetListButtons)/sizeof(CBouquetListButtons[0]);count++){
		int w_text = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getRenderWidth(g_Locale->getText(CBouquetListButtons[count].locale));
		w_max_text = std::max(w_max_text, w_text);
		frameBuffer->getIconSize(CBouquetListButtons[count].button, &icol_w, &icol_h);
		w_max_icon = std::max(w_max_icon, icol_w);
		h_max_icon = std::max(h_max_icon, icol_h);
	}

	int need_width =  sizeof(CBouquetListButtons)/sizeof(CBouquetListButtons[0])*(w_max_icon  + w_max_text + 20);
	CVFD::getInstance()->setMode(CVFD::MODE_MENU_UTF8, "");
	fheight     = g_Font[SNeutrinoSettings::FONT_TYPE_CHANNELLIST]->getHeight();

	width  = w_max (need_width, 20);
	height = h_max (16 * fheight, 40);

	footerHeight = std::max(h_max_icon+8, g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getHeight()+8);
	theight     = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getHeight();
	listmaxshow = (height - theight - footerHeight)/fheight;
	height      = theight + footerHeight + listmaxshow * fheight; // recalc height

	x = frameBuffer->getScreenX() + (frameBuffer->getScreenWidth() - width) / 2;
	y = frameBuffer->getScreenY() + (frameBuffer->getScreenHeight() - height) / 2;

	int lmaxpos= 1;
	int i= Bouquets.size();
	while ((i= i/10)!=0)
		lmaxpos++;

	COSDFader fader(g_settings.theme.menu_Content_alpha);
	fader.StartFadeIn();

	paintHead();
	paint();
	frameBuffer->blit();

	int oldselected = selected;
	int firstselected = selected+ 1;
	int zapOnExit = false;

	unsigned int chn= 0;
	int pos= lmaxpos;

	uint64_t timeoutEnd = CRCInput::calcTimeoutEnd(g_settings.timing[SNeutrinoSettings::TIMING_CHANLIST]);

	bool loop=true;
	while (loop) {
		g_RCInput->getMsgAbsoluteTimeout( &msg, &data, &timeoutEnd );

		if ( msg <= CRCInput::RC_MaxRC )
			timeoutEnd = CRCInput::calcTimeoutEnd(g_settings.timing[SNeutrinoSettings::TIMING_CHANLIST]);

		if((msg == NeutrinoMessages::EVT_TIMER) && (data == fader.GetFadeTimer())) {
			if(fader.FadeDone())
				loop = false;
		}
		else if ((msg == CRCInput::RC_timeout                             ) ||
				(msg == (neutrino_msg_t)g_settings.key_channelList_cancel) ||
				((msg == CRCInput::RC_favorites) && (CNeutrinoApp::getInstance()->GetChannelMode() == LIST_MODE_FAV)))
		{
			selected = oldselected;
			if(fader.StartFadeOut()) {
				timeoutEnd = CRCInput::calcTimeoutEnd( 1 );
				msg = 0;
			} else
				loop=false;
		}
		else if(msg == CRCInput::RC_red || msg == CRCInput::RC_favorites) {
			if (!favonly && CNeutrinoApp::getInstance()->GetChannelMode() != LIST_MODE_FAV) {
				CNeutrinoApp::getInstance()->SetChannelMode(LIST_MODE_FAV);
				hide();
				return CHANLIST_CHANGE_MODE;
			}
		} else if(msg == CRCInput::RC_green) {
			if (!favonly && CNeutrinoApp::getInstance()->GetChannelMode() != LIST_MODE_PROV) {
				CNeutrinoApp::getInstance()->SetChannelMode(LIST_MODE_PROV);
				hide();
				return CHANLIST_CHANGE_MODE;
			}
		} else if(msg == CRCInput::RC_yellow || msg == CRCInput::RC_sat) {
			if(!favonly && bShowChannelList && CNeutrinoApp::getInstance()->GetChannelMode() != LIST_MODE_SAT) {
				CNeutrinoApp::getInstance()->SetChannelMode(LIST_MODE_SAT);
				hide();
				return CHANLIST_CHANGE_MODE;
			}
		} else if(msg == CRCInput::RC_blue) {
			if(!favonly && bShowChannelList && CNeutrinoApp::getInstance()->GetChannelMode() != LIST_MODE_ALL) {
				CNeutrinoApp::getInstance()->SetChannelMode(LIST_MODE_ALL);
				hide();
				return CHANLIST_CHANGE_MODE;
			}
		}
		else if ( msg == CRCInput::RC_setup) {
			if (!favonly && !Bouquets.empty()) {
				int ret = doMenu();
				if(ret > 0) {
					res = CHANLIST_NO_RESTORE;
					loop = false;
				} else if(ret < 0) {
					paintHead();
					paint();
				}
			}
		}
		else if ( msg == (neutrino_msg_t) g_settings.key_list_start ) {
			if (!Bouquets.empty())
				updateSelection(0);
		}
		else if ( msg == (neutrino_msg_t) g_settings.key_list_end ) {
			if (!Bouquets.empty())
				updateSelection(Bouquets.size()-1);
		}
		else if (msg == CRCInput::RC_up || (int) msg == g_settings.key_pageup ||
			 msg == CRCInput::RC_down || (int) msg == g_settings.key_pagedown)
		{
			int new_selected = UpDownKey(Bouquets, msg, listmaxshow, selected);
			updateSelection(new_selected);
		}
		else if(msg == (neutrino_msg_t)g_settings.key_bouquet_up || msg == (neutrino_msg_t)g_settings.key_bouquet_down) {
			if(bShowChannelList) {
				int mode = CNeutrinoApp::getInstance()->GetChannelMode();
				mode += (msg == (neutrino_msg_t)g_settings.key_bouquet_down) ? -1 : 1;
				if(mode < 0)
					mode = LIST_MODE_LAST - 1;
				else if(mode >= LIST_MODE_LAST)
					mode = 0;
				CNeutrinoApp::getInstance()->SetChannelMode(mode);
				hide();
				return CHANLIST_CHANGE_MODE;
			}
		}
		else if ( msg == CRCInput::RC_ok ) {
			if(!Bouquets.empty() /* && (!bShowChannelList || !Bouquets[selected]->channelList->isEmpty())*/) {
				zapOnExit = true;
				loop=false;
			}
		}
		else if (CRCInput::isNumeric(msg)) {
			if (!Bouquets.empty()) {
				if (pos == lmaxpos) {
					if (msg == CRCInput::RC_0) {
						chn = firstselected;
						pos = lmaxpos;
					} else {
						chn = CRCInput::getNumericValue(msg);
						pos = 1;
					}
				} else {
					chn = chn * 10 + CRCInput::getNumericValue(msg);
					pos++;
				}

				if (chn > Bouquets.size()) {
					chn = firstselected;
					pos = lmaxpos;
				}

				int new_selected = (chn - 1) % Bouquets.size(); // is % necessary (i.e. can firstselected be > Bouquets.size()) ?
				updateSelection(new_selected);
			}
		} else if (msg == NeutrinoMessages::EVT_SERVICESCHANGED || msg == NeutrinoMessages::EVT_BOUQUETSCHANGED) {
			g_RCInput->postMsg(msg, data);
			loop = false;
			res = CHANLIST_CANCEL_ALL;
		} else if (msg > CRCInput::RC_MaxRC) {
			if ( CNeutrinoApp::getInstance()->handleMsg( msg, data ) & messages_return::cancel_all ) {
				loop = false;
				res = CHANLIST_CANCEL_ALL;
			}
		}
		frameBuffer->blit();
	}
	hide();

	fader.StopFade();

	CVFD::getInstance()->setMode(CVFD::MODE_TVRADIO);
	if (save_bouquets) {
		save_bouquets = false;
#if 0
		if (CNeutrinoApp::getInstance()->GetChannelMode() == LIST_MODE_FAV)
			g_bouquetManager->saveUBouquets();
		else
			g_bouquetManager->saveBouquets();
#endif
		if (g_settings.epg_scan == CEpgScan::SCAN_SEL)
			CEpgScan::getInstance()->Start();
	}
	if(zapOnExit)
		return (selected);

	return (res);
}
Ejemplo n.º 19
0
int main(int argc, char *argv[])
{
	unsigned int frameLimit;
	int go, i, mapID, loadSlot, recordingID, replayingID;
	int joystick, showCredits, languageID;

	go = TRUE;

	loadSlot = -1;

	game.fps = 1000 / 60;

	languageID = mapID = recordingID = replayingID = -1;

	joystick = 0;

	showCredits = FALSE;

	/* Load the resources */

	for (i=1;i<argc;i++)
	{
		if (strcmpignorecase("-record", argv[i]) == 0)
		{
			if (i + 1 >= argc)
			{
				printf("You must specify a file to record to\n");
				printf("Type %s -h for help\n", argv[0]);

				exit(1);
			}

			if (recordingID == -1)
			{
				recordingID = i + 1;
			}

			i++;
		}

		else if (strcmpignorecase("-playback", argv[i]) == 0)
		{
			if (i + 1 >= argc)
			{
				printf("You must specify a file to playback from\n");
				printf("Type %s -h for help\n", argv[0]);

				exit(1);
			}

			if (replayingID == -1)
			{
				replayingID = i + 1;
			}

			i++;
		}

		else if (strcmpignorecase("-load", argv[i]) == 0)
		{
			if (i + 1 >= argc)
			{
				printf("You must specify a slot to load from\n");
				printf("Type %s -h for help\n", argv[0]);

				exit(1);
			}

			loadSlot = atoi(argv[i + 1]);

			i++;
		}

		else if (strcmpignorecase("-nojoystick", argv[i]) == 0)
		{
			game.disableJoystick = TRUE;
		}

		else if (strcmpignorecase("-joystick", argv[i]) == 0)
		{
			if (i + 1 >= argc)
			{
				printf("You must specify a joystick slot to use\n");
				printf("Type %s -h for help\n", argv[0]);

				exit(1);
			}

			joystick = atoi(argv[i + 1]);

			i++;
		}

		else if (strcmpignorecase("-showcredits", argv[i]) == 0)
		{
			showCredits = TRUE;
		}

		else if (strstr(argv[i], "-lang") != NULL)
		{
			if (i + 1 >= argc)
			{
				printf("You must specify a language to use\n");
				printf("Type %s -h for help\n", argv[0]);

				exit(1);
			}

			languageID = i + 1;

			i++;
		}

		else if (strstr(argv[i], "-h") != NULL || strstr(argv[i], "-help") != NULL)
		{
			printf("The Legend of Edgar options\n\n");
			printf("\t-record <filename>: Captures keyboard input\n");
			printf("\t-playback <filename>: Replays keyboard input\n");
			printf("\t-load <save_slot>: Loads the game in slot <save_slot>. Slots start at 0\n");
			printf("\t-nojoystick: Disables the joystick\n");
			printf("\t-joystick <joystick_slot>: Use joystick <joystick_slot>. Slots start at 0\n");
			printf("\t-showcredits: Shows the end credits\n");
			printf("\t-language <language_code>: Use language <language_code>. e.g. en_US, es, pl\n\n");

			exit(0);
		}

		#if DEV == 1
			else if (strcmpignorecase("-saveonexit", argv[i]) == 0)
			{
				game.saveOnExit = TRUE;
			}

			else if (strcmpignorecase("-bmpwrite", argv[i]) == 0)
			{
				setScreenshotDir(argv[i + 1]);

				i++;
			}

			else
			{
				mapID = i;
			}
		#endif
	}

	setLanguage("edgar", languageID == -1 ? NULL : argv[languageID]);
	printf("Numeric is %s\n", setlocale(LC_NUMERIC, "C"));
	printf("atof(2.75) is %f\n", atof("2.75"));

	/* Call the cleanup function when the program exits */

	atexit(cleanup);

	/* Start up SDL */

	init(_("The Legend of Edgar"), joystick);

	loadRequiredResources();

	if (replayingID != -1 && recordingID != -1)
	{
		showErrorAndExit("Cannot record and replay at the same time");
	}

	#if DEV == 0
		verifyVersion();
	#endif

	/* Initialise the game variables */

	freeGameResources();

	initGame();

	if (loadSlot == -1)
	{
		if (recordingID != -1)
		{
			setRecordData(argv[recordingID]);

			setMapFile(mapID == -1 ? "map01" : argv[mapID]);
		}

		else if (replayingID != -1)
		{
			setReplayData(argv[replayingID], TRUE);

			setMapFile(mapID == -1 ? "map01" : argv[mapID]);
		}

		if (mapID != -1)
		{
			startOnMap(argv[mapID]);
		}

		else if (game.firstRun == TRUE)
		{
			tutorial();
		}

		else
		{
			game.status = IN_TITLE;
		}
	}

	else
	{
		if (recordingID != -1)
		{
			game.gameType = RECORDING;
		}

		else if (replayingID != -1)
		{
			game.gameType = REPLAYING;
		}

		if (loadGame(loadSlot) == FALSE)
		{
			showErrorAndExit("No saved game in slot %d", loadSlot);
		}

		if (recordingID != -1)
		{
			setRecordData(argv[recordingID]);

			setMapFile(getMapFilename());
		}

		else if (replayingID != -1)
		{
			setReplayData(argv[replayingID], TRUE);
		}
	}

	/* Loop indefinitely for messages */

	game.startTicks = SDL_GetTicks();

	#if DEV == 1
		printf("DEV Version\n");
	#else
		printf("Production Version\n");
	#endif

	frameLimit = SDL_GetTicks() + game.fps;

	if (showCredits == TRUE)
	{
		game.status = IN_CREDITS;
	}

	while (go == TRUE)
	{
		getInput(game.gameType);

		switch (game.status)
		{
			case IN_TITLE:
				doTitle();
			break;

			case IN_GAME:
				freeCollisionGrid();

				clearDrawLayers();

				doGame();

				doPlayer();

				doInventory();

				doMap();

				doEntities();

				doDecorations();

				doCollisions();

				doHud();

				doDialogBox();

				processMedals();
			break;

			case IN_INVENTORY:
				doInventoryMenu();
			break;

			case IN_MENU:
				doMenu();
			break;

			case IN_CREDITS:
				freeCollisionGrid();

				clearDrawLayers();

				doGame();

				doCredits();

				doDecorations();

				doCollisions();
			break;

			default:
				doMenu();
			break;
		}

		draw();

		/* Sleep briefly to stop sucking up all the CPU time */

		delay(frameLimit);

		frameLimit = SDL_GetTicks() + game.fps;

		game.frames++;
	}

	/* Exit the program */

	exit(0);
}
Ejemplo n.º 20
0
	void M11ComboLabel::mousePressEvent(QMouseEvent *e)
	{
		doMenu(e->pos());
		::QLabel::mousePressEvent(e);
	}
Ejemplo n.º 21
0
int main()
{
	long int savedfreq = 0;
	int s, c;
	unsigned char sw=0;

	// PORTB output for LCD
	DDRB = 0xff;
	PORTB = 0xff;

#ifdef BOARD2
	// PORTC PC0-4 output, PC5 input
	DDRC = 0x1f;
	PORTC = 0x00;
	sbi(PORTC, MUTE);
#endif
#ifdef BOARD1
	// PORTC PC0,2-5 output, PC1 input
	DDRC = 0x3d;
	PORTC = 0x00;
	sbi(PORTC, MUTE);
#endif

	// PORTD is input with pullup
	DDRD = 0x00;
	PORTD = 0xff;

	initLcd();
	initADC();

	// set reference freq
	fref = eeprom_read_word((unsigned int *)0x00);
	if (fref < 2000 || (fref % 100) != 0) {
		fref = 12000;
		eeprom_write_word((unsigned int *)0x00, fref);
	}

	// read squelch level from eeprom
	muteval = eeprom_read_word((unsigned int *)0x0c);
	if (muteval < 0 || muteval > 100) {
		muteval = 0;
		eeprom_write_word((unsigned int *)0x0c, muteval);
	}

	// read last frequency from eeprom
	freq = eeprom_read_dword((unsigned long int *)0x10);
	if (freq < 1240000UL || freq > 1300000UL) {
		freq = 1298375UL;
		eeprom_write_dword((unsigned long int *)0x10, freq);
	}

	// read shift from eeprom
	shift = eeprom_read_word((unsigned int *)0x18);
	if (shift < 60000UL || shift > 60000UL) {
		shift = -28000UL;
		eeprom_write_word((unsigned int *)0x18, shift);
	}

	// read tone (*10) from eeprom
	tone = eeprom_read_word((unsigned int *)0x1c);
	if (tone < 650 || tone > 1500) {
		tone = 650;
		eeprom_write_word((unsigned int *)0x1c, tone);
	}

	initInterrupts();
    initPLL(freq - IF);
	update();

	sprintf(str, "JPD 23cm v%s", version);
	lcdCmd(0x80);
	lcdStr(str);
	_delay_ms(500);

	for (;;) {

		lcdCmd(0x80);
		lcdStr("VFO             ");
		lcdCmd(0xc0);
		lcdStr("                ");
		update();

		for (;;) {
			// read switches on PORTD
			sw = PIND;

			// switch from tx to rx??
			if (tx && (sw & (1<<PTT) )) {
				cbi(PORTC, TXON);
				// switch TX off
				tx = FALSE;
//  				TCCR2A  &= ~(1<<COM2A1);
				update();
			}

			// switch from rx to tx?
			else if (!tx && !(sw & (1<<PTT) )) {
				tx = TRUE;
				displaySmeter(0);
				// switch TX on
				sbi(PORTC, TXON);
				sbi(PORTC, MUTE);
//				if (tone > 650) {
//	   				TCCR2A  |= (1<<COM2A1);
//				}
				update();
			}

			if (!tx) {
				s = readSmeter();
				displaySmeter(s);
				if (s > muteval)
					cbi(PORTC, MUTE);
				else
					sbi(PORTC, MUTE);
			}

			// switch shift off
			if ( (shiftSwitch == TRUE) && (sw & (1<<SHIFTKEY) )) {
				shiftSwitch = FALSE;
				update();
			}
			// switch shift on
			else if ( (shiftSwitch == FALSE) && !(sw & (1<<SHIFTKEY) )) {
				shiftSwitch = TRUE;
				update();
			}

			// save vfo frequency in eeprom after ~2 secs inactivity
			if (tick > 200) {
				if (freq != savedfreq) {
					eeprom_write_dword((unsigned long int *)0x10, freq);
					savedfreq = freq;
				}
			}
	
			// handle encoder pulses
			c = handleRotary();
			if (c!=0) {
				if (c>0) {
					freq += step;
				}
				else {
					freq -= step;
				}
				tick = 0;
				update();
			}

			if (rotaryPushed()) {
				doMenu();
				break;
			}
		}
	}
}
Ejemplo n.º 22
0
/* bShowChannelList default to true, returns new bouquet or -1/-2 */
int CBouquetList::show(bool bShowChannelList)
{
	neutrino_msg_t      msg;
	neutrino_msg_data_t data;
	int res = -1;

	//if(Bouquets.size()==0)
	//	return res;

	CVFD::getInstance()->setMode(CVFD::MODE_MENU_UTF8, "");

	width  = w_max (500, 0);
	height = h_max (440, 40);

	buttonHeight = 7 + std::min(16, g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getHeight());
	theight     = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getHeight();
	fheight     = g_Font[SNeutrinoSettings::FONT_TYPE_CHANNELLIST]->getHeight();
	listmaxshow = (height - theight - buttonHeight)/fheight;
	height      = theight + buttonHeight + listmaxshow * fheight; // recalc height

	x = frameBuffer->getScreenX() + (frameBuffer->getScreenWidth() - width) / 2;
	y = frameBuffer->getScreenY() + (frameBuffer->getScreenHeight() - height) / 2;

	int maxpos= 1;
	int i= Bouquets.size();
	while ((i= i/10)!=0)
		maxpos++;

	paintHead();
	paint();

	int oldselected = selected;
	int firstselected = selected+ 1;
	int zapOnExit = false;

	unsigned int chn= 0;
	int pos= maxpos;

	unsigned long long timeoutEnd = CRCInput::calcTimeoutEnd(g_settings.timing[SNeutrinoSettings::TIMING_CHANLIST]);

	bool loop=true;
	while (loop) {
		g_RCInput->getMsgAbsoluteTimeout( &msg, &data, &timeoutEnd );

		if ( msg <= CRCInput::RC_MaxRC )
			timeoutEnd = CRCInput::calcTimeoutEnd(g_settings.timing[SNeutrinoSettings::TIMING_CHANLIST]);

		if ((msg == CRCInput::RC_timeout                             ) ||
				(msg == (neutrino_msg_t)g_settings.key_channelList_cancel))
		{
			selected = oldselected;
			loop=false;
		}
		else if(msg == CRCInput::RC_red || msg == CRCInput::RC_favorites) {
			CNeutrinoApp::getInstance()->SetChannelMode(LIST_MODE_FAV);
			hide();
			return -3;
		} else if(msg == CRCInput::RC_green) {
			CNeutrinoApp::getInstance()->SetChannelMode(LIST_MODE_PROV);
			hide();
			return -3;
		} else if(msg == CRCInput::RC_yellow || msg == CRCInput::RC_sat) {
			CNeutrinoApp::getInstance()->SetChannelMode(LIST_MODE_SAT);
			hide();
			return -3;
		} else if(msg == CRCInput::RC_blue) {
			CNeutrinoApp::getInstance()->SetChannelMode(LIST_MODE_ALL);
			hide();
			return -3;
		}
		else if(Bouquets.size() == 0)
			continue; //FIXME msgs not forwarded to neutrino !!
		else if ( msg == CRCInput::RC_setup) {
			int ret = doMenu();
			if(ret) {
				res = -4;
				loop = false;
			} else
				paint();
		}
		else if ( msg == (neutrino_msg_t) g_settings.key_list_start ) {
			selected=0;
			liststart = (selected/listmaxshow)*listmaxshow;
			paint();
		}
		else if ( msg == (neutrino_msg_t) g_settings.key_list_end ) {
			selected=Bouquets.size()-1;
			liststart = (selected/listmaxshow)*listmaxshow;
			paint();
		}
		else if (msg == CRCInput::RC_up || (int) msg == g_settings.key_channelList_pageup)
		{
			int step = 0;
			int prev_selected = selected;

			step = ((int) msg == g_settings.key_channelList_pageup) ? listmaxshow : 1;  // browse or step 1
			selected -= step;
			if((prev_selected-step) < 0)            // because of uint
				selected = Bouquets.size()-1;

			paintItem(prev_selected - liststart);
			unsigned int oldliststart = liststart;
			liststart = (selected/listmaxshow)*listmaxshow;
			if(oldliststart!=liststart)
				paint();
			else
				paintItem(selected - liststart);
		}
		else if (msg == CRCInput::RC_down || (int) msg == g_settings.key_channelList_pagedown)
		{
			unsigned int step = 0;
			int prev_selected = selected;

			step = ((int) msg == g_settings.key_channelList_pagedown) ? listmaxshow : 1;  // browse or step 1
			selected += step;

			if(selected >= Bouquets.size()) {
				if (((Bouquets.size() / listmaxshow) + 1) * listmaxshow == Bouquets.size() + listmaxshow) // last page has full entries
					selected = 0;
				else
					selected = ((step == listmaxshow) && (selected < (((Bouquets.size() / listmaxshow) + 1) * listmaxshow))) ? (Bouquets.size() - 1) : 0;
			}
			paintItem(prev_selected - liststart);
			unsigned int oldliststart = liststart;
			liststart = (selected/listmaxshow)*listmaxshow;
			if(oldliststart!=liststart)
				paint();
			else
				paintItem(selected - liststart);
		}

		else if ( msg == CRCInput::RC_ok ) {
			if(!bShowChannelList || Bouquets[selected]->channelList->getSize() > 0) {
				zapOnExit = true;
				loop=false;
			}
		}
		else if (CRCInput::isNumeric(msg)) {
			if (pos == maxpos) {
				if (msg == CRCInput::RC_0) {
					chn = firstselected;
					pos = maxpos;
				} else {
					chn = CRCInput::getNumericValue(msg);
					pos = 1;
				}
			} else {
				chn = chn * 10 + CRCInput::getNumericValue(msg);
				pos++;
			}

			if (chn > Bouquets.size()) {
				chn = firstselected;
				pos = maxpos;
			}

			int prevselected=selected;
			selected = (chn - 1) % Bouquets.size(); // is % necessary (i.e. can firstselected be > Bouquets.size()) ?
			paintItem(prevselected - liststart);
			unsigned int oldliststart = liststart;
			liststart = (selected/listmaxshow)*listmaxshow;
			if(oldliststart!=liststart) {
				paint();
			} else {
				paintItem(selected - liststart);
			}

		} else {
			if ( CNeutrinoApp::getInstance()->handleMsg( msg, data ) & messages_return::cancel_all ) {
				loop = false;
				res = -2;
			}
		};
	}
	hide();
	CVFD::getInstance()->setMode(CVFD::MODE_TVRADIO);
	if(zapOnExit) {
		return (selected);
	} else {
		return (res);
	}
}
Ejemplo n.º 23
0
int balanceManagerChild(Menu* menu, char* currentWallet) {
  Currency balance;
  getWalletBalance(&balance, currentWallet);
  char balanceStr[15];
  currencyToString(balanceStr, &balance);
  char subtitle[21];
  strcpy(subtitle, (char*)"Balance: ");
  strcat(subtitle, balanceStr);
  Transaction txs[MAX_DAY_EVENTS];
  char menulabels[MAX_DAY_EVENTS][44];
  menu->numitems = getWalletTransactions(currentWallet, txs);
  MenuItem items[menu->numitems];
  for(int i = 0; i < menu->numitems; i++) {
    char amount[15];
    currencyToString(amount, &txs[i].amount);

    // build menu item so that the text is cut and the values aligned on the right column
    // independently of the description containing multibyte chars and their location
    char* s = txs[i].description;
    int len = 0, glen = 0;
    while(*s) {
      len++;
      glen++;
      if(MB_IsLead(*s)) glen--;
      if(glen >= 14) { // this way we only care about the section that is to be displayed
        break;
      }
      s++;
    }
    memset(menulabels[i], ' ', 43); // blank parts that would not be touched
    int offset = len-glen;
    memcpy(menulabels[i], txs[i].description, (glen > 14 ? 14+offset : len));
    if(MB_IsLead(menulabels[i][14+offset]))
      menulabels[i][14+offset] = ' '; // eliminate half-MB char
    strncpy(menulabels[i]+15+offset, amount, 6);
    menulabels[i][21+offset] = 0;

    if(txs[i].credit) items[i].color = TEXT_COLOR_GREEN;
    else items[i].color = TEXT_COLOR_RED;
    items[i].text = menulabels[i];
  }
  menu->items = items;
  while(1) {
    Bdisp_AllClr_VRAM();
    drawScreenTitle("Balance Manager", subtitle);
    // VIEW, INSERT, EDIT, DELETE, empty, LOAD
    drawFkeyLabels(-1, 0x03B4, -1, -1, -1, 0x03B7);
    if(menu->numitems > 0) drawFkeyLabels(0x049F, -1, 0x0038);
    int res = doMenu(menu);
    switch(res) {
      case MENU_RETURN_EXIT:
        return 0;
        break;
      case KEY_CTRL_F1:
      case MENU_RETURN_SELECTION:
        if(menu->numitems) viewTransaction(&txs[menu->selection-1]);
        break;
      case KEY_CTRL_F2:
        if(addTransactionWizard(currentWallet)) {
          return 1;
        }
        break;
      case KEY_CTRL_F3:
      case KEY_CTRL_DEL:
        if(menu->numitems &&
           deleteTransactionPrompt(txs, currentWallet, menu->numitems, menu->selection-1)) {
          return 1;
        }
        break;
      case KEY_CTRL_F6:
        if(changeWalletScreen(currentWallet)) {
          menu->selection = 0;
          menu->scroll = 0;
          return 1;
        }
        break;
    }
  }
  return 0;
}
Ejemplo n.º 24
0
void _hMenu()
{
	if (doMenu(&mnuMain))
		loadPage(mnuMain.marked + 2);
}
Ejemplo n.º 25
0
int addTransactionWizard(char* wallet) {
  Transaction tx;
  tx.date.year = getCurrentYear();
  tx.date.month = getCurrentMonth();
  tx.date.day = getCurrentDay();
  tx.time.hour = getCurrentHour();
  tx.time.minute = getCurrentMinute();
  tx.time.second = getCurrentSecond();
  strcpy(tx.description, (char*)"");
  int curstep = 0;
  while(1) {
    SetBackGround(0x0A);
    drawScreenTitle("Add transaction");
    // < (first label), SELECT of on date step, and Next or Finish (last label)
    drawFkeyLabels(curstep>0 ? 0x036F : -1, curstep == 2 ? 0x000F : 0, 0, 0, 0,
                   curstep==4 ? 0x04A4 : 0x04A3);
    if(curstep == 0) {
      MenuItem menuitems[5];
      menuitems[0].text = (char*)"Debit";
      menuitems[1].text = (char*)"Credit";

      Menu menu;
      menu.items=menuitems;
      menu.type=MENUTYPE_FKEYS;
      menu.numitems=2;
      menu.height=2;
      menu.startY=3;
      menu.pBaRtR=1;
      int inloop=1;
      while(inloop) {
        // this must be here, inside this loop:
        SetBackGround(0x0A);
        drawScreenTitle("Add transaction", "Select type:");
        drawFkeyLabels(-1, -1, -1, -1, -1, 0x04A3);
        int res = doMenu(&menu);
        if(res == MENU_RETURN_EXIT) return 0;
        else if(res == KEY_CTRL_F6 || res == MENU_RETURN_SELECTION) {
          tx.credit = menu.selection == 2;
          curstep++;
          break;
        }
      }
    } else if(curstep == 1) {
      drawScreenTitle(NULL, "Amount:");
      char samount[20] = "";
      if(tx.amount.val) {
        currencyToString(samount, &tx.amount);
      }
      textInput input;
      input.charlimit=12;
      input.acceptF6=1;
      input.symbols = 0; // allow the decimal separator
      input.forcetext = 1;
      input.buffer = (char*)samount;
      input.type = INPUTTYPE_NUMERIC;
      while(1) {
        input.key=0;
        int res = doTextInput(&input);
        if (res==INPUT_RETURN_EXIT) return 0; // user aborted
        else if (res==INPUT_RETURN_CONFIRM) {
          if(!stringToCurrency(&tx.amount, samount)) {
            if(!tx.amount.val) {
              AUX_DisplayErrorMessage(0x4B);
            } else {
              curstep++;
            }
            break;
          } else AUX_DisplayErrorMessage(0x43);
        } else if (res==INPUT_RETURN_KEYCODE && input.key == KEY_CTRL_F1) {
          curstep--;
          break;
        }
      }
    } else if(curstep == 2) {
      drawScreenTitle(NULL, "Date:");
      mPrintXY(7, 4, getInputDateFormatHint(), TEXT_MODE_TRANSPARENT_BACKGROUND, TEXT_COLOR_BLACK);
      textInput input;
      input.x=7;
      input.width=8;
      input.charlimit=8;
      input.acceptF6=1;
      input.type=INPUTTYPE_DATE;
      char datebuffer[15];
      fillInputDate(&tx.date, datebuffer);
      input.buffer = (char*)datebuffer;
      while(1) {
        input.key=0;
        int res = doTextInput(&input);
        if (res==INPUT_RETURN_EXIT) return 0; // user aborted
        else if (res==INPUT_RETURN_CONFIRM) {
          int len = strlen(datebuffer);
          if(len == input.charlimit) {
            int yr,m,d;
            stringToDate(datebuffer, &yr, &m, &d);
            if(isDateValid(yr, m, d)) {
                tx.date.year = yr;
                tx.date.month = m;
                tx.date.day = d;
                curstep++;
                break; // continue to next step
            } else invalidFieldMsg(0);
          } else invalidFieldMsg(0);
        } else if (res==INPUT_RETURN_KEYCODE) {
          if(input.key==KEY_CTRL_F1) {
            curstep=curstep-1; break;
          } else if(input.key==KEY_CTRL_F2) {
            int ey=0, em=0, ed=0;
            if(!selectDateScreen(&ey, &em, &ed,
                                  (char*)"Select transaction date:", NULL, 1)) {
              tx.date.year = ey;
              tx.date.month = em;
              tx.date.day = ed;
              curstep++; break; // continue to next step
            }
            break; //redraw
          }
        }
      }
    } else if(curstep == 3) {
      drawScreenTitle(NULL, "Time:");
      mPrintXY(8, 4, "HHMMSS", TEXT_MODE_TRANSPARENT_BACKGROUND, TEXT_COLOR_BLACK);
      
      textInput input;
      input.x=8;
      input.width=6;
      input.charlimit=6;
      input.acceptF6=1;
      input.type=INPUTTYPE_TIME;
      char tbuffer[15];
      fillInputTime(&tx.time, tbuffer);
      input.buffer = (char*)tbuffer;
      while(1) {
        input.key=0;
        int res = doTextInput(&input);
        if (res==INPUT_RETURN_EXIT) return 0; // user aborted
        else if (res==INPUT_RETURN_CONFIRM) {
          if((int)strlen(tbuffer) == input.charlimit) {
            int h, m, s;
            stringToTime(tbuffer, &h, &m, &s);
            if(isTimeValid(h, m, s)) {
              tx.time.hour = h;
              tx.time.minute = m;
              tx.time.second = s;
              curstep++;
              break; // continue to next step
            } else invalidFieldMsg(1);
          } else invalidFieldMsg(1);
        } 
        else if (res==INPUT_RETURN_KEYCODE && input.key==KEY_CTRL_F1) { curstep--; break; }
      }
    } else if(curstep == 4) {
      drawScreenTitle(NULL, "Description:");
      textInput input;
      input.charlimit=128;
      input.acceptF6=1;
      input.buffer = (char*)tx.description;
      int inloop = 1;
      while(inloop) {
        input.key=0;
        int res = doTextInput(&input);
        if (res==INPUT_RETURN_EXIT)
          return 0; // user aborted
        else if (res==INPUT_RETURN_CONFIRM)
          inloop = 0; // all fields complete, continue with transaction adding
        else if (res==INPUT_RETURN_KEYCODE && input.key == KEY_CTRL_F1) {
          curstep--;
          break;
        }
      }
      if(!inloop) break;
    }
  }
  addTransaction(&tx, wallet);
  return 1;
}
Ejemplo n.º 26
0
int changeWalletScreen(char* currentWallet) {
  // returns 1 if user changes to another wallet
  char* currentWalletNice = filenameToName(currentWallet);
  Menu menu;
  menu.title = (char*)"Wallet List";
  menu.scrollout=1;
  menu.type=MENUTYPE_FKEYS;
  menu.height = 7;
  MenuItem items[MAX_WALLETS];
  int mustRefresh = 0;
  while(1) {
    char wallets[MAX_WALLETS][MAX_WALLETNAME_SIZE];
    // build wallet list:
    unsigned short path[MAX_FILENAME_SIZE+1], found[MAX_FILENAME_SIZE+1];
    char buffer[MAX_FILENAME_SIZE+1];

    // make the buffer
    strcpy(buffer, BALANCEFOLDER"\\*");
    
    file_type_t fileinfo;
    int findhandle;
    Bfile_StrToName_ncpy(path, buffer, MAX_FILENAME_SIZE+1);
    int ret = Bfile_FindFirst_NON_SMEM((const char*)path, &findhandle, (char*)found, &fileinfo);
    int i = 0;
    while(!ret) {
      Bfile_NameToStr_ncpy(buffer, found, MAX_FILENAME_SIZE+1);
      if(fileinfo.fsize == 0 &&
         !(strcmp((char*)buffer, "..") == 0 || strcmp((char*)buffer, ".") == 0)) { // find folders
        strcpy(wallets[i], buffer);
        items[i].text = wallets[i];
        i++;
        if(!strcmp(buffer, currentWalletNice)) menu.selection = i;
        if(i == MAX_WALLETS) break;
      }
      ret = Bfile_FindNext_NON_SMEM(findhandle, (char*)found, (char*)&fileinfo);
    }
    menu.items = items;
    menu.numitems = i;
    Bfile_FindClose(findhandle);
    drawFkeyLabels(0x000F, 0x0186, 0x0188, 0x0038, 0, 0); // SELECT, NEW, RENAME, DELETE
    int res = doMenu(&menu);
    switch(res) {
      case MENU_RETURN_EXIT:
        return mustRefresh;
        break;
      case KEY_CTRL_F1:
      case MENU_RETURN_SELECTION:
        if(strcmp(currentWalletNice, wallets[menu.selection-1])) {
          walletNameToPath(buffer, wallets[menu.selection-1]);
          setCurrentWallet(buffer);
          return 1;
        } return mustRefresh;
        break;
      case KEY_CTRL_F2:
        if(menu.numitems >= MAX_WALLETS) {
          AUX_DisplayErrorMessage( 0x2E );
        } else {
          createWalletWizard(0);
        }
        break;
      case KEY_CTRL_F3:
        char newWallet[MAX_FILENAME_SIZE];
        if(renameWalletScreen(wallets[menu.selection-1], newWallet)) {
          walletNameToPath(buffer, wallets[menu.selection-1]);
          if(!strcmp(currentWallet, buffer)) {
            // if the renamed wallet was the current one, we must set the current wallet to the
            // new name.
            setCurrentWallet(newWallet);
            mustRefresh = 1;
          }
        }
        break;
      case KEY_CTRL_F4:
      case KEY_CTRL_DEL:
        walletNameToPath(buffer, wallets[menu.selection-1]);
        if(deleteWalletPrompt(buffer)) {
          if(menu.numitems <= 1) {
            // this was the only wallet: delete pointer file too, so that user is prompted to create
            // a new wallet.
            unsigned short path[MAX_FILENAME_SIZE+1];
            strcpy(buffer, BALANCEFOLDER"\\Wallet");
            Bfile_StrToName_ncpy(path, buffer, MAX_FILENAME_SIZE);
            Bfile_DeleteEntry(path);
            return 1;
          }
          if(!strcmp(currentWallet, buffer)) {
            // if the deleted wallet was the current one, we must set the current wallet to the
            // first one on the list that is not the deleted one.
            // (by now we know there is more than one wallet in the list)
            for(int i = 0; i < menu.numitems; i++) {
              walletNameToPath(buffer, wallets[i]);
              if(strcmp(currentWallet, buffer)) break;
            }
            setCurrentWallet(buffer);
            mustRefresh = 1;
          }
        }
        break;
    }
  }
}
Ejemplo n.º 27
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;
    }
  }
}
Ejemplo n.º 28
0
void main(void) 
{
    // initialise the RTC communication line
    I2C_Init() ;
    // initialise the LCD display
    LCDInit(LS_NONE);
    // initialise the actual RTC
    DS1307_Init() ;

    //clear the display
    LCDClear();
    
    // read back our running time
    DS1307_readRam(&runningMinutes,0,2) ;
    DS1307_readRam(&runningHours,2,2) ;
    
    LCDWriteString("Starting counter");
    LCDGotoXY(0,1) ;
    LCDWriteString("at ");
    LCDWriteInt(runningHours,1);
    LCDWriteString(":");
    LCDWriteInt(runningMinutes,1);
    __delay_ms(750) ;
    __delay_ms(750) ;
    __delay_ms(750) ;
    __delay_ms(750) ;

    // compensate for our handling on the first run of the readClock routine
    runningMinutes-- ;

    LCDClear();
    // infinite loop, read the clock, display on the LCD, check for the button, and if needed, process the menus
   while(1)
  {       
      readClock();
      
      showClock() ;           
      
      readInputs() ;
      
      if (bButton)
        doMenu();
      else if (state & 0x30)
      {
          // rotate the encoder to select a menu function, well, that was the aim, but encoder reading
          // seems a tad slow or inaccurate.
          //
          // there is a timeout if the button isn't pressed after selecting the menu option
          
          if (state & DIR_CW)
          {
              menuFunction++ ;
              if (menuFunction == MENU_LAST)
                  menuFunction = MENU_NONE ;
          }
          else if (state & DIR_CCW)
          {
              menuFunction-- ;
              if (menuFunction < MENU_NONE)
                  menuFunction = MENU_LAST-1 ;
          }
          
          if (menuFunction != MENU_NONE)
          {
              next_menu_clear = minute * 60 + seconds + 20 ;
              LCDGotoXY(9,0);
              if (menuFunction == MENU_TIME)
                LCDWriteString("Time ?");
              if (menuFunction == MENU_DATE)
                LCDWriteString("Date ?");
          }
          else
              clearPrompt();
      }
      else if (next_menu_clear && ((minute * 60 + seconds) > next_menu_clear))
      {
          clearPrompt();
      }
  }
}
Ejemplo n.º 29
0
int showCatalog(char* insertText) {
  int ret;
  // returns 0 on failure (user exit) and 1 on success (user chose a option)
  MenuItem menuitems[9];
  menuitems[0].text = (char*)"All";
  menuitems[1].text = (char*)"Complex number";
  menuitems[2].text = (char*)"Linear algebra";
  menuitems[3].text = (char*)"Calculus";
  menuitems[4].text = (char*)"Polynomial";
  menuitems[5].text = (char*)"Special";
  menuitems[6].text = (char*)"Program and logic";
  menuitems[7].text = (char*)"Trigonometry";
  menuitems[8].text = (char*)"Other";
  
  Menu menu;
  menu.items=menuitems;
  menu.numitems=9;
  menu.scrollbar=1;
  menu.scrollout=1;
  menu.selection=1;
  menu.scroll=0;
  menu.title = (char*)"Function Catalog";
  
  int incat = 1;
  while(incat) {
    int sres = doMenu(&menu);
    ret=0;
    if(sres == MENU_RETURN_SELECTION) {
      switch(menu.selection) {
        case 1:
          if(doCatalogMenu(insertText, menuitems[0].text, CAT_CATEGORY_ALL)) {
            ret=1;
            incat = 0;
          }
          break;
        case 2:
          if(doCatalogMenu(insertText, menuitems[1].text, CAT_CATEGORY_COMPLEXNUM)) {
            ret=1;
            incat = 0;
          }
          break;
        case 3:
          if(doCatalogMenu(insertText, menuitems[2].text, CAT_CATEGORY_LINEARALG)) {
            ret=1;
            incat = 0;
          }
          break;
        case 4:
          if(doCatalogMenu(insertText, menuitems[3].text, CAT_CATEGORY_CALCULUS)) {
            ret=1;
            incat = 0;
          }
          break;
        case 5:
          if(doCatalogMenu(insertText, menuitems[4].text, CAT_CATEGORY_POLYNOMIAL)) {
            ret=1;
            incat = 0;
          }
          break;
        case 6:
          if(doCatalogMenu(insertText, menuitems[5].text, CAT_CATEGORY_SPECIAL)) {
            ret=1;
            incat = 0;
          }
          break;
        case 7:
          if(doCatalogMenu(insertText, menuitems[6].text, CAT_CATEGORY_PROG)) {
            ret=1;
            incat = 0;
          }
          break;
        case 8:
          if(doCatalogMenu(insertText, menuitems[7].text, CAT_CATEGORY_TRIG)) {
            ret=1;
            incat = 0;
          }
          break;
        case 9:
          if(doCatalogMenu(insertText, menuitems[8].text, CAT_CATEGORY_OTHER)) {
            ret=1;
            incat = 0;
          }
          break;
      }
    } else {
      incat = 0;
    }
  }
  return ret;
}