Author Topic: SB π  (Read 7524 times)

Offline AIR

  • BASIC Developer
  • Posts: 684
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: 2745
    • 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: 2745
    • 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: 684
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: 2745
    • 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: 684
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: 2745
    • 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: 684
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: 2745
    • 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 »

Offline John

  • Forum Support / SB Dev
  • Posts: 2745
    • ScriptBasic Open Source Project
Re: SB π
« Reply #249 on: July 04, 2019, 09:27:35 PM »
AIR,

I get this error when trying to use IupPopup for the font dialog. The weird thing is I don't get this error running the tutorial edit project as a C program on the same Raspberry Pi 3 B.



pi@RPi3B:~/sbrt/examples $ scriba iup_edit.sb

(scriba:2717): Gtk-WARNING **: Unknown type PangoFontFamily specified in treemodel model

(scriba:2717): Gtk-WARNING **: Unknown type PangoFontFace specified in treemodel model

(scriba:2717): Gtk-WARNING **: /home/pi/gtk+3.0-3.22.11/./gtk/gtkliststore.c:516: Invalid type (null)

(scriba:2717): Gtk-WARNING **: /home/pi/gtk+3.0-3.22.11/./gtk/gtkliststore.c:516: Invalid type (null)

(scriba:2717): GLib-GObject-CRITICAL **: g_value_type_transformable: assertion 'G_TYPE_IS_VALUE (src_type)' failed

(scriba:2717): GLib-GObject-CRITICAL **: g_value_type_transformable: assertion 'G_TYPE_IS_VALUE (src_type)' failed

(scriba:2717): GLib-GObject-WARNING **: /build/glib2.0-F5w919/glib2.0-2.50.3/./gobject/gtype.c:4264: type id '0' is invalid

(scriba:2717): GLib-GObject-WARNING **: can't peek value table for type '<invalid>' which is not currently referenced
Segmentation fault
pi@RPi3B:~/sbrt/examples $


The Open and SaveAs dialogs work as expected. What could be causing this?

Offline AIR

  • BASIC Developer
  • Posts: 684

Offline John

  • Forum Support / SB Dev
  • Posts: 2745
    • ScriptBasic Open Source Project
Re: SB π
« Reply #251 on: July 05, 2019, 03:06:09 PM »
Nice find!

Is that a -D option on the command line?

Update

I tried adding -DRTLD_GLOBAL to the gcc line and no change.  :-[
« Last Edit: July 05, 2019, 05:16:36 PM by John »

Offline AIR

  • BASIC Developer
  • Posts: 684
Re: SB π
« Reply #252 on: July 06, 2019, 06:02:31 AM »
Nice find!

Is that a -D option on the command line?

Update

I tried adding -DRTLD_GLOBAL to the gcc line and no change.  :-[

Of course that wouldn't work.  The issue appears to be that GTK3 dynamically loads some of it's components via DLOPEN.

If the C example IS NOT using dlopen/dlsym, then the comparison you make ("The C Version Works") is invalid.

Attach your source
« Last Edit: July 06, 2019, 10:17:46 AM by AIR »

Offline John

  • Forum Support / SB Dev
  • Posts: 2745
    • ScriptBasic Open Source Project
Re: SB π
« Reply #253 on: July 06, 2019, 03:09:29 PM »
Sorry for the delay AIR, I had some personal stuff to do.

Here is where I'm at with the Simple Editor tutorial I have going on the RPi forum.

Code: Script BASIC
  1. ' IUP Simple Editor
  2.  
  3. IMPORT iup.bas
  4.  
  5. CONST IUP_CENTER = 0xFFFF
  6. CONST IUP_DEFAULT = -2
  7.  
  8.  
  9. FUNCTION Open_CB
  10.   LOCAL filedlg, filename, och, olen, fstr
  11.   filedlg = IUP::FileDlg()
  12.   IUP::SetAttribute(filedlg, "DIALOGTYPE", "OPEN")
  13.   IUP::SetAttribute(filedlg, "EXTFILTER", "Text Files|*.txt|All Files|*.*|")
  14.   IUP::Popup(filedlg, IUP_CENTER, IUP_CENTER)
  15.   IF IUP::GetInt(filedlg, "STATUS") <> -1 THEN
  16.     filename = IUP::GetAttribute(filedlg, "VALUE")
  17.     och = FREEFILE()
  18.     OPEN filename FOR BINARY AS och
  19.     olen = FILELEN(filename)
  20.     fstr = INPUT(olen, och)
  21.     IUP::StoreAttribute(multitext, "VALUE", fstr)
  22.     CLOSE(och)
  23.   END IF
  24.   IUP::Destroy(filedlg)
  25.   Open_CB = IUP_DEFAULT
  26. END FUNCTION
  27.  
  28.  
  29. FUNCTION SaveAs_CB
  30.   LOCAL filedlg, filename, sch, fstr
  31.   filedlg = IUP::FileDlg()
  32.   IUP::SetAttribute(filedlg, "DIALOGTYPE", "SAVE")
  33.   IUP::SetAttribute(filedlg, "EXTFILTER", "Text Files|*.txt|All Files|*.*|")
  34.   IUP::Popup(filedlg, IUP_CENTER, IUP_CENTER)
  35.   IF IUP::GetInt(filedlg, "STATUS") <> -1 THEN
  36.     filename = IUP::GetAttribute(filedlg, "VALUE")
  37.     fstr = IUP::GetAttribute(multitext, "VALUE")
  38.     sch = FREEFILE()
  39.     OPEN filename FOR BINARY AS sch
  40.     PRINT #sch, fstr
  41.     CLOSE(sch)
  42.   END IF
  43.   IUP::Destroy(filedlg)
  44.   SaveAs_CB = IUP_DEFAULT
  45. END FUNCTION
  46.  
  47.  
  48. FUNCTION Font_CB
  49.   LOCAL fontdlg, font
  50.   fontdlg = IUP::FontDlg()
  51.   font = IUP::GetAttribute(multitext, "FONT")
  52.   IUP::StoreAttribute(fontdlg, "VALUE", font)
  53.   IUP::Popup(fontdlg, IUP_CENTER, IUP_CENTER)
  54.   IF IUP::GetInt(fontdlg, "STATUS") = 1 THEN
  55.     font = IUP::GetAttribute(fontdlg, "VALUE")
  56.     IUP::StoreAttribute(multitext, "FONT", font)
  57.   END IF
  58.   IUP::Destroy(fontdlg)
  59.   Font_CB = IUP_DEFAULT
  60. END FUNCTION
  61.  
  62.  
  63. FUNCTION About_CB
  64.   IUP::Message("About", "   Simple Editor\n\nIUP ScriptBasic Binding")
  65.   About_CB = IUP_DEFAULT
  66. END FUNCTION
  67.  
  68.  
  69. SUB Win_exit
  70.   Iup::ExitLoop = TRUE
  71. END SUB
  72.  
  73.  
  74. ' *** MAIN ***
  75.  
  76. IUP::Open
  77. IUP::ImageLibOpen()
  78.  
  79.  
  80. multitext = IUP::Text()
  81. vbox = IUP::Vbox(multitext)
  82. IUP::SetAttribute(multitext, "MULTILINE", "YES")
  83. IUP::SetAttribute(multitext, "EXPAND", "YES")
  84.  
  85. lbl_statusbar = IUP::Label("Lin 1, Col 1")
  86. IUP::SetAttribute(lbl_statusbar, "NAME", "STATUSBAR")
  87. IUP::SetAttribute(lbl_statusbar, "EXPAND", "HORIZONTAL")
  88. IUP::SetAttribute(lbl_statusbar, "PADDING", "10x5")
  89.  
  90. item_open = IUP::Item("Open")
  91. btn_open = IUP::Button()
  92. IUP::SetAttribute(btn_open, "IMAGE", "IUP_FileOpen")
  93. IUP::SetAttribute(btn_open, "FLAT", "Yes")
  94. IUP::SetAttribute(btn_open, "CANFOCUS", "No")
  95.  
  96. item_saveas = IUP::Item("Save As")
  97. btn_save = IUP::Button("")
  98. IUP::SetAttribute(btn_save, "IMAGE", "IUP_FileSave")
  99. IUP::SetAttribute(btn_save, "FLAT", "Yes")
  100. IUP::SetAttribute(btn_save, "CANFOCUS", "No")
  101.  
  102. item_exit = IUP::Item("Exit")
  103.  
  104. item_find = IUP::Item("Find...")
  105. btn_find = IUP::Button("")
  106. IUP::SetAttribute(btn_find, "IMAGE", "IUP_EditFind")
  107. IUP::SetAttribute(btn_find, "FLAT", "Yes")
  108. IUP::SetAttribute(btn_find, "CANFOCUS", "No")
  109.  
  110. toolbar_hb = IUP::Hbox( _
  111.     btn_open, _
  112.     btn_save, _
  113.     IUP::SetAttributes(IUP::Label(), "SEPARATOR=VERTICAL"), _
  114.     btn_find)
  115.  
  116. IUP::SetAttribute(toolbar_hb, "MARGIN", "5x5")
  117. IUP::SetAttribute(toolbar_hb, "GAP", "2")
  118.  
  119. item_goto = IUP::Item("Go To...")
  120. item_font = IUP::Item("Font...")
  121. item_about = IUP::Item("About...")
  122.  
  123. Iup::SetCallback(item_exit,"ACTION", ADDRESS(Win_exit()))
  124. IUP::SetCallback(item_open, "ACTION", ADDRESS(Open_CB()))
  125. IUP::SetCallback(item_saveas, "ACTION", ADDRESS(SaveAs_CB()))
  126. IUP::SetCallback(item_font, "ACTION", ADDRESS(Font_CB()))
  127. IUP::SetCallback(item_about, "ACTION", ADDRESS(About_CB()))
  128.  
  129. file_menu = IUP::Menu( _
  130.     item_open, _
  131.     item_saveas, _
  132.     IUP::Separator(), _
  133.     item_exit)
  134. edit_menu = IUP::Menu( _
  135.     item_find, _
  136.     item_goto)
  137. format_menu = IUP::Menu(item_font)
  138. help_menu = IUP::Menu(item_about)
  139.  
  140. sub_menu_file = IUP::Submenu("File", file_menu)
  141. sub_menu_edit = IUP::Submenu("Edit", edit_menu)
  142. sub_menu_format = IUP::Submenu("Format", format_menu)
  143. sub_menu_help = IUP::Submenu("Help", help_menu)
  144.  
  145. menu = IUP::Menu( _
  146.     sub_menu_file, _
  147.     sub_menu_edit, _
  148.     sub_menu_format, _
  149.     sub_menu_help)
  150.  
  151.  
  152. vbox = IUP::Vbox(toolbar_hb, multitext, lbl_statusbar)
  153.  
  154. dlg = IUP::Dialog(vbox)
  155. IUP::SetAttributeHandle(dlg, "MENU", menu)
  156. IUP::SetAttribute(dlg, "TITLE", "Simple Editor")
  157. IUP::SetAttribute(dlg, "SIZE", "QUARTERxQUARTER")
  158. IUP::ShowXY(dlg, IUP_CENTER, IUP_CENTER)
  159. IUP::SetAttribute(dlg, "USERSIZE")
  160.  
  161. IUP::MainLoop
  162. IUP::Close
  163.  

Here is a link to the IUP/CD/IM distribution I built from source as there curently isn't one from the IUP site.

IUP for the RPi 3B

I'm attaching my current PUI extension module directory.
« Last Edit: July 06, 2019, 03:11:25 PM by John »

Offline AIR

  • BASIC Developer
  • Posts: 684
Re: SB π
« Reply #254 on: July 06, 2019, 05:27:17 PM »
Wheres the import file?
I'm trying this on my Linux WS first; I tried it with the bas file in the archive folder, immediate segfault.