int main(void){
	// The following four lines are due to my laziness about breadboard.
	SET_OUTPUT(DDRD,3); // +5v
	SET_HIGH(PORTD,3);  // +5V
	SET_OUTPUT(DDRD,4); // GND
	SET_LOW(PORTD,4);   // GND

	// Initial values of channels.
	channels[0]=25;
	channels[1]=75;
	channels[2]=125;
	channels[3]=175;
	channels[4]=225;

	// Set to taste. Start with 0 initially.
	pulse_fine_tune=30;

	// Start.
	init_transmission();
	while(1){
		// Changing channels
		channels[0]++;
		_delay_ms(100);
	}

	return 0;
}
Esempio n. 2
0
/******* EXT IO ***********************/
void ZeroPi::extInit(int index, int type){
	if(EXT_INPUT == type){
		SET_INPUT(extios[index].pin);
		extios[index].function = EXT_INPUT;
	}else if(EXT_OUTPUT == type){
		SET_OUTPUT(extios[index].pin);
		extios[index].function = EXT_OUTPUT;
	}else if(EXT_SERVO== type){
		SET_OUTPUT(extios[index].pin);
		extios[index].function = EXT_SERVO;
	}
}
Esempio n. 3
0
void HAL::spiBegin()
{
#if MOTHERBOARD == 500 || MOTHERBOARD == 501
  if (spiInitMaded == false)
  {
#endif        // Configre SPI pins
    PIO_Configure(
      g_APinDescription[SCK_PIN].pPort,
      g_APinDescription[SCK_PIN].ulPinType,
      g_APinDescription[SCK_PIN].ulPin,
      g_APinDescription[SCK_PIN].ulPinConfiguration);
    PIO_Configure(
      g_APinDescription[MOSI_PIN].pPort,
      g_APinDescription[MOSI_PIN].ulPinType,
      g_APinDescription[MOSI_PIN].ulPin,
      g_APinDescription[MOSI_PIN].ulPinConfiguration);
    PIO_Configure(
      g_APinDescription[MISO_PIN].pPort,
      g_APinDescription[MISO_PIN].ulPinType,
      g_APinDescription[MISO_PIN].ulPin,
      g_APinDescription[MISO_PIN].ulPinConfiguration);

    // set master mode, peripheral select, fault detection
    SPI_Configure(SPI0, ID_SPI0, SPI_MR_MSTR |
                  SPI_MR_MODFDIS | SPI_MR_PS);
    SPI_Enable(SPI0);
#if MOTHERBOARD == 500 || MOTHERBOARD == 501
    SET_OUTPUT(DAC0_SYNC);
#if NUM_EXTRUDER > 1
    SET_OUTPUT(DAC1_SYNC);
    WRITE(DAC1_SYNC, HIGH);
#endif
    SET_OUTPUT(SPI_EEPROM1_CS);
    SET_OUTPUT(SPI_EEPROM2_CS);
    SET_OUTPUT(SPI_FLASH_CS);
    WRITE(DAC0_SYNC, HIGH);
    WRITE(SPI_EEPROM1_CS, HIGH );
    WRITE(SPI_EEPROM2_CS, HIGH );
    WRITE(SPI_FLASH_CS, HIGH );
    WRITE(SDSS , HIGH );
#endif// MOTHERBOARD == 500 || MOTHERBOARD == 501
    PIO_Configure(
      g_APinDescription[SPI_PIN].pPort,
      g_APinDescription[SPI_PIN].ulPinType,
      g_APinDescription[SPI_PIN].ulPin,
      g_APinDescription[SPI_PIN].ulPinConfiguration);
    spiInit(1);
#if (MOTHERBOARD==500) || (MOTHERBOARD==501)
    spiInitMaded = true;
  }
#endif
}
Esempio n. 4
0
// ----------------------------------------------------------------------------
void mcp2515_spi_init(void)
{
	// Aktivieren der Pins fuer das SPI Interface
	SET(MCP2515_CS);
	SET_OUTPUT(MCP2515_CS);
	
	// Aktivieren der Pins fuer das SPI Interface
	RESET(P_SCK);
	RESET(P_MOSI);
	RESET(P_MISO);
	SET_OUTPUT(P_SCK);
	SET_OUTPUT(P_MOSI);
	SET_INPUT(P_MISO);
}
Esempio n. 5
0
void setup_powerhold()
{
  #if defined(SUICIDE_PIN) && SUICIDE_PIN > -1
    SET_OUTPUT(SUICIDE_PIN);
    WRITE(SUICIDE_PIN, HIGH);
  #endif
  #if defined(PS_ON_PIN) && PS_ON_PIN > -1
    SET_OUTPUT(PS_ON_PIN);
	#if defined(PS_DEFAULT_OFF)
	  WRITE(PS_ON_PIN, PS_ON_ASLEEP);
    #else
	  WRITE(PS_ON_PIN, PS_ON_AWAKE);
	#endif
  #endif
}
Esempio n. 6
0
void MD_TCS230::begin()
{
#define	SET_OUTPUT(x)	if (x!=NO_PIN) pinMode(x,OUTPUT)

	SET_OUTPUT(_S0);
	SET_OUTPUT(_S1);
	SET_OUTPUT(_S2);
	SET_OUTPUT(_S3);
	SET_OUTPUT(_OE);

	setEnable(false);
	setFrequency2(_freqSet);

#undef SET_OUTPUT
	DUMPS("\nLibrary begin initialised");
}
Esempio n. 7
0
void buzz(long duration, uint16_t freq) {
  if (freq > 0) {
#if ENABLED(LCD_USE_I2C_BUZZER)
    lcd_buzz(duration, freq);
#elif PIN_EXISTS(BEEPER) // on-board buzzers have no further condition
    SET_OUTPUT(BEEPER_PIN);
#if ENABLED(SPEAKER) // a speaker needs a AC ore a pulsed DC
    //tone(BEEPER_PIN, freq, duration); // needs a PWMable pin
    unsigned int delay = 1000000 / freq / 2;
    int i = duration * freq / 1000;
    while (i--) {
      WRITE(BEEPER_PIN, HIGH);
      delayMicroseconds(delay);
      WRITE(BEEPER_PIN, LOW);
      delayMicroseconds(delay);
    }
#else // buzzer has its own resonator - needs a DC
    WRITE(BEEPER_PIN, HIGH);
    delay(duration);
    WRITE(BEEPER_PIN, LOW);
#endif
#else
    delay(duration);
#endif
  } else
    delay(duration);
}
Esempio n. 8
0
void suicide()
{
  #if defined(SUICIDE_PIN) && SUICIDE_PIN > -1
    SET_OUTPUT(SUICIDE_PIN);
    WRITE(SUICIDE_PIN, LOW);
  #endif
}
Esempio n. 9
0
void setup_photpin()
{
  #if defined(PHOTOGRAPH_PIN) && PHOTOGRAPH_PIN > -1
    SET_OUTPUT(PHOTOGRAPH_PIN);
    WRITE(PHOTOGRAPH_PIN, LOW);
  #endif
}
Esempio n. 10
0
void Space::load_motor(int m, int32_t &addr) { // {{{
	loaddebug("loading motor %d", m);
	uint16_t enable = motor[m]->enable_pin.write();
	double old_home_pos = motor[m]->home_pos;
	double old_steps_per_unit = motor[m]->steps_per_unit;
	motor[m]->step_pin.read(read_16(addr));
	motor[m]->dir_pin.read(read_16(addr));
	motor[m]->enable_pin.read(read_16(addr));
	motor[m]->limit_min_pin.read(read_16(addr));
	motor[m]->limit_max_pin.read(read_16(addr));
	motor[m]->steps_per_unit = read_float(addr);
	motor[m]->home_pos = read_float(addr);
	motor[m]->limit_v = read_float(addr);
	motor[m]->limit_a = read_float(addr);
	motor[m]->home_order = read_8(addr);
	arch_motors_change();
	SET_OUTPUT(motor[m]->enable_pin);
	if (enable != motor[m]->enable_pin.write()) {
		if (motors_busy)
			SET(motor[m]->enable_pin);
		else {
			RESET(motor[m]->enable_pin);
		}
	}
	RESET(motor[m]->step_pin);
	SET_INPUT(motor[m]->limit_min_pin);
	SET_INPUT(motor[m]->limit_max_pin);
	bool must_move = false;
	if (!isnan(motor[m]->home_pos)) {
		// Axes with a limit switch.
		if (motors_busy && (old_home_pos != motor[m]->home_pos || old_steps_per_unit != motor[m]->steps_per_unit) && !isnan(old_home_pos)) {
			double ohp = old_home_pos * old_steps_per_unit;
			double hp = motor[m]->home_pos * motor[m]->steps_per_unit;
			double diff = hp - ohp;
			motor[m]->settings.current_pos += diff;
			//debug("load motor %d %d new home %f add %f", id, m, motor[m]->home_pos, diff);
			arch_addpos(id, m, diff);
			must_move = true;
		}
	}
	else {
		// Axes without a limit switch, including extruders.
		if (motors_busy && old_steps_per_unit != motor[m]->steps_per_unit) {
			debug("load motor %d %d new steps no home", id, m);
			double oldpos = motor[m]->settings.current_pos;
			double pos = oldpos / old_steps_per_unit;
			motor[m]->settings.current_pos = pos * motor[m]->steps_per_unit;
			arch_addpos(id, m, motor[m]->settings.current_pos - oldpos);
			// Adjust current_pos in all history.
			for (int h = 0; h < FRAGMENTS_PER_BUFFER; ++h) {
				oldpos = motor[m]->history[h].current_pos;
				pos = oldpos / old_steps_per_unit;
				motor[m]->history[h].current_pos = pos * motor[m]->steps_per_unit;
			}
		}
	}
	if (must_move)
		move_to_current();
} // }}}
Esempio n. 11
0
/******* DC MOTORS *******************/ 
void ZeroPi::motorInit(int slot){
	int n;
	for(n=0;n<SLOT_NUM_PINS;n++){
		SET_OUTPUT(slots[slot].pin[n]);
	}

	slots[slot].function = SLOT_MOTOR;
}
Esempio n. 12
0
/******* STEPPERS *******************/ 
void ZeroPi::stepperInit(int slot){
	int n;
	for(n=0;n<SLOT_NUM_PINS;n++){
		SET_OUTPUT(slots[slot].pin[n]);
	}
	stepperEnable(slot,0);
	slots[slot].function = SLOT_STEPPER;
}
Esempio n. 13
0
bool sja1000_init(uint8_t bitrate)
{
	if (bitrate >= 8)
		return false;

	#if !SJA1000_MEMORY_MAPPED
		SET(SJA1000_WR);
		SET(SJA1000_RD);
		RESET(SJA1000_ALE);
		RESET(SJA1000_CS);

		SET_OUTPUT(SJA1000_WR);
		SET_OUTPUT(SJA1000_RD);
		SET_OUTPUT(SJA1000_ALE);

		SET_OUTPUT(SJA1000_CS);
		DDR(SJA1000_DATA) = 0xff;
	#endif

	// enter reset mode
	sja1000_write(MOD, (1<<RM)|(1<<AFM));

	// choose PeliCAN-Mode
	sja1000_write(CDR, (1<<CANMODE) | SJA1000_CLOCK_REGISTER);

	// select the bitrate configuration
	sja1000_write(BTR0, pgm_read_byte(&_sja1000_cnf[bitrate][0]));
	sja1000_write(BTR1, pgm_read_byte(&_sja1000_cnf[bitrate][1]));

	// filter are not practical useable, so we disable them
	sja1000_write(AMR0, 0xff);
	sja1000_write(AMR1, 0xff);
	sja1000_write(AMR2, 0xff);
	sja1000_write(AMR3, 0xff);

	// set output driver configuration
	sja1000_write(OCR, (1<<OCTP0)|(1<<OCTN0)|(1<<OCMODE1));

	// enable receive interrupt
	sja1000_write(IER, (1<<RIE));

	// leave reset-mode
	sja1000_write(MOD, (1<<AFM));

	return true;
}
Esempio n. 14
0
/**
 * @brief  Begin SPI port setup
 *
 * @return Nothing
 *
 * @details Only configures SS pin since stm32duino creates and initialize the SPI object
 */
void spiBegin(void) {
  #if !PIN_EXISTS(SS)
    #error "SS_PIN not defined!"
  #endif

  SET_OUTPUT(SS_PIN);
  WRITE(SS_PIN, HIGH);
}
Esempio n. 15
0
void Space::load_motor(uint8_t m, int32_t &addr) { // {{{
	loaddebug("loading motor %d", m);
	uint16_t enable = motor[m]->enable_pin.write();
	double old_home_pos = motor[m]->home_pos;
	double old_steps_per_unit = motor[m]->steps_per_unit;
	motor[m]->step_pin.read(read_16(addr));
	motor[m]->dir_pin.read(read_16(addr));
	motor[m]->enable_pin.read(read_16(addr));
	motor[m]->limit_min_pin.read(read_16(addr));
	motor[m]->limit_max_pin.read(read_16(addr));
	motor[m]->sense_pin.read(read_16(addr));
	motor[m]->steps_per_unit = read_float(addr);
	motor[m]->max_steps = read_8(addr);
	motor[m]->home_pos = read_float(addr);
	motor[m]->limit_v = read_float(addr);
	motor[m]->limit_a = read_float(addr);
	motor[m]->home_order = read_8(addr);
	arch_motors_change();
	SET_OUTPUT(motor[m]->enable_pin);
	if (enable != motor[m]->enable_pin.write()) {
		if (motors_busy)
			SET(motor[m]->enable_pin);
		else {
			RESET(motor[m]->enable_pin);
		}
	}
	RESET(motor[m]->step_pin);
	SET_INPUT(motor[m]->limit_min_pin);
	SET_INPUT(motor[m]->limit_max_pin);
	SET_INPUT(motor[m]->sense_pin);
	bool must_move = false;
	if (!isnan(motor[m]->home_pos)) {
		// Axes with a limit switch.
		if (motors_busy && (old_home_pos != motor[m]->home_pos || old_steps_per_unit != motor[m]->steps_per_unit) && !isnan(old_home_pos)) {
			int32_t hp = motor[m]->home_pos * motor[m]->steps_per_unit + (motor[m]->home_pos > 0 ? .49 : -.49);
			int32_t ohp = old_home_pos * old_steps_per_unit + (old_home_pos > 0 ? .49 : -.49);
			int32_t diff = hp - ohp;
			motor[m]->settings.current_pos += diff;
			cpdebug(id, m, "load motor new home add %d", diff);
			arch_addpos(id, m, diff);
			must_move = true;
		}
	}
	else {
		// Axes without a limit switch, including extruders.
		if (motors_busy && old_steps_per_unit != motor[m]->steps_per_unit) {
			int32_t cp = motor[m]->settings.current_pos;
			double pos = cp / old_steps_per_unit;
			cpdebug(id, m, "load motor new steps no home");
			motor[m]->settings.current_pos = pos * motor[m]->steps_per_unit;
			int diff = motor[m]->settings.current_pos - cp;
			arch_addpos(id, m, diff);
		}
	}
	if (must_move)
		move_to_current();
} // }}}
Esempio n. 16
0
void Space::load_motor(int m) { // {{{
	loaddebug("loading motor %d", m);
	uint16_t enable = motor[m]->enable_pin.write();
	double old_home_pos = motor[m]->home_pos;
	double old_steps_per_unit = motor[m]->steps_per_unit;
	bool old_dir_invert = motor[m]->dir_pin.inverted();
	motor[m]->step_pin.read(shmem->ints[2]);
	motor[m]->dir_pin.read(shmem->ints[3]);
	motor[m]->enable_pin.read(shmem->ints[4]);
	motor[m]->limit_min_pin.read(shmem->ints[5]);
	motor[m]->limit_max_pin.read(shmem->ints[6]);
	motor[m]->home_order = shmem->ints[7];
	motor[m]->steps_per_unit = shmem->floats[0];
	if (std::isnan(motor[m]->steps_per_unit)) {
		debug("Trying to set NaN steps per unit for motor %d %d", id, m);
		motor[m]->steps_per_unit = old_steps_per_unit;
	}
	motor[m]->home_pos = shmem->floats[1];
	motor[m]->limit_v = shmem->floats[2];
	motor[m]->limit_a = shmem->floats[3];
	arch_motors_change();
	SET_OUTPUT(motor[m]->enable_pin);
	if (enable != motor[m]->enable_pin.write()) {
		if (motors_busy)
			SET(motor[m]->enable_pin);
		else {
			RESET(motor[m]->enable_pin);
		}
	}
	RESET(motor[m]->step_pin);
	RESET(motor[m]->dir_pin);
	SET_INPUT(motor[m]->limit_min_pin);
	SET_INPUT(motor[m]->limit_max_pin);
	if (motor[m]->dir_pin.inverted() != old_dir_invert)
		arch_invertpos(id, m);
	if (!std::isnan(motor[m]->home_pos)) {
		// Axes with a limit switch.
		if (motors_busy && (old_home_pos != motor[m]->home_pos || old_steps_per_unit != motor[m]->steps_per_unit) && !std::isnan(old_home_pos)) {
			double diff = motor[m]->home_pos - old_home_pos * old_steps_per_unit / motor[m]->steps_per_unit;
			motor[m]->settings.current_pos += diff;
			//debug("load motor %d %d new home %f add %f", id, m, motor[m]->home_pos, diff);
			// adjusting the arch pos is not affected by steps/unit.
			arch_addpos(id, m, motor[m]->home_pos - old_home_pos);
		}
		reset_pos(this);
	}
	else if (!std::isnan(motor[m]->settings.current_pos)) {
		// Motors without a limit switch: adjust motor position to match axes.
		for (int a = 0; a < num_axes; ++a)
			axis[a]->settings.target = axis[a]->settings.current;
		space_types[type].xyz2motors(this);
		double diff = motor[m]->settings.target_pos - motor[m]->settings.current_pos;
		motor[m]->settings.current_pos += diff;
		arch_addpos(id, m, diff);
	}
} // }}}
Esempio n. 17
0
/// Set up temp sensors.
void temp_init() {
	temp_sensor_t i;
	for (i = 0; i < NUM_TEMP_SENSORS; i++) {
		switch(temp_sensors[i].temp_type) {
      #ifdef TEMP_MAX6675
        case TT_MAX6675:
          WRITE(SS, 1); // Turn sensor off.
          SET_OUTPUT(SS);
          // Intentionally no break, we might have more than one sensor type.
      #endif

		#ifdef	TEMP_THERMISTOR
			// handled by analog_init()
/*			case TT_THERMISTOR:
				break;*/
		#endif

		#ifdef	TEMP_AD595
			// handled by analog_init()
/*			case TT_AD595:
				break;*/
		#endif

      #ifdef TEMP_INTERCOM
        case TT_INTERCOM:
          // Enable the RS485 transceiver
          SET_OUTPUT(RX_ENABLE_PIN);
          SET_OUTPUT(TX_ENABLE_PIN);
          WRITE(RX_ENABLE_PIN,0);
          disable_transmit();

          intercom_init();
          send_temperature(0, 0);
          // Intentionally no break.
      #endif

			default: /* prevent compiler warning */
				break;
		}
	}
}
void power_on() {

	if (ps_is_on == 0) {
		#ifdef	PS_ON_PIN
			WRITE(PS_ON_PIN, 0);
			SET_OUTPUT(PS_ON_PIN);
			_delay_ms(500);
		#endif
		ps_is_on = 1;
	}

	psu_timeout = 0;
}
Esempio n. 19
0
/// set up temp sensors. Currently only the 'intercom' sensor needs initialisation.
void temp_init() {
	temp_sensor_t i;
	for (i = 0; i < NUM_TEMP_SENSORS; i++) {
		switch(temp_sensors[i].temp_type) {
		#ifdef	TEMP_MAX6675
			// initialised when read
/*			case TT_MAX6675:
				break;*/
                #ifdef NAL_REPRAP
                            SET_OUTPUT(MAX6675_CS);
                            SET_OUTPUT(MAX6675_SCK);
                            SET_INPUT(MAX6675_SO);
                #endif
		#endif

		#ifdef	TEMP_THERMISTOR
			// handled by analog_init()
/*			case TT_THERMISTOR:
				break;*/
		#endif

		#ifdef	TEMP_AD595
			// handled by analog_init()
/*			case TT_AD595:
				break;*/
		#endif

		#ifdef	TEMP_INTERCOM
			case TT_INTERCOM:
				intercom_init();
				send_temperature(0, 0);
				break;
		#endif

			default: /* prevent compiler warning */
				break;
		}
	}
}
Esempio n. 20
0
uint8_t ds18b20_read_bit(){
	// synchronize
	SET_LOW(DS18B20_PORT, DS18B20_DQ);
	SET_OUTPUT(DS18B20_DDR, DS18B20_DQ);
	DS18B20_PRECISE_DELAY(2);

	// wait until thermometer puts bit
	SET_INPUT(DS18B20_DDR, DS18B20_DQ);
	DS18B20_PRECISE_DELAY(5);

	// read it
	uint8_t ret=IS_HIGH(DS18B20_PIN, DS18B20_DQ);
	DS18B20_PRECISE_DELAY(60);

	return ret;
}
Esempio n. 21
0
/** LCD API **/
void lcd_init()
{
    lcd_implementation_init();

#ifdef NEWPANEL
    SET_INPUT(BTN_EN1);
    SET_INPUT(BTN_EN2);
#if (SDCARDDETECT != -1)
    SET_INPUT(SDCARDDETECT);
#endif
    WRITE(BTN_EN1,HIGH);
    WRITE(BTN_EN2,HIGH);
  #if BTN_ENC > 0
    SET_INPUT(BTN_ENC);
    WRITE(BTN_ENC,HIGH);
  #endif
  #ifdef REPRAPWORLD_KEYPAD
    SET_OUTPUT(SHIFT_CLK);
    SET_OUTPUT(SHIFT_LD);
    SET_INPUT(SHIFT_OUT);
    WRITE(SHIFT_OUT,HIGH);
    WRITE(SHIFT_LD,HIGH);
  #endif
#else
  #ifdef SR_LCD_2W_NL
     SET_OUTPUT(SR_DATA_PIN);
     SET_OUTPUT(SR_CLK_PIN);
  #else
    SET_OUTPUT(SHIFT_CLK);
    SET_OUTPUT(SHIFT_LD);
    SET_OUTPUT(SHIFT_EN);
    SET_INPUT(SHIFT_OUT);
    WRITE(SHIFT_OUT,HIGH);
    WRITE(SHIFT_LD,HIGH); 
    WRITE(SHIFT_EN,LOW);
   #endif // SR_LCD_2W_NL
#endif//!NEWPANEL

#if (SDCARDDETECT > 0)
    WRITE(SDCARDDETECT, HIGH);
    lcd_oldcardstatus = IS_SD_INSERTED;
#endif//(SDCARDDETECT > 0)
    #ifdef LCD_HAS_SLOW_BUTTONS
    slow_buttons = 0;
    #endif
    lcd_buttons_update();
#ifdef ULTIPANEL
    encoderDiff = 0;
#endif
}
Esempio n. 22
0
void setup_neopixel() {
  SET_OUTPUT(NEOPIXEL_PIN);
  pixels.setBrightness(NEOPIXEL_BRIGHTNESS); // 0 - 255 range
  pixels.begin();
  pixels.show(); // initialize to all off

  #if ENABLED(NEOPIXEL_STARTUP_TEST)
    safe_delay(1000);
    set_neopixel_color(pixels.Color(255, 0, 0, 0));  // red
    safe_delay(1000);
    set_neopixel_color(pixels.Color(0, 255, 0, 0));  // green
    safe_delay(1000);
    set_neopixel_color(pixels.Color(0, 0, 255, 0));  // blue
    safe_delay(1000);
  #endif
  set_neopixel_color(pixels.Color(NEO_WHITE));       // white
}
Esempio n. 23
0
void buzz(long duration, uint16_t freq) {
    if (freq > 0) {
#ifdef LCD_USE_I2C_BUZZER
        lcd_buzz(duration, freq);
#elif defined(BEEPER) && BEEPER >= 0 // on-board buzzers have no further condition
        SET_OUTPUT(BEEPER);
        tone(BEEPER, freq);
        delay(duration);
        noTone(BEEPER);
#else
        delay(duration);
#endif
    }
    else {
        delay(duration);
    }
}
Esempio n. 24
0
void ds18b20_write_bit(uint8_t bit){
	// synchronize
	SET_OUTPUT(DS18B20_DDR, DS18B20_DQ);
	SET_LOW(DS18B20_PORT, DS18B20_DQ);
	DS18B20_PRECISE_DELAY(2);

	// put bit
	if(bit){
		SET_HIGH(DS18B20_PORT, DS18B20_DQ);
	}
	DS18B20_PRECISE_DELAY(60);

	// release line
	SET_INPUT(DS18B20_DDR, DS18B20_DQ);
	SET_LOW(DS18B20_PORT, DS18B20_DQ);
	DS18B20_PRECISE_DELAY(2);
}
Esempio n. 25
0
CardReader::CardReader()
{
    filesize = 0;
    sdpos = 0;
    sdprinting = false;
    cardOK = false;
    saving = false;
    autostart_atmillis=0;

    autostart_stilltocheck=true; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
    lastnr=0;
    //power to SD reader
#if SDPOWER > -1
    SET_OUTPUT(SDPOWER);
    WRITE(SDPOWER,HIGH);
#endif //SDPOWER

    autostart_atmillis=millis()+5000;
}
Esempio n. 26
0
uint8_t ds18b20_reset(){
	// reset pulse
	SET_LOW(DS18B20_PORT, DS18B20_DQ);
	SET_OUTPUT(DS18B20_DDR,DS18B20_DQ);
	DS18B20_PRECISE_DELAY(480);

	// presence pulse
	SET_INPUT(DS18B20_DDR, DS18B20_DQ);
	DS18B20_PRECISE_DELAY(100);
	if(IS_HIGH(DS18B20_PIN, DS18B20_DQ)){
		return 0; // not present
	}
	DS18B20_PRECISE_DELAY(380);
	if(IS_LOW(DS18B20_PIN, DS18B20_DQ)){
		return 0; // not present
	}

	return 1;
}
Esempio n. 27
0
SDCard::SDCard()
{
    sdmode = false;
    sdactive = false;
    savetosd = false;
    Printer::setAutomount(false);
    //power to SD reader
#if SDPOWER > -1
    SET_OUTPUT(SDPOWER);
    WRITE(SDPOWER,HIGH);
#endif

#define SDCARDDETECT 24


#if defined(SDCARDDETECT) && SDCARDDETECT>-1
    SET_INPUT(SDCARDDETECT);
    WRITE(SDCARDDETECT,HIGH);
#endif
}
Esempio n. 28
0
CardReader::CardReader() {
  filesize = 0;
  sdpos = 0;
  sdprinting = false;
  cardOK = false;
  saving = false;
  logging = false;
  workDirDepth = 0;
  file_subcall_ctr = 0;
  memset(workDirParents, 0, sizeof(workDirParents));

  autostart_stilltocheck = true; //the SD start is delayed, because otherwise the serial cannot answer fast enough to make contact with the host software.
  autostart_index = 0;
  //power to SD reader
  #if SDPOWER > -1
    SET_OUTPUT(SDPOWER);
    WRITE(SDPOWER, HIGH);
  #endif //SDPOWER

  autostart_atmillis = millis() + 5000;
}
Esempio n. 29
0
	TemperatureManager::TemperatureManager()
		: Subject<float>()
		, m_target_temperature(0)
		, m_current_temperature(0)
		, m_current_temperature_raw(0)
#ifdef DOGLCD
		, m_control()
#endif
		, m_blower_control(true)
	{
		setTargetTemperature(0);
		SET_OUTPUT(HEATER_0_PIN);
#ifdef FAN_BLOCK_PIN
		pinMode(FAN_BLOCK_PIN, OUTPUT);
		digitalWrite(FAN_BLOCK_PIN, LOW);
#endif //FAN_BLOCK_PIN

#ifdef DOGLCD
		m_control = new TemperatureControl();
#endif
	}
Esempio n. 30
0
void mcp2515_init(void)
{
	// Aktivieren der Pins fuer das SPI Interface
	PORT_SPI &=  ~((1 << PIN_NUM(P_SCK)) | (1 << PIN_NUM(P_MOSI)));
	DDR_SPI |= (1 << PIN_NUM(P_SCK)) | (1 << PIN_NUM(P_MOSI));
	
	SET(MCP2515_CS);
	SET_OUTPUT(MCP2515_CS);
	
	// Aktivieren des SPI Master Interfaces
	SPCR = (1 << SPE) | (1 << MSTR) | R_SPCR;
	SPSR = R_SPSR;
	
	_delay_us(1);
	
	// MCP2515 per Software Reset zuruecksetzten,
	// danach ist er automatisch im Konfigurations Modus
	RESET(MCP2515_CS);
	spi_putc(SPI_RESET);
	SET(MCP2515_CS);
	
	// ein bisschen warten bis der MCP2515 sich neu gestartet hat
	_delay_ms(0.1);
	
	// Filter usw. setzen
	RESET(MCP2515_CS);
	spi_putc(SPI_WRITE);
	spi_putc(RXF0SIDH);
	for (uint8_t i = 0; i < sizeof(mcp2515_register_map); i++) {
		spi_putc(pgm_read_byte(&mcp2515_register_map[i]));
	}
	SET(MCP2515_CS);
	
	// nur Standard IDs, Message Rollover nach Puffer 1
	mcp2515_write_register(RXB0CTRL, (0 << RXM1) | (1 << RXM0) | (1 << BUKT));
	mcp2515_write_register(RXB1CTRL, (0 << RXM1) | (1 << RXM0));
	
	// MCP2515 zurueck in den normalen Modus versetzten
	mcp2515_write_register(CANCTRL, CLKOUT_PRESCALER_);
}