Ejemplo n.º 1
0
void Timer_t::SetUpdateFrequency(uint32_t FreqHz) {
#if defined STM32F2XX || defined STM32F4XX
    if(ANY_OF_5(ITmr, TIM1, TIM8, TIM9, TIM10, TIM11))  // APB2 is clock src
    	SetTopValue((*PClk * Clk.TimerAPB2ClkMulti) / FreqHz);
    else // APB1 is clock src
    	SetTopValue((*PClk * Clk.TimerAPB1ClkMulti) / FreqHz);
#elif defined STM32L1XX
    uint32_t TopVal;
    if(ANY_OF_3(ITmr, TIM9, TIM10, TIM11)) // APB2 is clock src
        TopVal  = ((*PClk * Clk.Timer9_11ClkMulti) / FreqHz) - 1;
    else TopVal = ((*PClk * Clk.Timer2_7ClkMulti) / FreqHz) - 1;
//    Uart.Printf("Topval = %u\r", TopVal);
    SetTopValue(TopVal);
#else
//    uint32_t UpdFreqMax = *PClk / (ITmr->ARR + 1);
#endif
	ITmr->CNT = 0;  // Reset counter to start from scratch
//#if defined STM32F2XX || defined STM32F4XX
//    uint32_t UpdFreqMax;
//    if(ANY_OF_5(ITmr, TIM1, TIM8, TIM9, TIM10, TIM11))  // APB2 is clock src
//        UpdFreqMax = (*PClk) * Clk.TimerAPB2ClkMulti / (ITmr->ARR + 1);
//    else // APB1 is clock src
//        UpdFreqMax = (*PClk) * Clk.TimerAPB1ClkMulti / (ITmr->ARR + 1);
//#else
//    uint32_t UpdFreqMax = *PClk / (ITmr->ARR + 1);
//#endif
//    uint32_t div = UpdFreqMax / FreqHz;
//    if(div != 0) div--;
//    ITmr->PSC = div;
//    Uart.Printf("\r  FMax=%u; div=%u", UpdFreqMax, div);
}
Ejemplo n.º 2
0
void cScrollBar::DragMove(int y)
{  // ScrollBar is being dragged, so update bar position and send new position to scrollbar's parent
	// this function should be called only by mousemove detection after dragging is initiated
	int NPos = y - m_YPos;

	// set current bar position based on movement
	if (NPos <= m_DragInitYPos)
		m_BarTop = 0;
	else if (NPos - m_DragInitYPos + m_BarHeight >= m_SectionHeight)
		m_BarTop = m_SectionHeight - m_BarHeight;
	else
		m_BarTop = NPos - m_DragInitYPos;

	int lastitem = m_ItemsTotal - m_ItemsVisible;
	int maxtop = m_SectionHeight - m_BarHeight;
	int listpos = 0;

	// extrapolate first visible item based on bar position, set it
	if (m_BarTop == 0)  // first item
		listpos = 0;
	else if (m_BarTop >= maxtop)  // last item
		listpos = lastitem;
	else  // anywhere else between; the 0.5 added is to make it effectively "round" instead of "floor"
		listpos = (int) ( (double)m_BarTop * ((double)lastitem / (double)maxtop) + 0.5 );

	if(ParentPosition)  // send updated position back to parent control
	{
		*ParentPosition = listpos;
		if(m_UpdateSelf)
			SetTopValue(listpos);
	}
}
void MainWindow::on_pushButtonTimes_clicked()
{

    SetBeforeValues();
    SetTopValue(ui->doubleTopValue->value() *ui->doubleBottomValue->value());
    AddtoTextBox(mBeforeTop+ " * "+mBeforeBottom  + " = " +ui->doubleTopValue->text() );
}
void MainWindow::on_pushButtonDivide_clicked()
{
    if(ui->doubleBottomValue->value() != 0){
          SetBeforeValues();
          SetTopValue(ui->doubleTopValue->value() /ui->doubleBottomValue->value());
          AddtoTextBox(mBeforeTop+ " / "+mBeforeBottom  + " = " +ui->doubleTopValue->text() );
    }
   else
        QMessageBox::information(this,"Error","Can't divide by zero.");
}
Ejemplo n.º 5
0
bool cScrollBar::ButtonClicked(int x, int y, bool mouseWheelDown, bool mouseWheelUp)
{
	if(m_Disabled || m_Hidden || !ParentPosition)
		return false;

	if(IsOver(x,y))
	{
		int newpos = m_ItemTop;
		if (mouseWheelUp)
			newpos -= m_ScrollAmount;
		else if (mouseWheelDown)
			newpos += m_ScrollAmount;
		// clicked on "up" button; scroll up small amount
		else if (y <= m_YPos + m_ImgButtonUp->h)
			newpos -= m_ScrollAmount;
		// clicked on "down" button; scroll down small amount
		else if (y >= m_YPos + m_Height - m_ImgButtonUp->h)
			newpos += m_ScrollAmount;
		// clicked in bar space above actual scroll bar; scroll up large amount
		else if (y < m_YPos + m_BarTop + m_ImgButtonUp->h)
			newpos -= m_PageAmount;
		// clicked in bar space below actual scroll bar; scroll down large amount
		else if (y > m_YPos + m_BarTop + m_BarHeight + m_ImgButtonUp->h)
			newpos += m_PageAmount;

		if(newpos != m_ItemTop)
		{
			if(newpos > m_ItemsTotal - m_ItemsVisible)
				newpos = m_ItemsTotal - m_ItemsVisible;
			else if(newpos < 0)
				newpos = 0;

			*ParentPosition = newpos;

			if(m_UpdateSelf)
				SetTopValue(newpos);
		}

		return true;
	}
	return false;
}
void MainWindow::on_pushButtonSqrt_clicked()
{




    if(ui->doubleTopValue->value() < 0)
    {
         QMessageBox::information(this,"Error","Can't SQRT less than zero.");

    }
    else
    {
        SetBeforeValues();
        SetTopValue(qSqrt( ui->doubleTopValue->value()));
        AddtoTextBox(" SQRT ( "+mBeforeTop+ ") = " +ui->doubleTopValue->text() );
    }



}