Bug 1836 - request: add persistent variables to Math channel
Summary: request: add persistent variables to Math channel
Status: CONFIRMED
Alias: None
Product: PulseView
Classification: Unclassified
Component: UI (show other bugs)
Version: unreleased development snapshot
Hardware: x86 Linux
: Normal normal
Target Milestone: ---
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-04-15 13:03 CEST by cedric
Modified: 2023-04-15 13:03 CEST (History)
0 users



Attachments
screenshot for the actual traces, and a mockup of what I would like math1 to be (67.65 KB, image/png)
2023-04-15 13:03 CEST, cedric
Details

Note You need to log in before you can comment on or make changes to this bug.
Description cedric 2023-04-15 13:03:32 CEST
Created attachment 792 [details]
screenshot for the actual traces, and a mockup of what I would like math1 to be

Overview: I'm trying to use the math channel to create a decoder for my analog signal. This failed, because there's no way to create a variable that is persistent.

Steps to Reproduce:
1) Start Pulseview
2) Remove all traces of the demo device, except A3 (sawtooth)
3) Set the number of samples to 100, and set the samplerate to 100Hz
4) Click Run. Now channel A3 draws a sawtooth
5) Click "Add math channel". the signal trace "Math1" appears.
6) Click "Math1", and then the 4 symbols at the end of the line "expression". Now the "Math Expression Editor" appears.
7) Enter the following expression and click OK.
var themax := 0;
var thesample := A3;

if (thesample > themax)
{
	themax := thesample;
}

Actual Results:
The values in "Math1" are 0 when A3 is below 0, and are the same as A3 if A3 is above 0. This is working as expected.
 
Expected Results:
I would like to be able to enter this expression in the math Expression editor:
static var themax := 0; //persistent variable
var thesample := A3;

if (thesample > themax)
{
	themax := thesample;
}
Then the values in Math 1 should start with 0, and then increase every time the value in A3 is higher than the value of Math1. If A3 is then lower than Math1, Math1 should keep it's value, so math1 should stay constant after the first period of A3.

Build Date & Hardware: I build it myself on 04/15/2023 on a 64 bit AMD machine.
PulseView 0.5.0-git-62c0968
libsigrok 0.6.0-git/4:0:0 (rt: 0.6.0-git-5bce22ac/4:0:0)
Kernel version: $ uname -a 
Linux cedric 6.2.11-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 13 Apr 2023 16:59:24 +0000 x86_64 GNU/Linux

Additional Builds and Platforms: Also seen with Windows 10 and this version:
https://www.dropbox.com/s/i1guje5kg89yi7a/pulseview-0.5.0-git-7e5c839-installer_rev2.exe?dl=0

Additional Information:
See the attached screenshot for the actual traces, and a mockup of what I would like math1 to be