Esempio n. 1
0
void	Primaries::RgbSystem::init (const vsutl::FilterBase &filter, const ::VSMap &in, ::VSMap &out, const char r_0 [], const char g_0 [], const char b_0 [], const char w_0 [])
{
	assert (r_0 != 0);
	assert (g_0 != 0);
	assert (b_0 != 0);
	assert (w_0 != 0);

	const bool     ready_old_flag         = is_ready ();
	std::array <Vec2, NBR_PLANES> rgb_old = _rgb;
	Vec2                          w_old   = _white;

	const char *   name_0_arr [NBR_PLANES] = { r_0, g_0, b_0 };
	for (int k = 0; k < NBR_PLANES; ++k)
	{
		_init_flag_arr [k] |=
			read_coord_tuple (_rgb [k], filter, in, out, name_0_arr [k]);
	}

	_init_flag_arr [NBR_PLANES] |=
		read_coord_tuple (_white, filter, in, out, w_0);

	if (ready_old_flag && is_ready () && (rgb_old != _rgb || w_old != _white))
	{
		_preset = fmtcl::PrimariesPreset_UNDEF;
	}
}
Esempio n. 2
0
    /// Set the callback which needs to be invoked when the future becomes
    /// ready. If the future is ready the function will be invoked
    /// immediately.
    void future_data_base<traits::detail::future_data_void>::
        set_on_completed(completed_callback_type data_sink)
    {
        if (!data_sink) return;

        if (is_ready())
        {
            // invoke the callback (continuation) function right away
            handle_on_completed(std::move(data_sink));
        }
        else
        {
            std::unique_lock<mutex_type> l(mtx_);
            if (is_ready())
            {
                l.unlock();

                // invoke the callback (continuation) function
                handle_on_completed(std::move(data_sink));
            }
            else
            {
                on_completed_.push_back(std::move(data_sink));
            }
        }
    }
Esempio n. 3
0
void z80dma_device::timerproc()
{
	int done;

	if (--m_cur_cycle)
	{
		return;
	}

	if (m_is_read && !is_ready()) return;

	if (m_is_read)
	{
		/* TODO: there's a nasty recursion bug with Alpha for Sharp X1 Turbo on the transfers with this function! */
		do_read();
		done = 0;
		m_is_read = false;
		m_cur_cycle = (PORTA_IS_SOURCE ? PORTA_CYCLE_LEN : PORTB_CYCLE_LEN);
	}
	else
	{
		done = do_write();
		m_is_read = true;
		m_cur_cycle = (PORTB_IS_SOURCE ? PORTA_CYCLE_LEN : PORTB_CYCLE_LEN);
	}

	if (done)
	{
		m_dma_enabled = 0; //FIXME: Correct?
		m_status = 0x09;

		m_status |= !is_ready() << 1; // ready line status

		if(TRANSFER_MODE == TM_TRANSFER)     m_status |= 0x10;   // no match found

		update_status();
		if (LOG) logerror("Z80DMA '%s' End of Block\n", tag());

		if (INT_ON_END_OF_BLOCK)
		{
			trigger_interrupt(INT_END_OF_BLOCK);
		}

		if (AUTO_RESTART)
		{
			if (LOG) logerror("Z80DMA '%s' Auto Restart\n", tag());

			m_dma_enabled = 1;
			m_addressA = PORTA_ADDRESS;
			m_addressB = PORTB_ADDRESS;
			m_count = BLOCKLEN;
			m_status |= 0x30;
		}
	}
}
Esempio n. 4
0
void z80dma_device::rdy_write_callback(int state)
{
	// normalize state
	m_rdy = state;
	m_status = (m_status & 0xFD) | (!is_ready() << 1);

	update_status();

	if (is_ready() && INT_ON_READY)
    {
		trigger_interrupt(INT_RDY);
    }
}
Esempio n. 5
0
void z80dma_device::update_status()
{
	UINT16 pending_transfer;
	attotime next;

	// no transfer is active right now; is there a transfer pending right now?
	pending_transfer = is_ready() & m_dma_enabled;

	if (pending_transfer)
	{
		m_is_read = true;
		m_cur_cycle = (PORTA_IS_SOURCE ? PORTA_CYCLE_LEN : PORTB_CYCLE_LEN);
		next = attotime::from_hz(clock());
		m_timer->adjust(
			attotime::zero,
			0,
			// 1 byte transferred in 4 clock cycles
			next);
	}
	else
	{
		if (m_is_read)
		{
			// no transfers active right now
			m_timer->reset();
		}
	}

	// set the busreq line
	m_out_busreq_cb(pending_transfer ? ASSERT_LINE : CLEAR_LINE);
}
Esempio n. 6
0
int AudioRBResampler::get_num_of_ready_frames() {
	if (!is_ready())
		return 0;
	int32_t increment = (src_mix_rate * MIX_FRAC_LEN) / target_mix_rate;
	int read_space = get_reader_space();
	return (int64_t(read_space) << MIX_FRAC_BITS) / increment;
}
Esempio n. 7
0
long HX711::read() {
  // wait for the chip to become ready
  while (!is_ready());

  byte data[3];

  // pulse the clock pin 24 times to read the data
  for (byte j = 3; j--;) {
    for (char i = 8; i--;) {
      digitalWrite(PD_SCK, HIGH);
      bitWrite(data[j], i, digitalRead(DOUT));
      digitalWrite(PD_SCK, LOW);
    }
  }

  // set the channel and the gain factor for the next reading using the clock pin
  for (int i = 0; i < GAIN; i++) {
    digitalWrite(PD_SCK, HIGH);
    digitalWrite(PD_SCK, LOW);
  }

  data[2] ^= 0x80;

  return ((uint32_t) data[2] << 16) | ((uint32_t) data[1] << 8) | (uint32_t) data[0];
}
Esempio n. 8
0
void z80dma_device::update_status()
{
	UINT16 pending_transfer;
	attotime next;

	// no transfer is active right now; is there a transfer pending right now?
	pending_transfer = is_ready() & m_dma_enabled;

	if (pending_transfer)
	{
		m_is_read = true;
		m_cur_cycle = (PORTA_IS_SOURCE ? PORTA_CYCLE_LEN : PORTB_CYCLE_LEN);
		next = ATTOTIME_IN_HZ(clock());
		timer_adjust_periodic(m_timer,
			attotime_zero,
			0,
			// 1 byte transferred in 4 clock cycles
			next);
	}
	else
	{
		if (m_is_read)
		{
			// no transfers active right now
			timer_reset(m_timer, attotime_never);
		}
	}

	// set the busreq line
	devcb_call_write_line(&m_out_busreq_func, pending_transfer ? ASSERT_LINE : CLEAR_LINE);
}
Esempio n. 9
0
        void trigger_impl_future(std::true_type,
            typed_continuation<Result, RemoteResult>&& cont, F&& f, Ts&&... vs)
        {
            typedef
                typename std::is_same<RemoteResult, util::unused_type>::type
                is_void;

            auto result = util::invoke(std::forward<F>(f),
                std::forward<Ts>(vs)...);

            typedef typename hpx::util::decay<decltype(result)>::type future_type;

            if(result.is_ready())
            {
                detail::deferred_trigger<Result, RemoteResult>(
                    is_void(), std::move(cont), std::move(result));
                return;
            }

            void (*fun)(is_void, typed_continuation<Result, RemoteResult>&&,
                    future_type&&)
                = &detail::deferred_trigger<Result, RemoteResult, future_type>;

            result.then(
                hpx::util::bind(
                    hpx::util::one_shot(fun)
                  , is_void()
                  , std::move(cont) //-V575
                  , util::placeholders::_1
                )
            );
        }
Esempio n. 10
0
 // Resume coroutine.
 // Pre:  The coroutine must be ready.
 // Post: The coroutine relinquished control. It might be ready
 //       or exited.
 // Throws:- 'abnormal_exit' if the coroutine was exited by another
 //          uncaught exception.
 // Note, it guarantees that the coroutine is resumed. Can throw only
 // on return.
 void invoke()
 {
     this->init();
     HPX_ASSERT(is_ready());
     do_invoke();
     // TODO: could use a binary or here to eliminate
     // shortcut evaluation (and a branch), but maybe the compiler is
     // smart enough to do it anyway as there are no side effects.
     if (m_exit_status)
     {
         if (m_exit_status == ctx_exited_return)
             return;
         if (m_exit_status == ctx_exited_abnormally)
         {
             std::rethrow_exception(m_type_info);
             //std::type_info const* tinfo = nullptr;
             //std::swap(m_type_info, tinfo);
             //throw abnormal_exit(tinfo ? *tinfo :
             //      typeid(unknown_exception_tag));
         }
         else {
             HPX_ASSERT(0 && "unknown exit status");
         }
     }
 }
Esempio n. 11
0
size_t empty_fd(int fd, void *buffer, int size) {
	size_t bytes_copied = 0;
	while (is_ready(fd)) {
    	bytes_copied += read(fd, buffer, size);
    }

	return bytes_copied;
}
Esempio n. 12
0
      result_type get()
      {
        if(!is_ready())
        {
          wait();
        }

        return *res_;
      }
Esempio n. 13
0
static int
set_ready_fd(int fd, ofp_fd_set *fd_set, int(*is_ready)(int fd))
{
	if (OFP_FD_ISSET(fd, fd_set) && is_ready(fd))
		return 1;

	OFP_FD_CLR(fd, fd_set);
	return 0;
}
Esempio n. 14
0
//
//
//
/// @brief A private member function to allocate memory for arrays of any
/// rank order. Its behavior is driven by the array::data_length() member
/// function and thus by the current values of @c rank1, @c rank2, @c rank3
/// and @c rank4 data members. If the data length is null nothing is done.
/// The operation is carried out by the master thread only.
//
/// @return @c true if the memory was allocated properly, and @c false
/// otherwise.
//
inline bool init_data()
{
	#pragma omp master
	if(data_length() > 0)
	{
		data = new (std::nothrow) data_type[data_length()]();
	}
	return is_ready();
};
Esempio n. 15
0
	bool stepped_cooldown::try_to_fire_and_reset(stepped_timestamp s, fixed_delta t) {
		if (is_ready(s, t)) {
			ready_to_fire = false;
			when_last_fired = s;
			return true;
		}

		return false;
	}
Esempio n. 16
0
void z80dma_device::timerproc()
{
	int done;

	if (--m_cur_cycle)
	{
		return;
	}

	if (m_is_read && !is_ready()) return;

	if (m_is_read)
	{
		do_read();
		done = 0;
		m_is_read = false;
		m_cur_cycle = (PORTA_IS_SOURCE ? PORTA_CYCLE_LEN : PORTB_CYCLE_LEN);
	}
	else
	{
		done = do_write();
		m_is_read = true;
		m_cur_cycle = (PORTB_IS_SOURCE ? PORTA_CYCLE_LEN : PORTB_CYCLE_LEN);
	}

	if (done)
	{
		m_dma_enabled = 0; //FIXME: Correct?
        m_status = 0x19;

		m_status |= !is_ready() << 1; // ready line status

		if(TRANSFER_MODE == TM_TRANSFER)     m_status |= 0x10;   // no match found

		update_status();
		if (LOG) logerror("Z80DMA '%s' End of Block\n", tag());

		if (INT_ON_END_OF_BLOCK)
        {
			trigger_interrupt(INT_END_OF_BLOCK);
        }
	}
}
Esempio n. 17
0
static int
none_of_ready(int nfds, ofp_fd_set *fd_set, int (*is_ready)(int fd))
{
	int fd;

	for (fd = OFP_SOCK_NUM_OFFSET; fd < nfds && fd_set; ++fd)
		if (OFP_FD_ISSET(fd, fd_set) && is_ready(fd))
			return 0;

	return 1;
}
Esempio n. 18
0
	void create(unsigned int size1)
	{
		if(!is_ready())
		{
			rank1 = size1;
			if(!init_data())
			{
				reset_data_members();
			}
		}
	};
Esempio n. 19
0
void event_environment::log_error(const char * text_id, const char * error_message)
{
    assert(is_ready());
    
    std::stringstream format;
    format<<"Error on "<<text_id<<" event: "<<error_message<<std::endl;
    
    if(m_log_error_function)
        m_log_error_function(format.str().c_str());
    else std::cerr<<format.str();
}
Esempio n. 20
0
void * poll_t(void * arg) {
	struct pollfd pfd;
	int ready;
	State * state = (State *)arg;
	while ((ready = is_ready(state)) >= 0) {
		pfd.fd = state->clockid;
		pfd.events = POLLIN;
		if (poll(&pfd, 1, 0)) {
			send_poll_request(state, getID());
			reset_clock(state->clockid);
		}
	}
	return NULL;
}
Esempio n. 21
0
//
//
//
/// @brief Checks if all the elements are negative. Only if the current array
/// was previously initialized either by construction or the array::create().
//
/// @return @c true if all the elements are negative, and @c false otherwise.
//
bool is_negative() const
{
	if(is_ready())
	{
		auto check = [](int iter)
		{
			return (iter < 0.0);
		};
		return std::all_of(data, data_end(), check);
	}
	else
	{
		return false;
	}
};
Esempio n. 22
0
lua_State * event_environment::push_listeners_table(const char * text_id, int num_id)
{
    assert(is_ready());
    
    lua_rawgeti(m_state, LUA_REGISTRYINDEX, m_numeric_id_index);
    assert(lua_type(m_state, -1) == LUA_TTABLE);
    
    int bottom = lua_gettop(m_state);
    
    lua_pushinteger(m_state, num_id);
    lua_gettable(m_state, -2);
    assert(lua_type(m_state, -1) == LUA_TTABLE);    
    lua_replace(m_state, bottom);
    
    return m_state;
}
Esempio n. 23
0
long HX711::read() {
	// wait for the chip to become ready
	while (!is_ready()) {
		// Will do nothing on Arduino but prevent resets of ESP8266 (Watchdog Issue)
		yield();
	}

    unsigned long value = 0;
    byte data[3] = { 0 };
    byte filler = 0x00;

	// pulse the clock pin 24 times to read the data
    data[2] = shiftIn(DOUT, PD_SCK, MSBFIRST);
    data[1] = shiftIn(DOUT, PD_SCK, MSBFIRST);
    data[0] = shiftIn(DOUT, PD_SCK, MSBFIRST);

	// set the channel and the gain factor for the next reading using the clock pin
	for (unsigned int i = 0; i < GAIN; i++) {
		digitalWrite(PD_SCK, HIGH);
		digitalWrite(PD_SCK, LOW);
	}

    // Datasheet indicates the value is returned as a two's complement value
    // Flip all the bits
    data[2] = ~data[2];
    data[1] = ~data[1];
    data[0] = ~data[0];

    // Replicate the most significant bit to pad out a 32-bit signed integer
    if ( data[2] & 0x80 ) {
        filler = 0xFF;
    } else if ((0x7F == data[2]) && (0xFF == data[1]) && (0xFF == data[0])) {
        filler = 0xFF;
    } else {
        filler = 0x00;
    }

    // Construct a 32-bit signed integer
    value = ( static_cast<unsigned long>(filler) << 24
            | static_cast<unsigned long>(data[2]) << 16
            | static_cast<unsigned long>(data[1]) << 8
            | static_cast<unsigned long>(data[0]) );

    // ... and add 1
    return static_cast<long>(++value);
}
Esempio n. 24
0
void uci(void) {
    /* printf("Entering UCI mode.  Type in commands here (quit to quit, help for a list of commands)\n\n"); */
    
    // Default state
    isWhitesMove=1;
    //set_position_startpos();
    
    FILE *fp;
    fp=fopen("chess.log", "a");
    fprintf(fp, "---- CHESS v0.0 ------------\n");
    
    int keep_going = 1;
    char string[256];
    while (keep_going == 1) {
        //printf( "Command: " );
        fflush (stdout);
        int x = scanf ("%79s",string);
        fprintf(fp, "Received command: %s\n", string);
        if (strcmp(string, "quit")==0) {
            keep_going = 0;
        } else if (strcmp(string, "uci")==0) {
            show_uci_info();
        } else if (strcmp(string, "isready")==0) {
            is_ready();
        } else if (strcmp(string, "position")==0) {
            set_position();
        } else if (strcmp(string, "go")==0) {
            go();
        } else if (strcmp(string, "stop")==0) {
            stop();
        } else if (strcmp(string, "draw")==0) {
            draw();
        } else if (strcmp(string, "move")==0) {
            uci_make_move();
        } else if (strcmp(string, "dumpmoves")==0) {
            dump_moves();
        } else if (strcmp(string, "info")==0) {
            info();
        } else if (strcmp(string, "test")==0) {
            run_tests();
        } else {
            printf( "Unknown command: %s\n", string );
        }
    }
    fclose(fp);
}
Esempio n. 25
0
        // Nothrow.
        void do_invoke() throw ()
        {
            HPX_ASSERT(is_ready());
#if defined(HPX_HAVE_THREAD_PHASE_INFORMATION)
            ++m_phase;
#endif
            m_state = ctx_running;

#if defined(HPX_HAVE_ADDRESS_SANITIZER)
            start_switch_fiber(&asan_fake_stack);
#endif

            swap_context(m_caller, *this, detail::invoke_hint());

#if defined(HPX_HAVE_ADDRESS_SANITIZER)
            finish_switch_fiber(asan_fake_stack, m_caller);
#endif
        }
Esempio n. 26
0
bool pipesvr_win32::setup(remote_server *svr) {
    if (is_ready()) {
        return true;
    }

    if (!svr) {
        return false;
    }

    svr_ = svr;

    log_info("Creating pipe %s...", pipe_name_);

    pipe_ = CreateNamedPipe(pipe_name_,
        PIPE_ACCESS_DUPLEX,
        PIPE_TYPE_BYTE |                // from message
        PIPE_READMODE_BYTE |            // from message
        PIPE_NOWAIT |
        PIPE_REJECT_REMOTE_CLIENTS,
        PIPE_UNLIMITED_INSTANCES,       // max. instances 
        LEN_NETBUF,                     // output buffer size 
        LEN_NETBUF,                     // input buffer size 
        NMPWAIT_USE_DEFAULT_WAIT,       // client time-out 
        NULL);                          // no security attribute 

    if (pipe_ == PIPE_NONE) {
        DWORD error = GetLastError();
        switch (error) {
        case ERROR_PIPE_BUSY:
            log_error("Failed to create pipe with error 0x%x. Is the server "
                "already running?", error);
            break;
        default:
            log_error("Failed to create pipe with error 0x%x.", error);
            break;
        }
        return false;
    }
    else {
        log_info("Pipe created.");
    }

    return true;
}
Esempio n. 27
0
long HX711::read() {
    // Byte:     0        1        2        3
    // Bits:  76543210 76543210 76543210 76543210
    // Data: |--------|--------|--------|--------|
    // Bit#:  33222222 22221111 11111100 00000000
    //        10987654 32109876 54321098 76543210
    union DataBuffer {
        byte data[4];
        long value;
    } data_buffer;

    // Wait for the chip to become ready
    for (; !is_ready() ;) {
        // Will do nothing on Arduino but prevent resets of ESP8266 (Watchdog Issue)
        yield();
    }

    // Pulse the clock pin 24 times to read the data
    data_buffer.data[1] = shiftIn(DOUT, PD_SCK, MSBFIRST);
    data_buffer.data[2] = shiftIn(DOUT, PD_SCK, MSBFIRST);
    data_buffer.data[3] = shiftIn(DOUT, PD_SCK, MSBFIRST);

	// Set the channel and the gain factor for the next reading using the clock pin
	for (unsigned int i = GAIN ; 0 < i ; --i) {
		digitalWrite(PD_SCK, HIGH);
		digitalWrite(PD_SCK, LOW);
	}

    // Replicate the most significant bit to pad out a 32-bit signed integer
    if ( data_buffer.data[1] & 0x80 ) {
        data_buffer.data[0] = 0xFF;
    } else {
        data_buffer.data[0] = 0x00;
    }

    // Datasheet indicates the value is a 24-bit two's complement (signed) value
    // https://cdn.sparkfun.com/datasheets/Sensors/ForceFlex/hx711_english.pdf

    // Flip all the bits
    data_buffer.value = ~data_buffer.value;

    // ... and add 1
    return ++data_buffer.value;
}
Esempio n. 28
0
long LCS::read() {
  // wait for the chip to become ready
  while (!is_ready());

  byte data1[3];
  byte data2[3];
  byte data3[3];

  // pulse the clock pin 24 times to read the data
  for (byte j = 3; j--;) {
    for (char i = 8; i--;) {
      digitalWrite(PD_SCK, HIGH);
      bitWrite(data1[j], i, digitalRead(DOUT1));  //@@@@@@@@@@@@@@@@@ I feel like this might pose a problem if 3 bitWrites takes too long @@@@@@@@@@@@@@@@
      bitWrite(data2[j], i, digitalRead(DOUT2));
      bitWrite(data3[j], i, digitalRead(DOUT3));
      digitalWrite(PD_SCK, LOW);
    }
  }

  // set the channel and the gain factor for the next reading using the clock pin
  for (int i = 0; i < GAIN; i++) {
    digitalWrite(PD_SCK, HIGH);
    digitalWrite(PD_SCK, LOW);
  }

  data1[2] ^= 0x80;
  data2[2] ^= 0x80;
  data3[2] ^= 0x80;

  long result1 = ((uint32_t) data1[2] << 16) | ((uint32_t) data1[1] << 8) | (uint32_t) data1[0];
  long result2 = ((uint32_t) data2[2] << 16) | ((uint32_t) data2[1] << 8) | (uint32_t) data2[0];
  long result3 = ((uint32_t) data3[2] << 16) | ((uint32_t) data3[1] << 8) | (uint32_t) data3[0];

  long total = (long)((double)result3/1)+ (long)((double)result2*1) + result1;//(long) ((double)result1/1.045);
  //long total = result3;
  BVAL[COUNTER] = total;
  inc_counter();
  
  return total;
}
Esempio n. 29
0
bool pipesvr_win32::connect() {
    /* ensure need to connect */
    if (!is_ready() || is_connected()) {
        return false;
    }
    
    if (!ConnectNamedPipe(pipe_, NULL)) {
        DWORD error = GetLastError();

        switch (error) {
        case ERROR_PIPE_CONNECTED: /* process on other side of pipe */
            return connected_ = true;
        case ERROR_PIPE_LISTENING: /* other end of pipe not connected */
            return false;
        default:
            log_error("Failed to connect to pipe with error 0x%x.", error);
            return false;
        }
    }

    return connected_ = true;
}
Esempio n. 30
0
    void try_connect() {
        if (!ready && started && num_trials <= 20
        && lastmillis - last_connect_trial >= 1000) {
            if (is_ready()) {
                ready = true;
                ClientSystem::connect("127.0.0.1", TESSERACT_SERVER_PORT);
            }
            else {
                conoutf("Waiting for server to finish starting up .. (%d)",
                    num_trials);
            }

            if (num_trials == 20) {
                logger::log(logger::ERROR,
                    "Failed to start server. See %s for more information.",
                    server_log_file);
            }

            num_trials++;
            last_connect_trial = lastmillis;
        }
    }