 // bits 1 and 2 (0x02, 0x04) not connected
 
 // SALT2 yellow LED for J2,3,4 intended to show activity on that port: 9557 IO0, 0x01 
-// open drain, clearing this bit drives output low = LED on
+// open drain, SETTING (yes, opposite to the other bits) this bit drives output low = LED on
 #define LED BIT0	// 0x01
+
+// coreFET defines: TODO: move to appropriate .h file
+// LED on bit 0 uses the LED define above
+#define	LIGHTS		BIT2		// when set HIGH, turns on the habitats' fluorescent lights
+#define	ALARM		BIT3		// when set HIGH, sounds the alarm at the top of the A habitat
+#define	FAN3		BIT5		// when set HIGH, turns on the left-most fan
+#define	FAN2		BIT6		// when set HIGH, turns on the middle fan
+#define	FAN1		BIT7		// when set HIGH, turns on the right-most fan
+
 
 /**
  *  bit 5 is input; bits 2 and 1 are not connected, Bit 0 is the activity LED for that device
  *  so this mask has a '1' for every bit which is used as output
  *  Note: enclosing parentheses are required to force the '~' operator to operate on the whole quantity
- *  not just the first manifest constant!
+ *  not just the first manifest constant! TODO: move to common .h file
  */
 #define OUTMASK (RCLK595 | SCLK | SDOUT | SHIFT165 | LED)
 
 /**
- *  Only one actual input, serial data in
+ *  Only one actual input, serial data in; TODO: move to common .h file
  */
 #define INMASK (SDIN)
 
-Systronix_PCA9557 coreJ2(I2C_J2);
-Systronix_PCA9557 coreJ3(I2C_J3);
-Systronix_PCA9557 coreJ4(I2C_J4);
+SALT_JX coreJ2 (2);
+//SALT_JX coreJ3 (3);
+//SALT_JX coreJ4 (4);
+
+Systronix_PCA9557 coreJ2reg(I2C_J2);
+Systronix_PCA9557 coreJ3reg(I2C_J3);
+Systronix_PCA9557 coreJ4reg(I2C_J4);
 
 Systronix_PCA9557 coreFET(I2C_FET);
 
+// TODO: move to common .h file as #defines;
 uint8_t periph_rst = 22;	// peripheral reset asserted LOW to PCA9557, etc on board
 uint8_t ether_rst = 8;		// Wiznet module reset LOW
 
-/* ========== SETUP ========== */
+struct J_data
+	{
+	uint32_t	DC_data_in;			// data read from the DC board '165 shift register
+	uint16_t	AC_data_out;		// data sent to the AC board; send this before sending DC
+	uint16_t	DC_data_out;		// data sent to the DC board
+	} J2_data , J3_data, J4_data;
+
+	
+//---------------------------< S E T U P >--------------------------------------------------------------------
+
 void setup(void) 
-{
+	{
   	pinMode(periph_rst, OUTPUT);     
 	pinMode (ether_rst, OUTPUT);
 	

	digitalWrite(ether_rst, HIGH);

	Serial.print("SALT2 J2 I2C Register Test Code at 0x");
	Serial.println(coreJ2.BaseAddr, HEX);

	/**
	 *  Serial1 is a proprietary LCD and cap touch keypad
	 */
	// Serial1.begin(9600);			// UI Side 0 = LCD and keypad
	// while((!Serial1) && (millis()<10000));		// wait until serial port is open or timeout
	
	// delay(2000);
	//                0123456789ABCDEF 
	// Serial1.println("dSALT J2 I2C Test");

	/**
	* Start, now inits invert and output bit enable, clears outputs
	*/
	coreJ2.begin();
	coreJ3.begin();
	coreJ4.begin();
	coreFET.begin();
	
	// outmask, outdata, inputinvert
	coreJ2.init(OUTMASK, (SCLK | RCLK595 | LED), 0);
	coreJ3.init(OUTMASK, (SCLK | RCLK595 | LED), 0);
	coreJ4.init(OUTMASK, (SCLK | RCLK595 | LED), 0);
	// FETs don't have clocks to downstream devices
	// set all as outputs, all outputs off/low, no input inversion (none are inputs anyway)
	coreFET.init(0xFF, 0x00, 0x00);

	Serial.print(" Interval is ");
	Serial.print(dtime/1000);
	Serial.print(" sec, ");

	Serial.println("Setup Complete!");
	Serial.println(" "); 
  
}



/* ========== LOOP ========== */
void loop(void) 
{
	uint8_t read1=0;

	Serial.print("@");
	Serial.print(millis()/1000);
	Serial.println(" ");
	
	for (uint8_t i = 0; i<4; i++) {
		coreJ2.control_write(i);
		Serial.print("At reg 0x");
		Serial.print(i, HEX);
		read1 = coreJ2.default_read();
		Serial.print(" rd 0x");
		Serial.println(read1, HEX);
	}

	Serial.print("OUTMASK=0x");
	Serial.println(OUTMASK, HEX);
	
	read1 = coreJ2.output_read();
	Serial.print("Output read=0x");
	Serial.println(read1, HEX);
	
	read1 = coreJ2.input_read();
	Serial.print("Input=0x");
	Serial.println(read1, HEX);
	
	coreJ2.pin_drive (LED, false);
	// coreFET.pin_drive (LED, false);
	coreFET.pin_drive ((0x80 | LED), false);
	delay(1000);
	
	coreFET.pin_drive ((0x80 | LED), true);
	coreJ2.pin_drive (LED, true);
	// coreFET.pin_drive (LED, true);
	delay(1000);
	
	
}
 *  2016 May 26 bboyes moved into Systronix_PCA9557 examples folder
 *				Changed name to PCA9557_J2
 *  2016 May 15 bboyes Start with new SALT 2v0 board
 *	2016 Jul 4	wsk		complete thrash of this example used as a test bed for SALT_JX class
 */


#include <Arduino.h>
#include <Systronix_PCA9557.h>
#include <SALT_JX.h>
#include <NAP_pod_load_defs.h>

/**
 * These are the addresses of the I2C devices which drive the related
 * Core DB15 connector and the Core FETs
 * @TODO make these addresses manifest constants in some appropriate way; put them in a common .h file somewhere if they are needed in more than one file
 */
#define I2C_J2 0x1B
#define I2C_J3 0x1A
#define I2C_J4 0x19
#define I2C_FET 0x1C

// TODO: move to common .h file
#define JX_LED_ON	false		// yes, opposite to the other bits.  writing a 1 to the 9557 output register
#define JX_LED_OFF	true		// turns the output FET OFF


/**
 *  These are signal names specific to our custom SALT2 hardware; TODO: move to common .h file
 */

// SALT2 Core SDOUT on J2,3,4 pins 1/2 to '595 SDIN of DC and AC boards: 9557 IO7, 0x80 
// output from 9557 to '595 Din
#define SDOUT BIT7 	// 0x80

// SALT2 Core SCLK on J2,3,4 pins 5/6 to '595 and '165 SCLK of DC and AC boards: 9557 IO6, 0x40,
