Esempio n. 1
0
int main (int argc, char *argv[]) {
	// Bind the clean-up function to program exit
	atexit(dbmsg_disconnect);


///////////////////////////////////////////////////////////////////////////////
	if (argc < 2) {
		// Initialize the controller
		init_local();
		// Determine heater posture based on current readings
		comp_temps();
		
///////////////////////////////////////////////////////////////////////////////
	} else {
		// Initialize the web controller
		init_web();
		// One time variables
		devStat state;
		int pin = 5;
		// Parse the input parameters
		while ((argc > 1) && (argv[1][0] == '-')) {
			switch (argv[1][1]) {
			case 'h':		// Heater
				pin = (int)argv[1][2] - '1';
				break;
			case 'f':		// Fan
				pin = 4;
				break;
			case 'r':		// Run
				state = ON;
				break;
			case 's':		// Stop
				state = OFF;
				break;
			case 'a':		// All on
				allON();
				return 0;
			case 'x':		// All stop
				allOFF();
				return 0;
			case 't':
				desired_product_temp = get_desired_temp();
				return 0;
			default:
				printf("Invalid parameters\n");
				display_help();
				return 0;
			}
			++argv;
			--argc;
		}
		if (state == OFF) {
			turnOFF(heats[pin]);
		} else {
			turnON(heats[pin]);
		}
	}

	return 0;
}
Esempio n. 2
0
void comp_temps() {
	// If the product temperature is below the threshold, stop pumping heat
	if (temps[0] <= desired_product_temp) {
		printf("COLD!\n");
		// Set the outputs to the heatpump relays to open
		allOFF();
		// Keep the fans running
		turnON(FANS);
	} else {
		printf("WARM!\n");
		// Cycle through the heatpumps
		int i;
		for (i = 1; i < 5; ++i)
		{
			// If the pump is too hot, turn it off, start cooldown
			if (temps[i] >= PUMPHT) {
				turnOFF(heats[i-1]);
			} else {
				// Otherwise turn the pump on
				printf("%d:%f\n",i,temps[i]);
				turnON(heats[i-1]);
			}
		}
	}

}
Esempio n. 3
0
void fetchCycle(){
    if(isON(FETCH_FLAG)){
        fetch();
    if(isOFF(JMPR_FLAG)){
            decodeL();
            turnOFF(FETCH_FLAG);
        }else{
            decodeR(MBR);
            turnOFF(JMPR_FLAG);
        }       
    }else{
        decodeR(IBR);
        turnON(FETCH_FLAG);        
    }

}
Esempio n. 4
0
void allOFF() {
	// Turn each pin OFF
	int i;
	for (i = 0; i < 5; i++) {
		turnOFF(heats[i]);
	}

	return;
}
Esempio n. 5
0
void getOperands(uint64_t mar){
    if(isON(READMEM_FLAG)){  
        setReg(MBR,readMEM(mar));
        turnOFF(READMEM_FLAG);
    }        
}
Esempio n. 6
0
void saveResults(uint64_t mar, uint64_t mbr, uint64_t mask){
    if(isON(WRITEMEM_FLAG)){
        writeMEM(mar,mbr,mask);
        turnOFF(WRITEMEM_FLAG);
    }   
}