Bug 1836

Summary: request: add persistent variables to Math channel
Product: PulseView Reporter: cedric <cedric.dewijs>
Component: UIAssignee: Nobody <nobody>
Status: CONFIRMED ---    
Severity: normal    
Priority: Normal    
Version: unreleased development snapshot   
Target Milestone: ---   
Hardware: x86   
OS: Linux   
Attachments: screenshot for the actual traces, and a mockup of what I would like math1 to be

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