Touchaction Event firing twice - xamarin.forms

I am working with the skiasharp on xamarin with TouchTracking and while trying to handle the TouchAction event in code, i noticed the event gets fired twice instead of once.
void OnTouchEffectAction(object sender, TouchActionEventArgs args)
{
// Get touchpoint location
pt.X = XamDIUConvertToPixels(args.Location.X);
pt.Y = XamDIUConvertToPixels(args.Location.Y);
// Display point locations
Console.WriteLine("location X: " + pt.X + "\n location Y: " + pt.Y + "\n");
So, this would inevitably display to the console twice. And this becomes more problematic if say i want to call a function of text-to-speech in here, then the speech gets repeated.

Related

QTableView not scrolling all the way to the bottom

I'm mocking up a table in Qt using QTableView and QStandardItemModel. The table represents events in a log. It should scroll to the bottom so that it can show the most recent event. To be clear, I am mocking up this display, I am not adding elements to the table dynamically.
When I try using either the scrollToBottom method or the scrollTo method, the view is scrolling about 3/4 of the way down, rather than to the actual bottom of the window.
Here's a simplified version of my code:
logModel = new QStandardItemModel(THREADWATCHER_LOG_TABLE_LENGTH, 2, this);
logTable = new QTableView;
for (int i = 0; i < THREADWATCHER_LOG_TABLE_LENGTH; i += 6) {
QString spawnTimeString = QString("[16:09:10:");
int spawnTimeMs = 186 + i * 8; // a pseudo-random choice for the interval between spawns
spawnTimeString.append(QString::number(spawnTimeMs) + "]");
logMessage[i] = new QStandardItem(spawnTimeString + " Thread \"Image Fetcher 0\" was spawned in the image processor ");
logModel->setItem(i, 0, logMessage[i]);
// do the same thing with [i+1], [i+2]...[i+5]
// so that I get six different messages in each iteration of the loop
}
logTable->setModel(logModel);
QModelIndex lastIndex = logMessage[THREADWATCHER_LOG_TABLE_LENGTH - 1]->index();
logTable->scrollTo(lastIndex);
I get exactly the same thing if I call logTable->scrollToBottom() instead of scrolling to the last index.
Things I've tried already:
using a single-shot timer (to ensure events have completed before scrolling)
creating a public method that calls logTable->scrollToBottom(), and having something else call that method after this class's constructor finishes (the logic above is in the constructor)

Track position of Zaber device while moving

I am using a Zaber linear stage controlled by an Arduino using the Zaber shield. I try to do something similar to this question (Track position of a Zaber device as it moves), but using the Arduino language instead of Labview.
In the answer 3 options were provided: interpolate from the start and end points, poll the position using a timer, or turn on a device mode that reports the position every 250 ms.
The device mode does not seem to exist for my stage (X-LSQ-075B-E01) and I don't want to rely on interpolation. The stage is fitted with an encoder and I can easily get its readback for the exact position; I just don't know how to poll the stage while moving. I came up with the following code (a bit simplified), but it is relatively slow and only gives the readback from 1 stage (we are actually using 2) and sending the command to both does not really work.
#include <ZaberAscii.h>
ZaberShield shield(ZABERSHIELD_ADDRESS_AA);
ZaberAscii za(shield);
void setup() {
shield.begin(115200);
Serial.begin(115200);
za.send(1, 1, "move rel", 20000);
za.receive();
while (za.isIdle(1) == false) {
za.send(1, "get encoder.pos");
ZaberAscii::reply reply = za.receive();
if (!reply.isReply) {
Serial.println("*** Received a non-reply message from device " + String(reply.deviceNumber) + ".");
}
else if (reply.isRejected) {
Serial.println("*** A command was rejected by device " + String(reply.deviceNumber) + ".");
}
else {
Serial.println( String(reply.deviceNumber) + ": " + String(reply.responseData));
}
delay(5);
}
za.pollUntilIdle(1);
Serial.println("1 finished");
za.send(2, 1, "move rel", 20000);
while (za.isIdle(2) == false) {
za.send(2, "get encoder.pos");
Serial.println("Device 2 not idle");
ZaberAscii::reply reply = za.receive();
if (!reply.isReply) {
Serial.println("*** Received a non-reply message from device " + String(reply.deviceNumber) + ".");
}
else if (reply.isRejected) {
Serial.println("*** A command was rejected by device " + String(reply.deviceNumber) + ".");
}
else {
Serial.println( String(reply.deviceNumber) + ": " + String(reply.responseData));
}
//delay(10);
}
Serial.println("2 finished");
}
void loop() {}
To have it work on both devices, you would need to send both movement commands before starting the while loop, and then for the while loop you would want the condition to repeat until both axes are idle. Within the while loop you would read the position of both axes.
On the timing, can you say approximately what frequency you're getting now? The timing per communication is typically about 5-10ms. With the current functions, the isIdle() call takes it's own command, so I'd expect the above loop to be about 20-40ms. You could cut it in half by pulling the .IsBusy information from the 'get encoder.pos' reply.
Mike McDonald
mike#zaber.com

uwp GetcurrentPoint image

I am writing a code that move an image. it works.
I need the absolute x, y after the moving
how ca I get them ?
thank you
my code gives me only the relative points. :
private static void MyImage_PointerMoved(object sender, PointerRoutedEventArgs e)
{
Pointer ptr = e.Pointer;
if (ptr.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse)
{
// To get mouse state, we need extended pointer details.
// We get the pointer info through the getCurrentPoint method
// of the event argument.
Windows.UI.Input.PointerPoint ptrPt = e.GetCurrentPoint(micky.MyImage);
var transform = (micky.MyImage.RenderTransform as CompositeTransform);
double imagex = e.GetCurrentPoint(micky.MyImage).Position.X;
double imageY = e.GetCurrentPoint(micky.MyImage).Position.Y;
Not sure what you want to do. If you just want to get the image's absolute position. You could use TransformToVisual and TransformPoint method.
<Image x:Name="pic" Source="Assets/1.jpg"/>
var trans = pic.TransformToVisual(Window.Current.Content);
Point position = trans.TransformPoint(new Point(0, 0));
But I checked your code, I guess you want to move your image. If so, using Manipulation event should meet your target.
<Image x:Name="pic" Source="Assets/1.jpg" ManipulationMode="All" ManipulationDelta="Image_ManipulationDelta" Height="100" Width="200">
<Image.RenderTransform>
<TranslateTransform x:Name="translateTransform"></TranslateTransform>
</Image.RenderTransform>
</Image>
private void Image_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
translateTransform.X += e.Delta.Translation.X;
translateTransform.Y += e.Delta.Translation.Y;
System.Diagnostics.Debug.WriteLine("Manipulation: X: " + translateTransform.X + ", Y: " + translateTransform.Y);
}

QProgressBar (Qt 5.4.0) produces black blank screen

I wanted to use a QProgressBar in the following function:
void InstallingWindow::install_package(QString pkgname, QString tempdir){
qDebug() << "Imported tempdir is " + tempdir;
QFile ee_script("/usr/bin/ee_script");
QString program_install = "sudo /usr/bin/ee_script " + pkgname + " " + tempdir + " install";
if (!ee_script.exists()){
qDebug() << "Install script does not exists";
ee_script.error();
}
else{
process_install->start(program_install);
ui->progressBar->setMinimum(0);
ui->progressBar->setMaximum(0);
connect(process_install, SIGNAL(finished(int, QProcess::ExitStatus)), ui->progressBar, SLOT(show_progress_bar()));
process_install->waitForFinished(-1); //this will make the screen blank
ui->progressBar->setMaximum(0);
ui->progressBar->setValue(100);
ui->nextButton->setEnabled(true);
}
post_install();
}
void InstallingWindow::show_progress_bar(){
ui->progressBar->setMaximum(100);
ui->progressBar->setValue(100);
ui->nextButton->setEnabled(true);
}
I wanted progress bar to work as a wait bar (initially; later will be implemented with timer) and completed (finished at 100) after the QProcess finished. I get a blank black screen with process_install->waitForFinished(-1).
I tried many options but all in vain, while QProgressDialog works fine. Kindly help me where is the fault and what could I do.
When you waitForFinished, you are blocking the GUI thread, so the progress dialog never gets events, and so never paints. You'll need to arrange for the event loop to run regularly - something like (untested):
process_install->start(program_install);
do {
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
} while (process_install->waitForFinished(20)); // 1/50 second
ui->nextButton->setEnabled(true);
BTW, it's good idea to connect(process_install, SIGNAL(...), ...) before process_install->start, to avoid race conditions. Unlikely with a process that needs a progress meter, but still a good habit to get into. :-)

Values not getting printed outside a for loop

in my program a simple shopping application for my lab exercise, i just calculated the price of items inside a for loop but when i try to print it outside it is not getting printed...pls give me some suggestion.
for (int i = 1; i < 7; i++) {
String selection = request.getParameter("a" + i);
if (selection.equals("l")) {
price = Integer.parseInt(request.getParameter("b" + i));
total = total + price;
out.println("<h3>You have purchased the item:<br>Price is:</h3>" + price);
}
}
out.println("THE TOTAL IS"+total);
out.println("</body>");
out.println("</html>");
String selection = request.getParameter("a" + i);
//Here print the selection there is the problem
if (selection.equals("l")) ///Here alway it is false thats why you are getting this.
{
}
It gets not printed because its out of scope. Your total
variable only lives within the loop.
You have basic programming skills and know about variable scope, right?
http://www.java-made-easy.com/variable-scope.html

Resources