Author Topic: SB π  (Read 5505 times)

Offline AIR

  • BASIC Developer
  • Posts: 649
Re: SB π
« Reply #240 on: June 09, 2019, 07:25:11 PM »
Couldn't you do this with a besAlloc/besFree combo?

Offline John

  • Forum Support / SB Dev
  • Posts: 2669
    • ScriptBasic Open Source Project
Re: SB π
« Reply #241 on: June 09, 2019, 07:37:11 PM »
Good idea!

I'll take a look at requirements.

Offline John

  • Forum Support / SB Dev
  • Posts: 2669
    • ScriptBasic Open Source Project
Re: SB π
« Reply #242 on: June 09, 2019, 08:44:46 PM »
How can I treat these buffers as a character array? I need to populate every element in the buffer.

Offline AIR

  • BASIC Developer
  • Posts: 649
Re: SB π
« Reply #243 on: June 10, 2019, 04:33:25 PM »
I think you need to besDeref them, to get the actual pointer.
From there you should be able to index as needed, I think.

Offline John

  • Forum Support / SB Dev
  • Posts: 2669
    • ScriptBasic Open Source Project
Re: SB π
« Reply #244 on: June 10, 2019, 05:21:27 PM »
Is there an extension module that does this already you know of?

Offline AIR

  • BASIC Developer
  • Posts: 649
Re: SB π
« Reply #245 on: June 10, 2019, 05:31:18 PM »
A simpler way, where you can see/control what is actually happening, might be to use

calloc

do what you need to do with the allocated string

besSetReturnString (check if this is right, this is off the top of my head)


free what you calloc'd above

OR, instead of the 'bes' function above, you can make use of the pModuleObject (you'll need to configure the struct itself to hold whatever values you need and then populate as needed).  Then add a function to return what you need from that struct.  The potential advantage of this approach is that you can retrieve the value as you need it, instead of having the function run through the entire calculation if you haven't stored the result somewhere.  From looking over other modules, that seems to be the preferred approach in SB modules.

If you want to see how either approach is used, grep the macro/function using the -ir switches (insensitve case, recursive) over the extensions folder.
« Last Edit: June 10, 2019, 05:34:15 PM by AIR »

Offline John

  • Forum Support / SB Dev
  • Posts: 2669
    • ScriptBasic Open Source Project
Re: SB π
« Reply #246 on: June 10, 2019, 05:45:52 PM »
Perfect world would be only passing the pin and delay values and the extension auto creates / frees the sampling buffer and returns if a stream of "1" 'a exceeds 64.

Offline AIR

  • BASIC Developer
  • Posts: 649
Re: SB π
« Reply #247 on: June 10, 2019, 07:14:42 PM »
That's the front end / api interface at work.

The back end / actual code is never as simple as that.

So you have a goal, to provide a simple api.  Time to get your hands dirty to make it happen!

Offline John

  • Forum Support / SB Dev
  • Posts: 2669
    • ScriptBasic Open Source Project
Re: SB π
« Reply #248 on: June 10, 2019, 07:33:56 PM »
I'll take it in baby steps. First I need to get It working passing a buffer size to use. The results will show you if you need to increase your delay or your buffer size to see the sample period you're after.
« Last Edit: June 10, 2019, 07:37:36 PM by John »