Exemplo n.º 1
0
Arquivo: M16.cpp Projeto: pekasus/M16
void M16::buttonSelect(byte butOne, byte butTwo, byte butThree)
{
	for(unsigned int ii = 0; ii < timeout; ii++) {
    	byte butPress = checkButtons();
    	if (butPress == but1) {
      menuSelect(butOne);
    	}
    	else if (butPress == but2) {
			menuSelect(butTwo);
    	}
    	else if (butPress == but3) {
    		menuSelect(butThree);
    	}
    	else if (butPress == but4) {
			break;
    	}
    	else {
    		delay(200);
    	}
  	}
}
Exemplo n.º 2
0
int main(int argc, const char * argv[])
{
	/*
	 * Actual app
	 */
	// Setup Connection to DB
	setupConnection();
	
	// Create dirs
	createDirectory(BackgroundDIR);
	createDirectory(TargetDIR);
	
	// Run Menu
	menuSelect();
	
	// Close Connection
	closeConnection();
	/*
	 * END Actual app
	 */
	
    return 0;
}
Exemplo n.º 3
0
//----------------------------------------------------------------------
//  This is the Main routine for swtmain1c
//
int main(short argc, char **argv)
{
   char msg[200];
   uchar data[256];
   int portnum = 0;
   int n=0;
   int addr = 0;
   int len;
   uchar es = 0x00;
   uchar address[2];
   ushort i;
   uchar sn[8],state[3], reg[3], send_block[37];
   uchar family[2][8];
   int done=FALSE; 
   int channel=0,send_cnt=0;
   SMALLINT alternate=TRUE, alt=FALSE;
   ushort lastcrc16;
   uchar latch, set;
   uchar check;

   // check for required port name
   if (argc != 2)
   {
      sprintf(msg,"1-Wire Net name required on command line!\n"
                  " (example: \"COM1\" (Win32 DS2480),\"/dev/cua0\" "
                  "(Linux DS2480),\"1\" (Win32 TMEX)\n");
      printf("%s",msg);
      return 0;
   }

   if((portnum = owAcquireEx(argv[1])) < 0)
   {
      printf("Did not Acquire port.\n",1);
      exit(1);
   }
   else
   {
      if(FindDevices(portnum,&family[0],0x1C,1))
      {
         for(i=0;i<8;i++)
            sn[i] = family[0][i];

         printf("device found: ");
         for(i=0;i<8;i++)
            printf("%02X ",sn[i]);
         printf("\n");

         do
         {
            printf("PICK AN OPERATION:\n\n");
            printf("(1)  Read Channel state\n");             // Gives channel information

            printf("(2)  Set Channel On/Off\n");             // Sets channel

            printf("(3)  Read Channel Mask\n");              // Read Selection Mask

            printf("(4)  Set Channel mask\n");               // Sets channel mask

            printf("(5)  Read Channel Polarity\n");          // Read Polarity Selection

            printf("(6)  Set Channel polarity\n");           // sets channel polarity

            printf("(7)  Read Control/Status Register\n");   // Read Control/Status Reg

            printf("(8)  Set Reset Mode On/Off\n");          // Set Reset Mode

            printf("(9)  Clear Power on Reset\n");           // Clear Power on reset

            printf("(10) Get VCC state\n");                  // Get VCC state

            printf("(11) Set OR conditional search\n");      // or condition search

            printf("(12) Set AND conditional search\n");     // and condition search

            printf("(13) Write Scratchpad\n");               // write scratchpad command

            printf("(14) Read Scratchpad\n");                // read scratchpad command

            printf("(15) Copy Scratchpad\n");                // copy scratchpad command

            printf("(16) Read Memory\n");                    // read memory

            printf("(17) PIO access read with CRC confirmation\n");  // access read

            printf("(18) LED test\n");                       // LED test

            printf("(19) QUIT\n");

            scanf("%d",&n);
            if(n == 19)
            {
               n = 0;        //used to finish off the loop
               done = TRUE;
               break;
            }

            switch(n)
            {
               case 1:  // Channel Info
                  printf("\nEnter the channel\n");
                  scanf("%d",&channel);

                  if(readSwitch1C(portnum,&sn[0],&state[0]))
                  {
                     printf("The channel is ");
                     if(getLatchState1C(channel,&state[0]))
                        printf("on.\n");
                     else
                        printf("off\n");
                     printf("The Level is ");
                     if(getLevel1C(channel,&state[0]))
                        printf("high.\n");
                     else
                        printf("low.\n");
                     if(getSensedActivity1C(channel,&state[0]))
                        printf("Activity was detected on the channel.\n\n");
                     else
                        printf("No activity was detected on the channel.\n\n");
                  }
                  else
                     OWERROR_DUMP(stdout);

                  break;

               case 2:  // Sets channel
                  printf("\nEnter the channel\n");
                  scanf("%d",&channel);
                  printf("Turn channel off enter 0, on 1.\n");
                  scanf("%d",&set);

                  if(setLatchState1C(portnum,&sn[0],channel,set))
                  {
                     printf("Latch was set ");
                     if(set)
                        printf("on.\n");
                     else
                        printf("off.\n");
                  }
                  else
                     OWERROR_DUMP(stdout);

                  break;

               case 3:  // Read Selection Mask
                  printf("\nEnter the channel\n");
                  scanf("%d",&channel);

                  if(readRegister1C(portnum,&sn[0],&reg[0]))
                  {
                     printf("register is %02X %02X %02X\n",reg[0],reg[1],reg[2]);
                     printf("The Selection Mask for channel %d is ",channel);

                     latch = (uchar) (0x01 << channel);
                    
                     if((reg[0] & latch) == latch)
                        printf("set.\n\n");
                     else
                        printf("not set.\n\n");
                  }
                  else
                     OWERROR_DUMP(stdout);

                  break;

               case 4:  // Sets channel mask
                  printf("\nEnter the channel\n");
                  scanf("%d",&channel);
                  printf("Turn channel mask off enter 0, on 1.\n");
                  scanf("%d",&set);

                  if(setChannelMask1C(portnum,&sn[0],channel,set))
                  {
                     printf("The mask for channel %d was set ",channel);
                     if(set)
                        printf("on.\n\n");
                     else
                        printf("off.\n\n");
                  }
                  else
                     OWERROR_DUMP(stdout);

                  break;

               case 5:  // Read Polarity Selection 
                  printf("\nEnter the channel\n");
                  scanf("%d",&channel);

                  printf("The Polarity for channel %d is ",channel);

                  if(getChannelPolarity1C(portnum,&sn[0],channel))
                     printf("set.\n\n");
                  else
                     printf("not set.\n\n");

                  break;

               case 6:  // sets channel polarity
                  printf("\nEnter the channel\n");
                  scanf("%d",&channel);
                  printf("Turn channel polarity off enter 0, on 1.\n");
                  scanf("%d",&set);

                  if(setChannelPolarity1C(portnum,&sn[0],channel,set))
                  {
                     printf("The polarity for channel %d was set ",channel);
                     if(set)
                        printf("on.\n\n");
                     else
                        printf("off.\n\n");
                  }
                  else
                     OWERROR_DUMP(stdout);

                  break;

               case 7:  // Read Control/Status Reg
                  if(readRegister1C(portnum,&sn[0],&reg[0]))
                     printf("The Constrol/Status register is as following in hex %02X\n\n",
                             reg[2]);
                  else
                     OWERROR_DUMP(stdout);

                  break;

               case 8:  // Set Reset Mode
                  printf("Turn reset mode off enter 0, on 1.\n");
                  scanf("%d",&set);

                  if(setResetMode1C(portnum,&sn[0],set))
                  {
                     printf("Reset Mode was turned ");
                     if(set)
                        printf("on.\n\n");
                     else
                        printf("off.\n\n");
                  }
                  else
                     OWERROR_DUMP(stdout);

                  break;

               case 9:  // Clear Power on reset
                  if(clearPowerOnReset1C(portnum,&sn[0]))
                     printf("Power on reset was cleared.\n\n");
                  else
                     OWERROR_DUMP(stdout);

                  break;

               case 10:  // Get VCC state
                  if(readRegister1C(portnum,&sn[0],&reg[0]))
                  {
                     printf("VCC state register is %02X\n",reg[2]);
                     if(getVCC1C(&reg[0]))
                        printf("VCC is powered.\n\n");
                     else
                        printf("VCC is grounded.\n\n");
                  }
                  else
                     OWERROR_DUMP(stdout);

                  break;

               case 11:  // or condition search
                  if(orConditionalSearch1C(portnum,&sn[0]))
                     printf("OR condition search was set.\n\n");
                  else
                     OWERROR_DUMP(stdout);

                  break;

               case 12:  // and condition search
                  if(andConditionalSearch1C(portnum,&sn[0]))
                     printf("AND condition search was set.\n\n");
                  else
                     OWERROR_DUMP(stdout);

                  break;

               case 13:  // write scratchpad
                  printf("Enter the address to start writing: ");

                  addr = getNumber(0, 550);

            		if(menuSelect(&sn[0]) == MODE_TEXT)
       					len = getData(data,MAX_LEN,MODE_TEXT);
        				else
        					len = getData(data,MAX_LEN,MODE_HEX);

                  if(!writeScratch1C(portnum,&sn[0],addr,len,&data[0]))
                     OWERROR_DUMP(stdout);
                  break;

               case 14:  // read scratchpad
                  if(!readScratch1C(portnum,&sn[0],&len,&es,&address[0],&data[0]))
                  {
                     printf("error\n");
                     OWERROR_DUMP(stdout);
                  }
                  else
                  {
                     printf("Address bytes:   %02X %02X\n",address[0],address[1]);
                     printf("ES byte:         %02X\n",es);
                     printf("Length:          %d\n",len);
                     printf("Scratchpad data: ");
                     for(i=0;i<len;i++)
                        printf("%02X ",data[i]);
                     printf("\n");
                  }

                  break;

               case 15:  // copy scratchpad
                  if(!copyScratch1C(portnum,&sn[0]))
                  {
                     OWERROR_DUMP(stdout);
                  }
                  else
                  {
                     printf("Copy Scratchpad Complete.\n");
                  }

                  break;

               case 16:  // read memory
                  printf("Enter the address to start reading: ");
                  addr = getNumber(0, 550);

                  printf("Enter the length you want to read: ");
                  len = getNumber(0,256);

                  if(!read1C(portnum,&sn[0],addr,len,&data[0]))
                  {
                     OWERROR_DUMP(stdout);
                  }
                  else
                  {
                     for(i=0;i<len;i++)
                        printf("%02X ",data[i]);
                     printf("\n");
                  }

                  break;

               case 17:  // and condition search
                  if (!owTouchReset(portnum))
                     OWERROR_DUMP(stdout);

                  if(!owWriteByte(portnum,0xCC))
                     printf("skip rom error.\n");

                  owWriteByte(portnum,0xF5);
                  for(i=0;i<34;i++)
                     send_block[send_cnt++] = 0xFF;
                  
                  if(!owBlock(portnum,FALSE,&send_block[0],send_cnt))
                  {
                     OWERROR(OWERROR_BLOCK_FAILED);
                     return FALSE;
                  }

                  setcrc16(portnum,0);
                  lastcrc16 = docrc16(portnum,0xF5);
                  for(i=0;i<34;i++)
                     lastcrc16 = docrc16(portnum,send_block[i]);
                  if(lastcrc16 != 0xB001)
                     printf("CRC didn't match.\n");


                  printf("read data: ");
                  for(i=0;i<34;i++)
                     printf("%02X ",send_block[i]);
                  printf("\n");

                  send_cnt = 0;
                  for(i=0;i<34;i++)
                     send_block[send_cnt++] = 0xFF;
                  
                  if(!owBlock(portnum,FALSE,&send_block[0],send_cnt))
                  {
                     OWERROR(OWERROR_BLOCK_FAILED);
                     return FALSE;
                  }

                  setcrc16(portnum,0);
                  for(i=0;i<34;i++)
                     lastcrc16 = docrc16(portnum,send_block[i]);
                  if(lastcrc16 != 0xB001)
                     printf("CRC2 didn't match.\n");


                  printf("read data2: ");
                  for(i=0;i<34;i++)
                     printf("%02X ",send_block[i]);
                  printf("\n");

                  send_cnt = 0;
                  for(i=0;i<34;i++)
                     send_block[send_cnt++] = 0xFF;
                  
                  if(!owBlock(portnum,FALSE,&send_block[0],send_cnt))
                  {
                     OWERROR(OWERROR_BLOCK_FAILED);
                     return FALSE;
                  }

                  setcrc16(portnum,0);
                  for(i=0;i<34;i++)
                     lastcrc16 = docrc16(portnum,send_block[i]);
                  if(lastcrc16 != 0xB001)
                     printf("CRC3 didn't match.\n");


                  printf("read data3: ");
                  for(i=0;i<34;i++)
                     printf("%02X ",send_block[i]);
                  printf("\n");

                  break;

               case 18:  // LED test
                  printf("\nEnter the channel to turn the LED on.\n");
                  scanf("%d",&channel);
                  printf("Turn reset mode off enter 1, on 0.\n");
                  scanf("%d",&set);
                  printf("Alternate on and off 0=No, 1=Yes.\n");
                  scanf("%d",&alternate);

                  if (!owTouchReset(portnum))
                     OWERROR_DUMP(stdout);

                  if(!owWriteByte(portnum,0xCC))
                     printf("skip rom error.\n");

                  owWriteByte(portnum,0x5A);

                  for(i=0;i<256;i++)
                  {
                     if(channel == 0)
                     {
                        if(set == 0)
                        {
                           if(!alternate)
                           {
                              if(!owWriteByte(portnum,0xFE))
                                 printf("write byte error.\n");
                              if(!owWriteByte(portnum,0x01))
                                 printf("write byte error.\n");
                              check = 0xFE;
                           }
                           else
                           {
                              if(alt)
                              {
                                 if(!owWriteByte(portnum,0xFE))
                                    printf("write byte error.\n");
                                 if(!owWriteByte(portnum,0x01))
                                    printf("write byte error.\n");
                                 check = 0xFE;
                                 alt = FALSE;
                              }
                              else
                              {
                                 if(!owWriteByte(portnum,0xFF))
                                    printf("write byte error.\n");
                                 if(!owWriteByte(portnum,0x00))
                                    printf("write byte error.\n");
                                 check = 0xFF;
                                 alt = TRUE;
                              }
                           }
                        }
                        else
                        {
                           if(!alternate)
                           {
                              if(!owWriteByte(portnum,0xFF))
                                 printf("write byte error.\n");
                              if(!owWriteByte(portnum,0x00))
                                 printf("write byte error.\n");
                              check = 0xFF;
                           }
                           else
                           {
                              if(alt)
                              {
                                 if(!owWriteByte(portnum,0xFE))
                                    printf("write byte error.\n");
                                 if(!owWriteByte(portnum,0x01))
                                    printf("write byte error.\n");
                                 check = 0xFE;
                                 alt = FALSE;
                              }
                              else
                              {
                                 if(!owWriteByte(portnum,0xFF))
                                    printf("write byte error.\n");
                                 if(!owWriteByte(portnum,0x00))
                                    printf("write byte error.\n");
                                 check = 0xFF;
                                 alt = TRUE;
                              }
                           }
                        }
                     }
                     else
                     {
                        if(set == 0)
                        {
                           if(!alternate)
                           {
                              if(!owWriteByte(portnum,0xFD))
                                 printf("write byte error.\n");
                              if(!owWriteByte(portnum,0x02))
                                 printf("write byte error.\n");
                              check = 0xFD;
                           }
                           else
                           {
                              if(alt)
                              {
                                 if(!owWriteByte(portnum,0xFD))
                                    printf("write byte error.\n");
                                 if(!owWriteByte(portnum,0x02))
                                    printf("write byte error.\n");
                                 check = 0xFD;
                                 alt = FALSE;
                              }
                              else
                              {
                                 if(!owWriteByte(portnum,0xFF))
                                    printf("write byte error.\n");
                                 if(!owWriteByte(portnum,0x00))
                                    printf("write byte error.\n");
                                 check = 0xFF;
                                 alt = TRUE;
                              }
                           }
                        }
                        else
                        {
                           if(!alternate)
                           {
                              if(!owWriteByte(portnum,0xFF))
                                 printf("write byte error.\n");
                              if(!owWriteByte(portnum,0x00))
                                 printf("write byte error.\n");
                              check = 0xFF;
                           }
                           else
                           {
                              if(alt)
                              {
                                 if(!owWriteByte(portnum,0xFD))
                                    printf("write byte error.\n");
                                 if(!owWriteByte(portnum,0x02))
                                    printf("write byte error.\n");
                                 check = 0xFD;
                                 alt = FALSE;
                              }
                              else
                              {
                                 if(!owWriteByte(portnum,0xFF))
                                    printf("write byte error.\n");
                                 if(!owWriteByte(portnum,0x00))
                                    printf("write byte error.\n");
                                 check = 0xFF;
                                 alt = TRUE;
                              }
                           }
                        }
                     }

                     send_block[0] = (uchar)owReadByte(portnum);

                     send_block[1] = (uchar)owReadByte(portnum);

                     if((send_block[0] != 0xAA) && (send_block[1] != check))
                        printf("confirmation byte was %02X and read back was %02X\n",
                                 send_block[0],send_block[1]);
                  }

               default:
                  break;
            }

         }while(!done);

      }
      else
         printf("DS28E04 not found on One Wire Network\n");

      owRelease(portnum);
   }

   return 1;
}
Exemplo n.º 4
0
/**
 * Extra options for the DS2432
 *
 * bank    the memory bank to be used.
 * portnum port number for the device
 * SNum    The serial number for the chosen device.
 *
 * @return numeric value entered from the console.
 */
SMALLINT optionSHAEE(SMALLINT bank, int portnum, uchar *SNum)
{
   int done      = FALSE;
   int try_again = FALSE;
   int addr,len;
   uchar data[64];
   int i;

   do
   {
      switch(bank)
      {
         case 0: case 1: case 2: case 3:
            done = TRUE;
            break;

         case 4:   // Load First Secret
            printf("Enter the address for loading first secret: ");
            addr = getNumber(0, 152);

            printf("Enter the Load First Secret data: ");
            if(menuSelect(ENTRY_MENU,SNum) == MODE_TEXT)
            	len = getData(data,MAX_LEN,MODE_TEXT);
            else
            	len = getData(data,MAX_LEN,MODE_HEX);

            if(!loadFirstSecret(portnum,addr,SNum,&data[0],len))
               OWERROR_DUMP(stderr);
            break;

         case 5:   // Compute Next Secret
            printf("Enter the address for computing next secret: ");
            addr = getNumber(0,128);

            if(!computeNextSecret(portnum,addr,SNum,&data[0]))
               OWERROR_DUMP(stderr);

            printf("The new secret is: ");
            for(i=0;i<8;i++)
               printf("%02X ",data[i]);
            printf("\n");
            break;

         case 6:   // Change Bus Master Secret
            printf("Enter the new Bus Master Secret: ");

            try_again = FALSE;

            do
            {
            	if(menuSelect(ENTRY_MENU,SNum) == MODE_TEXT)
            		len = getData(data,MAX_LEN,MODE_TEXT);
            	else
            		len = getData(data,MAX_LEN,MODE_HEX);

               if(len != 8)
               {
                  printf("The secret is 8 bytes long try again: ");
                  try_again = TRUE;
               }
               else
                  try_again = FALSE;
            }
            while(try_again);

            setBusMasterSecret(&data[0]);
            break;

         case 7:   // Lock Secret
            data[0] = 0xAA;

            if(!bankWriteBlock(3,portnum,SNum,8,data,1))
            {
               OWERROR_DUMP(stderr);
               break;
            }
            break;

         case 8:   // Input new challenge for Read Authenticate
            printf("Enter the New Challenge: ");

            try_again = FALSE;

            do
            {
            	if(menuSelect(ENTRY_MENU,SNum) == MODE_TEXT)
            		len = getData(data,MAX_LEN,MODE_TEXT);
            	else
            		len = getData(data,MAX_LEN,MODE_HEX);

               if(len != 8)
               {
                  printf("The challenge is 8 bytes long try again: ");
                  try_again = TRUE;
               }
               else
                  try_again = FALSE;
            }
            while(try_again);

            setChallenge(&data[0]);
            break;

         case 9:   // Write Protect page 0-3
            data[0] = 0x00;

            if(!bankWriteBlock(3,portnum,SNum,9,data,1))
            {
               OWERROR_DUMP(stderr);
               break;
            }
            break;

         case 10:  // Set Page 1 to EEPROM mode
            data[0] = 0xAA;

            for(i=5;i<8;i++)
               data[i] = 0x00;

            if(!bankWriteBlock(3,portnum,SNum,12,data,1))
            {
            OWERROR_DUMP(stderr);
            break;
            }
            break;

         case 11:  // Write Protect Page 0
            data[0] = 0xAA;

            if(!bankWriteBlock(3,portnum,SNum,13,data,1))
            {
               OWERROR_DUMP(stderr);
               break;
            }
            break;

         case 12:  // Print Current Bus Master Secret
            returnBusMasterSecret(&data[0]);

            printf("The current Bus Master Secret is:  ");
            for(i=0;i<8;i++)
               printf("%02X ",data[i]);
            printf("\n");
            break;

         default:
            done = TRUE;
            break;
      }

      if(!done)
      {
         printf("\n");
         bank = selectBank(bank, SNum);
      }
   }
   while(!done);

   return bank;

}
Exemplo n.º 5
0
int main(int argc, char **argv)
{
   int len, addr, page, answer, i;
   int done      = FALSE;
   SMALLINT  bank = 1;
   uchar     data[552];
   int portnum = 0;
   uchar AllSN[MAXDEVICES][8];
   int NumDevices;
   int owd;
   char msg[132];


      // check for required port name
   if (argc != 2)
   {
      sprintf(msg,"1-Wire Net name required on command line!\n"
                  " (example: \"COM1\" (Win32 DS2480),\"/dev/cua0\" "
                  "(Linux DS2480),\"{1,5}\" (Win32 TMEX)\n");
      printf("%s\n",msg);
      return 0;
   }

   printf("\n1-Wire Memory utility console application Version 0.01\n");

   if((portnum = owAcquireEx(argv[1])) < 0)
   {
      OWERROR_DUMP(stdout);
      return 0;
   }
   else
   {
      // loop to do menu
      do
      {

         // Main menu
         switch (menuSelect(MAIN_MENU,&AllSN[0][0]))
         {

            case MAIN_SELECT_DEVICE :

               // find all parts
               // loop to find all of the devices up to MAXDEVICES
               NumDevices = 0;
               do
               {
                  // perform the search
                  if (!owNext(portnum,TRUE, FALSE))
                     break;

                  owSerialNum(portnum,AllSN[NumDevices], TRUE);
                  NumDevices++;
               }
               while (NumDevices < (MAXDEVICES - 1));

               /* for test devices without a serial number
               if(NumDevices == 0)
               {
                  for(i=0;i<8;i++)
                     AllSN[0][i] = 0x00;
                  NumDevices++;
               }*/

               // select a device
               owd = selectDevice(NumDevices,&AllSN[0]);

               // display device info
               printDeviceInfo(portnum,&AllSN[owd][0]);

               // select a bank
               bank = selectBank(bank, &AllSN[owd][0]);

               if((AllSN[owd][0] == 0x33) || (AllSN[owd][0] == 0xB3))
                  bank = optionSHAEE(bank,portnum,&AllSN[owd][0]);

               // display bank information
               displayBankInformation(bank,portnum,&AllSN[owd][0]);

               // loop on bank menu
               do
               {
                  switch (menuSelect(BANK_MENU,&AllSN[owd][0]))
                  {

                     case BANK_INFO :
                        // display bank information
                        displayBankInformation(bank,portnum,&AllSN[owd][0]);
                        break;

                     case BANK_READ_BLOCK :
                        // read a block
                        printf("Enter the address to start reading: ");
                        addr = getNumber(0, (owGetSize(bank,&AllSN[owd][0])-1));
                        printf("\n");

                        printf("Enter the length of data to read: ");
                        len = getNumber(0, owGetSize(bank, &AllSN[owd][0]));
                        printf("\n");

                        if(!dumpBankBlock(bank,portnum,&AllSN[owd][0],addr,len))
                           OWERROR_DUMP(stderr);
                        break;

                     case BANK_READ_PAGE :
                        printf("Enter the page number to read:  ");

                        page = getNumber(0, (owGetNumberPages(bank,&AllSN[owd][0])-1));

                        printf("\n");

                        if(!dumpBankPage(bank,portnum,&AllSN[owd][0],page))
                           OWERROR_DUMP(stderr);

                        break;

                     case BANK_READ_UDP :
                        printf("Enter the page number to read: ");

                        page = getNumber(0, (owGetNumberPages(bank,&AllSN[owd][0])-1));

                        printf("\n");

                        if(!dumpBankPagePacket(bank,portnum,&AllSN[owd][0],page))
                           OWERROR_DUMP(stderr);
                        break;

                     case BANK_WRITE_BLOCK :
                        // write a block
                        printf("Enter the address to start writing: ");

                        addr = getNumber(0, (owGetSize(bank,&AllSN[owd][0])-1));

            				if(menuSelect(ENTRY_MENU,&AllSN[owd][0]) == MODE_TEXT)
            					len = getData(data,MAX_LEN,MODE_TEXT);
            				else
            					len = getData(data,MAX_LEN,MODE_HEX);

                        if(!bankWriteBlock(bank,portnum,&AllSN[owd][0],addr,data,len))
                        {
                           OWERROR_DUMP(stderr);
                           break;
                        }

                        if(owCanRedirectPage(bank,&AllSN[owd][0]))
                        {
                           printf("Enter if you want to redirect page (0 no, 1 yes): ");

                           answer = getNumber(0,1);

                           if(answer)
                           {
                              printf("What page would you like to redirect:");

                              page = getNumber(0,255);

                              printf("Where would you like to redirect:");

                              addr = getNumber(0,255);

                              if(!redirectPage(bank,portnum,&AllSN[owd][0],page,addr))
                              {
                                 OWERROR_DUMP(stderr);
                                 break;
                              }
                           }
                        }

                        if(owCanLockPage(bank,&AllSN[owd][0]))
                        {
                           printf("Enter if you want to lock page (0 no, 1 yes):");

                           answer = getNumber(0,1);

                           if(answer)
                           {
                              printf("What page would you like to lock?");

                              page = getNumber(0,255);

                              if(!lockPage(bank,portnum,&AllSN[owd][0],page))
                              {
                                 OWERROR_DUMP(stderr);
                                 break;
                              }
                           }
                        }

                        if(owCanLockRedirectPage(bank,&AllSN[owd][0]))
                        {
                           printf("Enter if you want to lock redirected page (0 no, 1 yes):");

                           answer = getNumber(0,1);

                           if(answer)
                           {
                              printf("Which redirected page do you want to lock:");

                              page = getNumber(0,255);

                              if(!lockRedirectPage(bank,portnum,&AllSN[owd][0],page))
                              {
                                 OWERROR_DUMP(stderr);
                                 break;
                              }
                           }
                        }
                        break;

                     case BANK_WRITE_UDP :
                        printf("Enter the page number to write a UDP to: ");

                        page = getNumber(0, (owGetNumberPages(bank,&AllSN[owd][0])-1));

            				if(menuSelect(ENTRY_MENU,&AllSN[owd][0]) == MODE_TEXT)
            					len = getData(data,MAX_LEN,MODE_TEXT);
            				else
            					len = getData(data,MAX_LEN,MODE_HEX);

                        if(!bankWritePacket(bank,portnum,&AllSN[owd][0],page,data,len))
                           OWERROR_DUMP(stderr);
                        break;

                     case BANK_BM_READ_PASS:
                        printf("Enter the 8 byte read only password if less 0x00 will be filled in.");

            				if(menuSelect(ENTRY_MENU,&AllSN[owd][0]) == MODE_TEXT)
            					len = getData(data,8,MODE_TEXT);
            				else
            					len = getData(data,8,MODE_HEX);

                        if(len != 8)
                        {
                           for(i=len;i<8;i++)
                              data[i] = 0x00;
                        }

                        if(!owSetBMReadOnlyPassword(portnum,&AllSN[owd][0],data))
                           OWERROR_DUMP(stderr);

                        break;

                     case BANK_BM_RW_PASS:
                        printf("Enter the 8 byte read/write password if less 0x00 will be filled in.");

            				if(menuSelect(ENTRY_MENU,&AllSN[owd][0]) == MODE_TEXT)
            					len = getData(data,8,MODE_TEXT);
            				else
            					len = getData(data,8,MODE_HEX);

                        if(len != 8)
                        {
                           for(i=len;i<8;i++)
                              data[i] = 0x00;
                        }

                        if(!owSetBMReadWritePassword(portnum,&AllSN[owd][0],data))
                           OWERROR_DUMP(stderr);

                        break;

                     case BANK_READ_PASS:
                        printf("Enter the 8 byte read only password if less 0x00 will be filled in.");

            				if(menuSelect(ENTRY_MENU,&AllSN[owd][0]) == MODE_TEXT)
            					len = getData(data,8,MODE_TEXT);
            				else
            					len = getData(data,8,MODE_HEX);

                        if(len != 8)
                        {
                           for(i=len;i<8;i++)
                              data[i] = 0x00;
                        }

                        if(!owSetReadOnlyPassword(portnum,&AllSN[owd][0],data))
                           OWERROR_DUMP(stderr);

                        break;

                     case BANK_RW_PASS:
                        printf("Enter the 8 byte read/write password if less 0x00 will be filled in.");

            				if(menuSelect(ENTRY_MENU,&AllSN[owd][0]) == MODE_TEXT)
            					len = getData(data,8,MODE_TEXT);
            				else
            					len = getData(data,8,MODE_HEX);

                        if(len != 8)
                        {
                           for(i=len;i<8;i++)
                              data[i] = 0x00;
                        }

                        if(!owSetReadWritePassword(portnum,&AllSN[owd][0],data))
                           OWERROR_DUMP(stderr);

                        break;

                     case BANK_ENABLE_PASS:
                        if(!owSetPasswordMode(portnum,&AllSN[owd][0],ENABLE_PSW))
                           OWERROR_DUMP(stderr);
                        break;

                     case BANK_DISABLE_PASS:
                        if(!owSetPasswordMode(portnum,&AllSN[owd][0],DISABLE_PSW))
                           OWERROR_DUMP(stderr);
                        break;

                     case BANK_NEW_BANK :
                        // select a bank
                        bank = selectBank(bank,&AllSN[owd][0]);

                        if((AllSN[owd][0] == 0x33) || (AllSN[owd][0] == 0xB3))
                           bank = optionSHAEE(bank,portnum,&AllSN[owd][0]);

                        // display bank information
                        displayBankInformation(bank,portnum,&AllSN[owd][0]);
                        break;

                     case BANK_MAIN_MENU :
                        done = TRUE;
                        break;
                  }
               }
               while (!done);

               done = FALSE;
               break;

            case MAIN_QUIT :
               done = TRUE;
               break;

         }  // Main menu switch
      }
      while (!done);  // loop to do menu

      owRelease(portnum);
   }  // else for owAcquire

   return 1;
}
Exemplo n.º 6
0
void LCDST7565::buttonEvent(int buttonIndex, button_event_e event)
{
	pressedButtonIndex = buttonIndex;
	if( event == RELEASE_EVENT )
	{
		pressedButtonIndex = -1;
		//return;
	}
	if(currentMenu == MENU_HOME)
	{
		if(event == PRESS_EVENT)
		{
			switch(buttonIndex)
			{
			case 3:
			{
				menuSelect();
				break;
			}
			case 0:
			{
				midi->setEnabled( ! midi->configuration()->enabled );
				break;
			}
			case 1:
			{
				synth->setEnabled( ! synth->configuration()->enabled );
				break;
			}
			}
		}
	}
	else // We are in a menu or sub menu
	{
		if(event == PRESS_EVENT || event == REPEATED_PRESS_EVENT)
		{
			if(event == PRESS_EVENT)
			{
				valStepFactor = 1;
			}
			else if(valueMenuActive)
			{
				if(++valRepeatedCount >= cSynthVal.incSpeed)
				{
					valRepeatedCount = 0;
					valStepFactor *= 2;
				}
			}
			switch(buttonIndex)
			{
			case BUT_BACK:
			{
				if( event == REPEATED_PRESS_EVENT )
				{
					if( _menu_items[_item_index].type == MENU_ITEM_TYPE_INLINE_INT )
						menuBack();
				}
				else
				{
					menuBack();
				}
				break;
			}
			case BUT_UP:
			{
				if(valueMenuActive)
				{
					valueMenuUp();
				}
				else
				{
					menuUp();
				}
				break;
			}
			case BUT_DOWN:
			{
				if(valueMenuActive)
				{
					valueMenuDown();
				}
				else
				{
					menuDown();
				}
				break;
			}
			case BUT_OK:
			{
				if( event == REPEATED_PRESS_EVENT )
				{
					if( _menu_items[_item_index].type == MENU_ITEM_TYPE_INLINE_INT )
						menuSelect();
				}
				else
				{
					if(valueMenuActive)
					{
						menuBack();
					}
					else
					{
						menuSelect();
					}
				}
				break;
			}
			}
		}
	}
	update();
}
Exemplo n.º 7
0
int WINAPI WinMain  ( HINSTANCE hInstance,  HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow )
{
	CoInitialize(NULL);

	Mycapp.Initilize(hInstance,TEXT("MY"),WndProc);
	hwnd = Mycapp.GetHWND();
	ghInstance = hInstance;

	w.Initialize(Mycapp);

	CInput cinput;
	cinput.Initialize(hInstance,Mycapp.GetHWND());
	pcinput = &cinput;
	RECT _rect ={0,0,640,480};

	PlaySound(TEXT("melody of life.wav"),hInstance,SND_LOOP|SND_FILENAME|SND_ASYNC );

	LeadReader r;
	Attribute attr = r.GetAttr();
	CLead  lead(&w,attr);
	lead.Initialize();

	CWeaponReader cwR;
	CSceneReader cr;
	vector<WeaponInfo> vecWeapon = cwR.GetWeapons();
	CWeapons Weapon(&w);
	Weapon.SetVec(vecWeapon);
	psmanger.SetWeapon(&Weapon);
	psmanger.SetDraw(&w);
	psmanger.SetOverImage(TEXT("gameover.bmp"));

	

	

	CSceneInit csi;
	CScene* pscene = csi.InitScene("4096",&lead,&w,pcinput);
	CScene* pscene2 = csi.InitScene("4097",&lead,&w,pcinput);
	CScene* pscene3 = csi.InitScene("4098",&lead,&w,pcinput);
	CScene* pscene4 = csi.InitScene("4099",&lead,&w,pcinput);
	CScene* pscene5 = csi.InitScene("4100",&lead,&w,pcinput);
	CPathReader cpr;
	psmanger.SetPaths(cpr.GetPaths());

	psmanger.RegisterScene(pscene);
	psmanger.RegisterScene(pscene2);
	psmanger.RegisterScene(pscene3);
	psmanger.RegisterScene(pscene4);
	psmanger.RegisterScene(pscene5);
	CSceneReader sr;
	SceneDesc scenedesc = sr.GetDesc("4097");
	scenedesc.lpImage = NULL;
	scenedesc.pCDraw = &w;
	scenedesc.pcInput = &cinput;	
	scenedesc.lpwFileName = TEXT("4.bmp");
	scenedesc.bIsFightable = true;
	CMyMenu menuRectVictory(TEXT("6.bmp"),pcinput,&w,250,400);
	CMyMenu menuSelect(TEXT("6.bmp"),pcinput,&w,250,200);
	menuSelect.Initialize();
	menuSelect.AddItem(TEXT("Attack!"));
	menuSelect.AddItem(TEXT("使用药水:10个"));
	CMyMenu menuStatus(TEXT("6.bmp"),pcinput,&w,250,200);
	menuStatus.Initialize();
	menuStatus.AddItem(TEXT("主  角 H P:"));
	menuStatus.AddItem(TEXT("主角攻击力:"));
	menuStatus.AddItem(TEXT("主角防御力:"));
	menuRectVictory.Initialize();
	CFightScene csceneFight(scenedesc,&menuRectVictory,&menuSelect,TEXT("bomb.bmp"),&menuStatus);

	CMyMenu menuSelectBuy(TEXT("6.bmp"),pcinput,&w,250,400);
	menuSelectBuy.Initialize();
	cwR.FillItems( vecWeapon,menuSelectBuy);

	CSellScene css(scenedesc,&menuSelectBuy);
	css.Initialize();
	css.SetWeapons(&Weapon);
	css.RegisterLead(&lead);
	
	psmanger.SetSellScene(&css);
	csceneFight.Initialize();
	psmanger.SetFightScene(&csceneFight);
	

#ifndef WINDOW_DEBUG
	psmanger.Draw();

#else
		psmanger.Draw(Mycapp.GetHWND());

#endif
	MSG  msg;	
	msg.message = WM_NULL;
	for(;;)
	{	if(PeekMessage(&msg,NULL,NULL,NULL,PM_REMOVE))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);		
	}
	if(msg.message == WM_QUIT) break;
	else
	{


#ifndef WINDOW_DEBUG
			psmanger.Draw();
#else
			psmanger.Draw(Mycapp.GetHWND());
#endif
	
	}
	}
	
	CoUninitialize();
	return msg.message;

}