EEPROM STORAGE CODE HELP Please

In the interest of learning, i am trying to put another switch that works of the lcd EDIT menu with a button press with the 2 existing switches.
I copied all the entry's in the sketch of switch 1 and changed them to switch 3, in order to make the switch state on or off for switch 3 it needs to work independently.

// Memory stucture:
// byte 0 -> init marker
// byte 1 -> midi channel
// byte 2 -> maximum bank
// byte 4/5 -> PDL1 min
// byte 6/7 -> PDL1 max
// byte 8/9 -> PDL2 min
// byte 10/11 -> PDL2 max
// byte 12 -> Performance mode
// from byte 16 and further
// Each patch, 16 bytes long:
// 0 : ProgChangeNo
// 1 : S1 CC
// 2 : S2 CC
// 3 : S1/S2 state and vol->wah (bitwise)
// 4..15: 12-character name
// 16 : S3 CC
// 17 : S3 State
// 

#include "Storage.h"
#include "constants.h"

void StorageClass::init()
{
  if (EEPROM.read(0) != 127)
  {
    EEPROM.write(0,127);
   // for (int i = 0; i < 4024; i++)
    // EEPROM.write(i, 0);

    writeChannel(1);
    writeMaxBank(12);

    writePatchName(0, "JMP1");
    writePatchName(1, "CleanChorus");
    writePatchName(2, "Clean");
    writePatchName(3, "Lead");
    writePatchName(4, "JMP1");
    writePatchName(5, "CleanCh");
    writePatchName(6, "Cry");
    writePatchName(7, "Luke");
    writePatchName(8, "JMP1!");
    writePatchName(9, "Clubclean");
    writePatchName(10, "Country");
    writePatchName(11, "CountryTS");

	for (int i = 0; i < 63; i++)
	{
		writeS1CC(i, 80);
		writeS2CC(i, 82);
                writeS3CC(i, 83);
	}	
	for (int i = 0; i < 4; i++)
	{
		writeS1State(i, true);
	
	writeS2W2VState(6, true);

    writeS3State(2, true);
} 
  }
}

int StorageClass::Offset(int patchno)
{
  return (patchno * 16) + 16;
}

byte StorageClass::readChannel()
{
  EEPROM.read(1);
}
void StorageClass::writeChannel(byte channel)
{
  EEPROM.write(1, channel);
}
byte StorageClass::readMaxBank()
{
  EEPROM.read(2);
}
void StorageClass::writeMaxBank(byte maxbank)
{
  // 63 programs max
  maxbank = min(byte(63 / banksize), maxbank);
  EEPROM.write(2, maxbank);
}
String StorageClass::readPatchName(int patchno)
{
  // start in EEPROM from position 16, max = 1007 => 63 patches max!
  // Each patch, 16 bytes long:
  // 0 : ProgChangeNo (not used)
  // 1 : S1 CC
  // 2 : S2 CC
  // 3 : S1/S2 state and vol->wah (bitwise)
  // 4..15: 12-character name
  char buf[13];
  for (int i = 0; i < 12; i++)
	  buf[i] = EEPROM.read(Offset(patchno) + i + 4);
  buf[12] = 0;

  return String(buf);
}
void StorageClass::writePatchName(int patchno, char *patchname)
{
  int len = strlen(patchname);
  for (int i = 0; i < 12; i++)
  {  
    if (i < len)
		EEPROM.write(Offset(patchno) + i + 4, patchname[i]);
    else
		EEPROM.write(Offset(patchno) + i + 4, ' ');
  }
}

byte StorageClass::readS1CC(int patchno)
{
	return EEPROM.read(Offset(patchno) + 1);
}
void StorageClass::writeS1CC(int patchno, byte CC)
{
	EEPROM.write(Offset(patchno) + 1, CC);
}
  byte StorageClass::readS2CC(int patchno)
{
	return EEPROM.read(Offset(patchno) + 2);
}
void StorageClass::writeS2CC(int patchno, byte CC)
{
	EEPROM.write(Offset(patchno) + 2, CC);
}
byte StorageClass::readS3CC(int patchno)
{
	return EEPROM.read(Offset(patchno) + 17);
}
void StorageClass::writeS3CC(int patchno, byte CC)
{
	EEPROM.write(Offset(patchno) + 17, CC);
}
bool StorageClass::readS1State(int patchno)
{
	// 3 : S1/S2 state and vol->wah (bitwise)
	return (EEPROM.read(Offset(patchno) + 3) & 0x1) == 0x1;
}
void StorageClass::writeS1State(int patchno, bool state)
{
	byte bit_fld = EEPROM.read(Offset(patchno) + 3);
  	if (state)
		bit_fld |= 1 << 0;
	else
		bit_fld &= ~(1 << 0);
	EEPROM.write(Offset(patchno) + 3, bit_fld);
}
bool StorageClass::readS2State(int patchno)
{
	return (EEPROM.read(Offset(patchno) + 3) & 0x2) == 0x2;
}
void StorageClass::writeS2State(int patchno, bool state)
{
	byte bit_fld = EEPROM.read(Offset(patchno) + 3);
	if (state)
		bit_fld |= 1 << 1;
	else
		bit_fld &= ~(1 << 1);
	EEPROM.write(Offset(patchno) + 3, bit_fld);
}
  bool StorageClass::readS2W2VState(int patchno)
{
	return (EEPROM.read(Offset(patchno) + 3) & 0x4) == 0x4;
}
void StorageClass::writeS2W2VState(int patchno, bool state)
{
	byte bit_fld = EEPROM.read(Offset(patchno) + 3);
	if (state)
		bit_fld |= 1 << 2;
	else
		bit_fld &= ~(1 << 2);
	EEPROM.write(Offset(patchno) + 3, bit_fld);
}

void StorageClass::writePDL1Min(int Value)
{
    EEPROM.write(4,highByte(Value));
    EEPROM.write(5,lowByte(Value));
}

int StorageClass::readPDL1Min()
{
    return word(EEPROM.read(4),EEPROM.read(5));
}

void StorageClass::writePDL1Max(int Value)
{
    EEPROM.write(6,highByte(Value));
    EEPROM.write(7,lowByte(Value));
}

int StorageClass::readPDL1Max()
{
    return word(EEPROM.read(6),EEPROM.read(7));
}

  void StorageClass::writePDL2Min(int Value)
{
    EEPROM.write(8,highByte(Value));
    EEPROM.write(9,lowByte(Value));
}

int StorageClass::readPDL2Min()
{
    return word(EEPROM.read(8),EEPROM.read(9));
}

void StorageClass::writePDL2Max(int Value)
{
    EEPROM.write(10,highByte(Value));
    EEPROM.write(11,lowByte(Value));
}

int StorageClass::readPDL2Max()
{
    return word(EEPROM.read(10),EEPROM.read(11));
}

byte StorageClass::readPrgChg(int patchno)
{
  // start in EEPROM from position 16, max = 1007 => 63 patches max!
  // Each patch, 16 bytes long:
  // 0 : ProgChangeNo (not used)
  // 1 : S1 CC
  // 2 : S2 CC
  // 3 : S1/S2 state and vol->wah (bitwise)
  // 4..15: 12-character name
  return EEPROM.read(Offset(patchno));
}
void StorageClass::writePrgChg(int patchno, byte PrgChg)
{
    EEPROM.write(Offset(patchno), PrgChg);
}

void StorageClass::ResetProgramMap()
{
    for(int i = 0; i < 63; i++)
      writePrgChg(i, i);
}

void StorageClass::writePerfMode(boolean Value)
{
    EEPROM.write(12,Value ? 1 : 0);
}

boolean StorageClass::readPerfMode()
{
    return EEPROM.read(12) == 1;
}



bool StorageClass::readS3State(int patchno)
{
	// 3 : S1/S2 state and vol->wah (bitwise)
	return (EEPROM.read(Offset(patchno) + 17) & 0x1) == 0x1;
}
void StorageClass::writeS3State(int patchno, bool state)
{
	byte bit_fld = EEPROM.read(Offset(patchno) + 17);
  	if (state)
		bit_fld |= 1 << 1;
	else
		bit_fld &= ~(1 << 1);
	EEPROM.write(Offset(patchno) + 17, bit_fld);
}

I have narrowed the code down to the section (bool StorageClass::readS3State(int patchno))
the section with the bit_fld toggles the on and off( i think) ANY HELP HERE WOULD BE GREAT. But i dont know what the (return (EEPROM.read(Offset(patchno) + 3) & 0x1) == 0x1) is and how it works.

Would someone be kind enough to explain this, and what the new entry's for the switch should be.

i have tried changing the entry's to see how they work.but cant get it working.

Thanks

return (EEPROM.read(Offset(patchno) + 3) & 0x1) == 0x1

returns 1 (true) if the lowest bit of the data in EEPROM at address returned by Offset(patchno)+3 (ie, this is the third byte after that offset we're talking about, which the Offset() function figures out from patchno) is a 1, otherwise return 0 (false).

Oddly written - I'd have just done

return (EEPROM.read(Offset(patchno) + 3) & 1)

& is bitwise and (look up the operators in reference) - so he's reading that byte from EEPROM, and using the bitwise and to "mask off" all except the low bit - which presumably contains the information needed there.

As for the restof your post, I have no idea what you're asking or what you're having trouble with. But I know what that line of code means.

Thanks for that.

a few questions

would return (EEPROM.read(Offset(patchno) + 3) & 0x2) == 0x2

be the same as
return (EEPROM.read(Offset(patchno) + 3) & 2)

and how does this work with the rest of the statement?

bool StorageClass::readS3State(int patchno)
{
	// 3 : S1/S2 state and vol->wah (bitwise)
	return (EEPROM.read(Offset(patchno) + 3) & 0x1) == 0x1;
}
[color=red]void StorageClass::writeS3State(int patchno, bool state)
{
	byte bit_fld = EEPROM.read(Offset(patchno) + 3);
  	if (state)
		bit_fld |= 1 << 0;
	else
		bit_fld &= ~(1 << 0);
	EEPROM.write(Offset(patchno) + 3, bit_fld);

[/color]

This section is part of a switch that the user can select through a edit menu in the lcd which stores the on or off state in the eeprom.

Can any one explain this part of the code

void StorageClass::writeS1State(int patchno, bool state)
{
	byte bit_fld = EEPROM.read(Offset(patchno) + 3);
  	if (state)
		bit_fld |= 1 << 0;
	else
		bit_fld &= ~(1 << 0);
	EEPROM.write(Offset(patchno) + 3, bit_fld);

Thanks

G