void send(Message* const message) {
		if( message->id < Message::ID::MAX ) {
			auto& fn = map_[toUType(message->id)];
			if( fn ) {
				fn(message);
			}
		}
	}
void TouchCalibrationView::touch_complete() {
	auto next_phase = static_cast<Phase>(toUType(phase) + 1);

	switch(phase) {
	case Phase::Calibrate0:
	case Phase::Verify0:
		digitizer_points[0] = average;
		break;

	case Phase::Calibrate1:
	case Phase::Verify1:
		digitizer_points[1] = average;
		break;

	case Phase::Calibrate2:
	case Phase::Verify2:
		digitizer_points[2] = average;
		break;

	default:
		break;
	}

	if( phase == Phase::Calibrate2 ) {
		const std::array<Point, 3> display_points { {
			image_calibrate_0.screen_rect().center(),
			image_calibrate_1.screen_rect().center(),
			image_calibrate_2.screen_rect().center(),
		} };

		calibration = { digitizer_points, display_points };
	}

	if( phase == Phase::Verify2 ) {
		const auto calibrated_0 = calibration.translate(digitizer_points[0]);
		const auto d_sq_0 = distance_squared(calibrated_0, image_verify_0);

		const auto calibrated_1 = calibration.translate(digitizer_points[1]);
		const auto d_sq_1 = distance_squared(calibrated_1, image_verify_1);

		const auto calibrated_2 = calibration.translate(digitizer_points[2]);
		const auto d_sq_2 = distance_squared(calibrated_2, image_verify_2);

		if( (d_sq_0 < verify_d_sq_max) && (d_sq_1 < verify_d_sq_max) && (d_sq_2 < verify_d_sq_max) ) {
			next_phase = Phase::Success;
		} else {
			next_phase = Phase::Failure;
		}
	}

	set_phase(next_phase);
}
bool XC2C64A::shift_ir(const instruction_t instruction) {
	const ir_t ir_buffer = toUType(instruction);
	const jtag::tap::bits_t bits { &ir_buffer, ir_length };
	return tap.shift_ir(bits);
}
	void unregister_handler(const Message::ID id) {
		map_[toUType(id)] = nullptr;
	}
	void register_handler(const Message::ID id, MessageHandler&& handler) {
		if( map_[toUType(id)] != nullptr ) {
			chDbgPanic("MsgDblReg");
		}
		map_[toUType(id)] = std::move(handler);
	}
AnalogAudioView::AnalogAudioView(
	NavigationView& nav
) {
	add_children({ {
		&rssi,
		&channel,
		&audio,
		&field_frequency,
		&field_lna,
		&field_vga,
		&options_modulation,
		&field_volume,
		&record_view,
		&waterfall,
	} });

	field_frequency.set_value(receiver_model.tuning_frequency());
	field_frequency.set_step(receiver_model.frequency_step());
	field_frequency.on_change = [this](rf::Frequency f) {
		this->on_tuning_frequency_changed(f);
	};
	field_frequency.on_edit = [this, &nav]() {
		// TODO: Provide separate modal method/scheme?
		auto new_view = nav.push<FrequencyKeypadView>(receiver_model.tuning_frequency());
		new_view->on_changed = [this](rf::Frequency f) {
			this->on_tuning_frequency_changed(f);
			this->field_frequency.set_value(f);
		};
	};

	field_frequency.on_show_options = [this]() {
		this->on_show_options_frequency();
	};

	field_lna.on_show_options = [this]() {
		this->on_show_options_rf_gain();
	};

	field_vga.on_show_options = [this]() {
		this->on_show_options_rf_gain();
	};

	const auto modulation = receiver_model.modulation();
	options_modulation.set_by_value(toUType(modulation));
	options_modulation.on_change = [this](size_t, OptionsField::value_t v) {
		this->on_modulation_changed(static_cast<ReceiverModel::Mode>(v));
	};
	options_modulation.on_show_options = [this]() {
		this->on_show_options_modulation();
	};

	field_volume.set_value((receiver_model.headphone_volume() - audio::headphone::volume_range().max).decibel() + 99);
	field_volume.on_change = [this](int32_t v) {
		this->on_headphone_volume_changed(v);
	};

	record_view.on_error = [&nav](std::string message) {
		nav.display_modal("Error", message);
	};

	audio::output::start();

	update_modulation(static_cast<ReceiverModel::Mode>(modulation));
}
Esempio n. 7
0
nImO::SpValue
nImO::Array::extractValue
    (const nImO::Message &  theMessage,
     const int              leadByte,
     size_t &               position,
     nImO::SpArray          parentValue)
{
    ODL_ENTER(); //####
    ODL_P3("theMessage = ", &theMessage, "position = ", &position, "parentValue = ", //####
           parentValue.get()); //####
    ODL_X1("leadByte = ", leadByte); //####
    SpValue result;
    bool    atEnd;
    bool    isEmpty = (DataKind::OtherContainerEmptyValue == (DataKind::OtherContainerEmptyMask & leadByte));
    int     aByte;

    ++position; // We will always accept the lead byte
    ODL_I1("position <- ", position); //####
    if (isEmpty)
    {
        ODL_LOG("(isEmpty)"); //####
        aByte = theMessage.getByte(position, atEnd);
        ODL_X1("aByte <- ", aByte); //####
        ODL_B1("atEnd <- ", atEnd); //####
        if (! atEnd)
        {
            ODL_LOG("(! atEnd)"); //####
            static const DataKind   endMarker = (DataKind::Other | DataKind::OtherContainerEnd |
                                                 DataKind::OtherContainerTypeArray | DataKind::OtherContainerEmptyValue);

            if (toUType(endMarker) == aByte)
            {
                ODL_LOG("(endMarker == aByte)"); //####
                result.reset(new Array);
                ++position;
                ODL_I1("position <- ", position); //####
            }
            else
            {
                ODL_LOG("! (endMarker == aByte)"); //####
                result.reset(new Invalid("Empty Array with incorrect end tag @", position));
            }
        }
    }
    else
    {
        ODL_LOG("! (isEmpty)"); //####
        aByte = theMessage.getByte(position, atEnd);
        ODL_X1("aByte <- ", aByte); //####
        ODL_B1("atEnd <- ", atEnd); //####
        if (! atEnd)
        {
            ODL_LOG("(! atEnd)"); //####
            IntStatus numStatus;
            int64_t   elementCount = extractInt64FromMessage(theMessage, aByte, position, numStatus);

            if (IntStatus::Successful == numStatus)
            {
                ODL_LOG("(IntStatus::Successful == status)"); //####
                elementCount -= DataKindIntegerShortValueMinValue - 1;
                ODL_I1("elementCount <- ", elementCount); //####
                if (0 >= elementCount)
                {
                    ODL_LOG("(0 >= elementCount)"); //####
                    result.reset(new Invalid("Array with zero or negative count @", position));
                }
                else
                {
                    auto    anArray = std::make_shared<Array>();

                    result = anArray;
                    if (nullptr == result)
                    {
                        ODL_LOG("(nullptr == result)"); //####
                        result.reset(new Invalid("Could not allocate an Array"));
                    }
                    else
                    {
                        bool    okSoFar = true;

                        for ( ; okSoFar && (elementCount > static_cast<int64_t>(anArray->size())); )
                        {
                            aByte = theMessage.getByte(position, atEnd);
                            ODL_X1("aByte <- ", aByte); //####
                            ODL_B1("atEnd <- ", atEnd); //####
                            if (atEnd)
                            {
                                ODL_LOG("(atEnd)"); //####
                                result.reset();
                                okSoFar = false;
                            }
                            else
                            {
                                SpValue aValue(getValueFromMessage(theMessage, position, aByte, anArray));

                                // Note that it is the responsibility of the extractor to add to
                                // this Array, so it's not correct for this loop to perform an
                                // append operation.
                                if (nullptr == aValue)
                                {
                                    ODL_LOG("(nullptr == aValue)"); //####
                                    result.reset(new Invalid("Null Value read @", position));
                                    okSoFar = false;
                                }
                                else if (aValue->asFlaw())
                                {
                                    ODL_LOG("(aValue->asFlaw())"); //####
                                    result = aValue;
                                    okSoFar = false;
                                }
                            }
                        }
                        if (okSoFar)
                        {
                            aByte = theMessage.getByte(position, atEnd);
                            ODL_X1("aByte <- ", aByte); //####
                            ODL_B1("atEnd <- ", atEnd); //####
                            if (atEnd)
                            {
                                ODL_LOG("(atEnd)"); //####
                                result.reset();
                                okSoFar = false;
                            }
                            else
                            {
                                ODL_LOG("! (atEnd)"); //####
                                static const DataKind endMarker = (DataKind::Other | DataKind::OtherContainerEnd |
                                                                   DataKind::OtherContainerTypeArray |
                                                                   DataKind::OtherContainerNonEmptyValue);

                                if (toUType(endMarker) == aByte)
                                {
                                    ODL_LOG("(toUType(endMarker) == aByte)"); //####
                                    ++position;
                                    ODL_I1("position <- ", position); //####
                                }
                                else
                                {
                                    ODL_LOG("! (toUType(endMarker) == aByte)"); //####
                                    result.reset(new Invalid("Non-empty Array with incorrect end "
                                                             "tag @", position));
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                ODL_LOG("! (IntStatus::Successful == numStatus)"); //####
            }
        }
    }
    if ((nullptr != parentValue) && (nullptr != result) && (! result->asFlaw()))
    {
        ODL_LOG("((nullptr != parentValue) && (nullptr != result) && (! result->asFlaw()))"); //####
        parentValue->addValue(result);
    }
    ODL_EXIT_P(result.get()); //####
    return result;
} // nImO::Array::extractValue
Esempio n. 8
0
std::string type(Reading::Type type) {
	return to_string_dec_uint(toUType(type), 2);
}
Esempio n. 9
0
	void register_handler(const Message::ID id, MessageHandler&& handler) {
		map_[toUType(id)] = std::move(handler);
	}