Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 28 Nov 2014, 19:08
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
BaCon Bits
Post new topic   Reply to topic View previous topic :: View next topic
Page 4 of 12 [168 Posts]   Goto page: Previous 1, 2, 3, 4, 5, 6, ..., 10, 11, 12 Next
Author Message
GatorDog


Joined: 12 Sep 2006
Posts: 136

PostPosted: Thu 11 Aug 2011, 14:11    Post subject:  

We'll add another widget to Hello BaCon and then look
into processing the information gathered.

Concept- If we want to count out 5 apples, we don't call the
first apple zero. However, computers like to start counting at zero.
(We don't). Bacon has an option that specifies to start counts with
1 instead of zero. "OPTION BASE 1". Put that near the top of the
program. See the BaCon doc for further information.

The ENTRY widget allows the user to type in some piece
of information. Their name for example. This is how we'll
set up an info label and an ENTRY widget.
Code:
   '--- Customer info
   Customer_label_ = MARK("We'll call you when order is ready!", 380, 30)
   PROPERTY(Customer_label_, "xalign", 0.5)
   ATTACH(Mainwin_, Customer_label_, 10, 220)

   Customer_name_ = ENTRY(Customer_directions$, 380, 30)
   ATTACH(Mainwin_, Customer_name_, 10, 246)

To initiate the process I've added a "Place-Order" button next to
the "Cancel" button. We need a CALLBACK to trigger a FUNCTION
when the "Place-Order" button is clicked.
Code:
   Place_order_ = BUTTON("Place-Order", 100, 28)
   ATTACH(Mainwin_, Place_order_, 170, 365)

   CALLBACK(Place_order_, PLACE_ORDER)

Now to write a function named FUNCTION PLACE_ORDER.
We'll only do minimal amount of error checking.
GRAB$(widget_) gets the text, if any, that is in the ENTRY widget.
The double set of double quotes stands for a "null" string (ie. nothing).
If ENTRY is blank, we'll just wait until the customer
is ready to let us know their name Wink The CHOP$ command removes any
leading or trailing spaces or tabs.
Code:
' ------------------
FUNCTION PLACE_ORDER
' ------------------
   Customer_name$ = GRAB$(Customer_name_)
   Customer_name$ = CHOP$(Customer_name$)
   IF Customer_name$ = "" THEN
      RETURN FALSE
   END IF
END FUNCTION

Next we'll check to see if there are spaces in the name. Maybe they
entered their first and last names. To do this, we use the SPLIT
command. We use the space character as the seperator (if there is one).
ex. SPLIT String_to_split$ BY character_to_split_on TO an_array_name$ SIZE how_many_names.
After SPLIT seperates the string into individual smaller chunks (array), it sets
the "how_many_names" variable to the number of smaller chunks. If the customer
entered their first and last name, how_many_names will be set to 2. If there is only
one name, SPLIT is happy setting how_many to one. By the way, if we hadn't used
the "OPTION BASE 1" mentioned earlier, we'd be working with 0 and 1. One meaning
that there are actually two items. (That can get confusing quick.) Any way,
using SPLIT we can make sure we have a single name and that's all the error
checking we'll do on that item.
Code:
' ------------------
FUNCTION PLACE_ORDER
' ------------------
   Customer_name$ = GRAB$(Customer_name_)
   IF Customer_name$ = "" THEN
      RETURN FALSE
   END IF

   SPLIT Customer_name$ BY " " TO Array$ SIZE How_many_names
   Customer_name$ = Array$[ How_many_names ]
END FUNCTION

Refer to the following function code for the rest of this discussion.
Grab the drink order with Drink$ = GRAB$(Drink_combo_) .

The radio buttons for slice thickness take a little more work. We have
to check each one to see which is selected. It will be TRUE if it is selected,
otherwise FALSE. This is a simple IF/THEN test so we can use the shortened IF/THEN syntax.

Now check if they're ordering eggs, and if so grab that information.
The call to our SHOW_ORDER function opens a message box so that the customer
can confirm the order is correct.
Code:
' ------------------
FUNCTION PLACE_ORDER
' ------------------
   Customer_name$ = GRAB$(Customer_name_)
   IF Customer_name$ = "" THEN
      RETURN FALSE
   END IF

   SPLIT Customer_name$ BY " " TO Array$ SIZE How_many_names
   Customer_name$ = Array$[ How_many_names ]

   Drink$ = GRAB$(Drink_combo_)

   IF GET(Slice_size_1_) THEN Slice_thickness$ = "Thin"
   IF GET(Slice_size_2_) THEN Slice_thickness$ = "Medium"
   IF GET(Slice_size_3_) THEN Slice_thickness$ = "Thick"

   Eggs_cooked$ = ""
   How_many_eggs$ = ""
   IF GET(Eggs_or_not_) THEN
      Eggs_cooked$ = GRAB$(Eggs_list_)
      How_many_eggs$ = STR$( GET(How_many_eggs_))
   END IF
   
   SHOW_ORDER : 'Show Msgdialog, Confirm order
   RETURN TRUE
END FUNCTION

This is the code added to set up a MSGDIALOG. Refer to the complete
source code for location and details.
Code:
   '--- This initializes the MSGDIALOG, but doesn't display it yet
   Order_window_ = MSGDIALOG("Confirm Order", 300, 220, 4, 5)

   '--- This "shows" the MSGDIALOG when the "Place-Order" button is clicked
   CALLBACK(Place_order_, PLACE_ORDER)

   '--- This "hides" the MSGDIALOG when the "dialog" button is clicked
   CALLBACK(Order_window_, ORDER_CLOSE)

These are the subroutines that open and close the msgdialog widget.
Code:
' ------------------
SUB SHOW_ORDER
' ------------------
   Tmp$ = CONCAT$("Hello ", Customer_name$, NL$, NL$)
   Tmp$ = CONCAT$(Tmp$, "Please click OK if order is correct", NL$, NL$)
   Tmp$ = CONCAT$(Tmp$, "Drink - ", Drink$, NL$)
   Tmp$ = CONCAT$(Tmp$, "Bacon - ", Slice_thickness$, NL$)
   IF GET(Eggs_or_not_) THEN
      Tmp$ = CONCAT$(Tmp$, How_many_eggs$, " Egg(s), ", Eggs_cooked$, NL$)
   ELSE
      Tmp$ = CONCAT$(Tmp$, "No Eggs", NL$)
   END IF

   TEXT(Order_window_, Tmp$)
   SHOW(Order_window_)
END SUB

' ------------------
SUB ORDER_CLOSE(NUMBER Dialog_, int Button_)
' ------------------
   HIDE(Dialog_)
END SUB


This Hello BaCon program should give you a good running start to create GUI's
using BaCon and HUG.

I added a few other goodies in the source to discover, but you should be able
to figure them out Razz

Happy Crankin'
rod
hello_bacon.tar.gz
Description  source
gz

 Download 
Filename  hello_bacon.tar.gz 
Filesize  2.11 KB 
Downloaded  310 Time(s) 
hello_bacon.jpg
 Description   
 Filesize   25.93 KB
 Viewed   956 Time(s)

hello_bacon.jpg

Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1287
Location: Ukraine

PostPosted: Fri 12 Aug 2011, 06:19    Post subject: bacon diner  

Dear Rod,

Thanks for the nice demo - I think it will help people... I think Peter should also post it at his site.

With kind regards,
vovchik
Back to top
View user's profile Send private message 
GatorDog


Joined: 12 Sep 2006
Posts: 136

PostPosted: Thu 18 Aug 2011, 23:46    Post subject: BaCon File I/O  

Sooner or later you'll write a program that collects some data that you'd
like to save for later use. That's where File I/O - Input/Output comes in.
The general flow is -
OPEN file
WRITE data
CLOSE file
There are variations on this. For example putting the WRITE data in a loop
to write several data samples. Reading the data back in is -
OPEN file
READ data
CLOSE file
Again with some variations in setup.

BaCon has several directives for File I/O. Here I'll cover plain ASCII
reading and writting which uses the READING, WRITING, APPENDING directives.
READING is for reading in data from a file. WRITING and APPENDING both
write to a file. The difference being that WRITING will overwrite an
existing file with the new data. APPENDING adds the data to the end of
an existing file. Here I'll be using READING and WRITING.

First let's create a gui that asks for three pieces of data, and a button.
(The button doesn't do anything yet.)
Code:
'BaCon File I/O

INCLUDE "/usr/share/BaCon/hug_imports.bac"
INIT

HUGOPTIONS("BASEXFTDPI 78")
HUGOPTIONS("FONT DejaVu Sans 12")

OPTION BASE 1
CONST Mainwin_width = 300
CONST Mainwin_height = 250
CONST Mainwin_border = 5
CONST Widget_width = Mainwin_width - (2 * Mainwin_border)
CONST Widget_height = 30
CONST Widget_spacing = 5
CONST Btn_height = 25
CONST Btn_width = 90

GLOBAL Row TYPE int

' ------------------
SUB MAKE_GUI
' ------------------
   Mainwin_ = WINDOW("File I/O", Mainwin_width, Mainwin_height)

   Label1_ = MARK("First & Last Name:", Widget_width, Widget_height)
   Entry1_ = ENTRY("", Widget_width, Widget_height)

   Label2_ = MARK("Age:", Widget_width, Widget_height)
   Entry2_ = ENTRY("", Widget_width, Widget_height)

   Label3_ = MARK("Yes or No:", Widget_width, Widget_height)
   Entry3_ = ENTRY("", Widget_width, Widget_height)

   Row = 0
   ATTACH(Mainwin_, Label1_, Mainwin_border, Row)
   INCR Row, Widget_height + Widget_spacing
   ATTACH(Mainwin_, Entry1_, Mainwin_border, Row)

   INCR Row, Widget_height + Widget_spacing
   ATTACH(Mainwin_, Label2_, Mainwin_border, Row)
   INCR Row, Widget_height + Widget_spacing
   ATTACH(Mainwin_, Entry2_, Mainwin_border, Row)

   INCR Row, Widget_height + Widget_spacing
   ATTACH(Mainwin_, Label3_, Mainwin_border, Row)
   INCR Row, Widget_height + Widget_spacing
   ATTACH(Mainwin_, Entry3_, Mainwin_border, Row)

   '--- Bottom Buttons
   Save_btn_ = BUTTON("Save", Btn_width, Btn_height)
   Btn_x = Mainwin_width - Btn_width - Mainwin_border
   Btn_y = Mainwin_height - Btn_height - Mainwin_border
   ATTACH(Mainwin_, Save_btn_, Btn_x, Btn_y)

END SUB

MAKE_GUI

DISPLAY
Use CONST and variables wherever you can for dimentioning and placing
widgets. It allows you to change your gui with a single edit.
The above code creates our main gui window. Then three labels and three
ENTRY fields. Then the labels and entry (widgets) are attached to the main
window. The button is also created and attached to the bottom of the window.

Our save file will need a name. This can be done with the FILEDIALOG widget
but for now we'll just hard code it to save the file in our HOME directory.
We'll add this to our CONST's -
Code:
CONST Filename$ = CONCAT$( GETENVIRON$("HOME"), "/my_file.txt")

Now we'll add a SUBroutine to write the data to the file (my_file.txt", and a
CALLBACK that runs the SUB when the "Save" button is clicked.

The subroutine name is SAVE_TO_FILE. We'll put this above the MAKE_GUI subroutine.
Code:
' ------------------
SUB SAVE_TO_FILE
' ------------------
   OPEN Filename$ FOR WRITING AS Filehandle_
      WRITELN GRAB$(Entry1_) TO Filehandle_
      WRITELN GRAB$(Entry2_) TO Filehandle_
      WRITELN GRAB$(Entry3_) TO Filehandle_
   CLOSE FILE Filehandle_
END SUB
We use GRAB$ to get the text from the entries.

Add the callback to the end of the MAKE_GUI sub.
Code:
CALLBACK(Save_btn_, SAVE_TO_FILE)
Compile and run the program. Fill in the blanks and click Save. The program
saves the data. Check you home folder for the file if you like.

Let's add a button, callback and subroutine to clear or reset the entry fields.
The button and callback go to the end of MAKE_GUI and the SUB CLEAR_ENTRIES above
the MAKE_GUI sub.
Code:
' ------------------
SUB CLEAR_ENTRIES
' ------------------
   TEXT(Entry1_, "")
   TEXT(Entry2_, "")
   TEXT(Entry3_, "")
END SUB
Code:
   Clear_btn_ = STOCK("gtk-clear", Btn_width, Btn_height)
   Btn_x = Btn_x - Btn_width - Widget_spacing
   ATTACH(Mainwin_, Clear_btn_, Btn_x, Btn_y)

   CALLBACK(Clear_btn_, CLEAR_ENTRIES)
Compile and run. Enter some data into the blanks. Click "Clear", the data
will erase.

Now we'll add a button, callback and subroutine to "read" the data from the
file, and populate the entries in the gui. Again, button and callback to the
end of MAKE_GUI and the subroutine above MAKE_GUI.
Code:
' ------------------
SUB READ_FROM_FILE
' ------------------
   LOCAL Name$, Age$, Yes$ TYPE STRING
   OPEN Filename$ FOR READING AS Filehandle_
      READLN Name$ FROM Filehandle_
      READLN Age$  FROM Filehandle_
      READLN Yes$  FROM Filehandle_
   CLOSE FILE Filehandle_
   TEXT(Entry1_, Name$)
   TEXT(Entry2_, Age$)
   TEXT(Entry3_, Yes$)
END SUB
Code:
   Read_btn_ = BUTTON("Read Data", Btn_width, Btn_height)
   Btn_x = Btn_x - Btn_width - Widget_spacing
   ATTACH(Mainwin_, Clear_btn_, Btn_x, Btn_y)

   CALLBACK(Read_btn_, READ_DATA)
Compile and run. Now you can enter and save data. Clear the data fields and
read and display previously saved data.

This is pretty much Straight Up no frills File I/O. For saving and reading a
few pieces of data, it works fine. For a larger number of fields, a loop of
some sort will make more sense.

*Note: All ENTRY fields are text or string data. That means that even numbers are
GRABed from and ENTRY and treated as text or string data. However! Your program
can write a "number" to a file. But! when you read it in, you read it in as a
string variable and if necessary convert it back to a number with VAL(Var$).

rod
file-io.png
 Description   
 Filesize   14.63 KB
 Viewed   980 Time(s)

file-io.png

file_io.tar.gz
Description  file i/o source
gz

 Download 
Filename  file_io.tar.gz 
Filesize  938 Bytes 
Downloaded  303 Time(s) 
Back to top
View user's profile Send private message 
Volhout


Joined: 28 Dec 2008
Posts: 410

PostPosted: Mon 05 Sep 2011, 08:47    Post subject:
Subject description: Passing strings
 

[i]I am trying to write a BaCon glue layer to the FTDI (USB serial port) chip. I plan to use this chip in bitbang mode to get 8 individual IO pins.

I managed to connect to the chip, to write data out, and to read data back. Problem is that each write or read takes 1 msecond.
I want to test if sending out multiple bytes in 1 write command achieves a faster throughput. The C-code header file allows this.

test program:

'-------------------------------------------------------------
'
' program to test the driver glue layer in ftdi_drv.bac
'
' 2011-09-02 Harm de Leeuw
'--------------------------------------------------------------

INCLUDE "ftdi_drv.bac"

LOCAL data TYPE unsigned char
LOCAL mask TYPE unsigned char

PRINT "connect to USB module with FT245BM"
mask = 0xFF
ft245bm_open (mask)
PRINT "device connected, enabling bitbang mode"

'PRINT "start banging"
'FOR data = 0 TO 254
' ft245bm_poke (data)
' PRINT RIGHT$(HEX$(ft245bm_peek()),2)
'NEXT data
'PRINT "stop banging, disable bitbang mode"

'trigger
ft245bm_poke (0xFF)
ft245bm_poke (0x00)
ft245bm_poke (0xFF)

'test
PRINT "start printing string"
g$="2"
ft245bm_print (g$)
PRINT "done, closing down"

INPUT a

ft245bm_close ()

END





My glue layer -------------------------------------------------------

'---------------------------------------------------------------------------
' BaCon driver for FTDI USB-SERIAL convertor chips. Uses compiled libraries
' from FTDI : libftdi-0.19. When compiled (./configure, make, make install)
' this library generates libftdi.so.1
' 2011-09-02 Harm de Leeuw
'---------------------------------------------------------------------------
' Version
' 0.1 Supports open(mask), poke(byte), and close()
' 0.2 Added peek() function
'---------------------------------------------------------------------------
TRAP LOCAL

' Import some calls first
CONST library$ = "libftdi.so.1"

' Get the functions from the library
IMPORT ftdi_init(long) FROM library$ TYPE int
IMPORT ftdi_usb_open(long,int,int) FROM library$ TYPE int
IMPORT ftdi_get_error_string(long) FROM library$ TYPE char* ALIAS ftdi_get_error_string$
IMPORT ftdi_read_chipid(long,long) FROM library$ TYPE int
IMPORT ftdi_usb_close(long) FROM library$ TYPE int
IMPORT ftdi_deinit(long) FROM library$ TYPE void
IMPORT ftdi_write_data(long,long,int) FROM library$ TYPE int
IMPORT ftdi_set_bitmode(long,unsigned char,unsigned char) FROM library$ TYPE int
IMPORT ftdi_disable_bitbang(long) FROM library$ TYPE int
IMPORT ftdi_usb_get_strings(long,long,long,int,long,int,long,int) FROM library$ TYPE int
IMPORT ftdi_read_pins(long,long) FROM library$ TYPE int

CONST TYPE_AM = 0
CONST TYPE_BM = 1
CONST TYPE_2232C = 2
CONST TYPE_R = 3
CONST TYPE_2232H = 4
CONST TYPE_4232H = 5

CONST BITMODE = 0x01

' BaCon does not know types so we define
' a RECORD with the needed members
RECORD ftdic
' USB specific
LOCAL usb_dev TYPE long
LOCAL usb_read_timeout TYPE int
LOCAL usb_write_timeout TYPE int
' FTDI specific
LOCAL type TYPE int
LOCAL baudrate TYPE int
LOCAL bitbang_enabled TYPE unsigned char
LOCAL *readbuffer TYPE unsigned char
LOCAL readbuffer_offset TYPE unsigned int
LOCAL readbuffer_remaining TYPE unsigned int
LOCAL readbuffer_chunksize TYPE unsigned int
LOCAL writebuffer_chunksize TYPE unsigned int
LOCAL max_packet_size TYPE unsigned int
' FTDI FT2232C requirecments
LOCAL interface TYPE int
LOCAL index TYPE int
' Endpoints
LOCAL in_ep TYPE int
LOCAL out_ep TYPE int
' General
LOCAL bitbang_mode TYPE unsigned char
LOCAL eeprom_size TYPE int
LOCAL error_str TYPE char*
LOCAL async_usb_buffer TYPE char*
LOCAL async_usb_buffer_size TYPE unsigned int
END RECORD

'-----------------------------------------------------------------------
SUB ft245bm_open (unsigned char io_mask)
'-----------------------------------------------------------------------
' this function initializes the FTDI 245 BM chip attached to the USB bus
' of the PC in bitbang mode (8 bit wide IO port). The io_mask define the
' data direction ("1"=out, "0"=in).
' timing: every byte write takes 1 milisecond, regardless CPU speed.

IF ftdi_init(ADDRESS(ftdic)) < 0 THEN
PRINT "ftdi_init failed"
END 1
END IF
ret = ftdi_usb_open(ADDRESS(ftdic), 0x0403, 0x6001)
IF ret < 0 THEN
PRINT "unable to open ftdi device: ", ret, " (", ftdi_get_error_string$(ADDRESS(ftdic)), ")"
END 1
END IF
ret = ftdi_set_bitmode(ADDRESS(ftdic), io_mask, BITMODE)
IF ret < 0 THEN
PRINT "unable to set bitmode: ", ret, " (", ftdi_get_error_string$(ADDRESS(ftdic)), ")"
END 1
END IF
END SUB

'-----------------------------------------------------------------------
SUB ft245bm_poke (unsigned char data)
'-----------------------------------------------------------------------
' this function sends out a byte to the 8 bit wide io port of the ftdi
' 245bm chip. The actual data output is masked by the io_mask set in
' the init command.
ret = ftdi_write_data(ADDRESS(ftdic), ADDRESS(data), 1)
IF ret < 0 THEN
PRINT "unable to write: ", ret, " (", ftdi_get_error_string$(ADDRESS(ftdic)), ")"
END 1
END IF
END SUB


'-----------------------------------------------------------------------
SUB ft245bm_close ()
'-----------------------------------------------------------------------
' this function disconnects the ftdi 245bm chip from the USB bus.
' first bitbang mode is disabled, putting the io pins in tristate.
ret = ftdi_disable_bitbang(ADDRESS(ftdic))
IF ret < 0 THEN
PRINT "unable to close ftdi device: ", ret, " (", ftdi_get_error_string$(ADDRESS(ftdic)), ")"
END 1
END IF
ret = ftdi_usb_close(ADDRESS(ftdic))
IF ret < 0 THEN
PRINT "unable to close ftdi device: ", ret, " (", ftdi_get_error_string$(ADDRESS(ftdic)), ")"
END 1
END IF
ftdi_deinit(ADDRESS(ftdic))
END SUB

'-----------------------------------------------------------------------
FUNCTION ft245bm_peek () TYPE unsigned char
'-----------------------------------------------------------------------
' this function reads the 8 io pins from the ftdi 245bm chip, and returns
' the value. The value read is depending on the mask set when opening the
' connection.
LOCAL data TYPE unsigned char
ret = ftdi_read_pins(ADDRESS(ftdic), ADDRESS(data))
IF ret < 0 THEN
PRINT "unable to read: ", ret, " (", ftdi_get_error_string$(ADDRESS(ftdic)), ")"
END 1
END IF
RETURN data
END FUNCTION

' *** TEST ***
'-----------------------------------------------------------------------
SUB ft245bm_print (STRING data)
'-----------------------------------------------------------------------
' this function sends out a string of bytes byte to the 8 bit wide io
' port of the ftdi ' 245bm chip. The actual data output is masked by
' the io_mask set in the init command by the chip.
LOCAL len TYPE int
len = LEN(data)
PRINT len
PRINT data FORMAT "%s"
ret = ftdi_write_data(ADDRESS(ftdic), data, len)
IF ret < 0 THEN
PRINT "unable to write: ", ret, " (", ftdi_get_error_string$(ADDRESS(ftdic)), ")"
END 1
END IF
END SUB
' *** TEST ***

'-----------------------------------------------------------------------




The void that does not work is ft245bm_print. In the line

ret = ftdi_write_data(ADDRESS(ftdic), data, len)

I get a compiler error that data is converted from pointer to integer. Whereas I defined data as a string. Even if I replace

data

with

ADDRESS(data)

it does not work.

Any idea's ??
Back to top
View user's profile Send private message 
GatorDog


Joined: 12 Sep 2006
Posts: 136

PostPosted: Tue 06 Sep 2011, 18:42    Post subject:  

This does look interesting, and I'd like to be able to do it myself.
Hopefully someone with some experience with this will check in.

rod
Back to top
View user's profile Send private message 
PjotAwake


Joined: 03 Nov 2010
Posts: 34
Location: The Hague, The Netherlands

PostPosted: Thu 08 Sep 2011, 18:29    Post subject:  

Hi Volhout,

Quote:

I get a compiler error that data is converted from pointer to integer. Whereas I defined data as a string.


The problem is in the IMPORT definition of 'ftdi_write_data'. This is defined as follows:

Code:

IMPORT ftdi_write_data(long,long,int) FROM library$ TYPE int


As you can see, BaCon now expects the second argument to be a 'long' while you are trying to send a string.

The issue is solved when this definition is corrected. Also according to these docs the second argument should be a string. Therefore, change the IMPORT into the following:

Code:

IMPORT ftdi_write_data(long,char*,int) FROM library$ TYPE int


Of course, you need to remove the ADDRESS construct from the second argument if you invoke this function, and also change the 'ft245bm_poke' function. Its argument should be a STRING also, and should be invoked as follows:

Code:

ft245bm_poke (CHR$(0xFF))
ft245bm_poke (CHR$(0))
ft245bm_poke (CHR$(0xFF))


Now compilation will work.

M.vr.grt,
Peter
Back to top
View user's profile Send private message Visit poster's website 
ICQ Number 
Volhout


Joined: 28 Dec 2008
Posts: 410

PostPosted: Fri 09 Sep 2011, 09:32    Post subject:  

Hi Peter,

Thanks for your help. It compiles now, and it actually works. GREAT !!
I think I was lucky that the poke worked

Final goal is to implement I2C through this interface, and the functions that I have now are sufficient to do I2C writes, and with carefull design, even I2C ACK. Still need to think about I2C read . If I bitbang that then it will be terribly slow.

Thanks for your help,

Volhout
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5042
Location: Arizona, U.S.A.

PostPosted: Sat 10 Sep 2011, 23:56    Post subject: Searched for notebook example.  

##### SOLVED #####

Searched but didn`t find any examples of how to use it.
TEXT creates a new tab, and I assumed new widgets go on the new panel.
The list boxes on the panels are good, but the buttons are off the bottom.
Code:
tab0_ = NOTEBOOK("Debian Packages",tabW,tabH) : ATTACH(winMAIN_,tab0_,tabX,tabY)
lstGRPS_ = LIST(lstGrpsW,lstH) : ATTACH(tab0_,lstGRPS_,lstGrpsX,allY) : CALLBACK(lstGRPS_,lstGRPS)

lstPKGS_ = LIST(lstPkgsW,lstH) : ATTACH(tab0_,lstPKGS_,lstPkgsX,allY) : CALLBACK(lstPKGS_,lstPKGS)

btnBIN_ = BUTTON(INTL$("Binary"),90,btnH) : ATTACH(tab0_,btnBIN_,btnBinX,btnY) : CALLBACK(btnBIN_,btnBIN)

btnSRC_ = BUTTON(INTL$("Source"),90,btnH) : ATTACH(tab0_,btnSRC_,btnSrcX,btnY) : CALLBACK(btnSRC_,btnSRC)

btnQUIT_ = BUTTON(INTL$("Quit"),60,btnH) : ATTACH(tab0_,btnQUIT_,btnQuitX,btnY) : CALLBACK(btnQUIT_,QUIT)

TEXT(tab0_,"Package Info.")
edINFO_ = EDIT(edInfoW,edInfoH) : ATTACH(tab0_,edINFO_,edInfoX,allY)
DISPLAY

The geometry is mostly variables, but you can see what I`ve done.
Thanks GatorDog... Terry
Back to top
View user's profile Send private message 
GatorDog


Joined: 12 Sep 2006
Posts: 136

PostPosted: Sun 11 Sep 2011, 23:06    Post subject:  

Quote:
TEXT creates a new tab, and I assumed new widgets go on the new panel.

Yes. Attaching new widgets to a tab goes on the currently active tab. If you want
to place something on a previously created tab, you first need to select the tab
with, for ex. SET(tab0_, n). (The first tab being "0" zero).

If you haven't tried bacon3G yet, give it a go. (Gators Gui Guide for HUG).
For example under "Widgets", scroll down to Notebook, and see-
Code:
NOTEBOOK
Notebook_ = NOTEBOOK("caption", xsize, ysize)

Creates a notebook with one tab containing a caption, and a width of xsize
  and a height of ysize.

A notebook tab is treated as a window, that is you can directly attach
  widgets to it. In essence, notebook tabs are a collection of windows.

- Attach tab to your main widow - ATTACH(Mainwin_, Notebook_, xpos, ypos)

- Add another tab - TEXT(Notebook_, "New tab name")

- Add a widget to the current tab - ATTACH(Notebook_, Widget_, xpos, ypos)

- Get caption in the active tab - Var$ = GRAB$(Notebook_)

- Get current tab number - Var = GET(Notebook_)

- Set current tab to, (first tab is zero) - SET(Notebook_, n)

- You either populate a tab immediately after defining it or you will have to
  set the tab as the current tab with SET(Notebook_, n) before populating it.

As you'll see, it's an attempt to pull the information for HUG widgets together.
There are some examples for using widgets like the MSGDIALOG.
Preview of the gtk-stock buttons and a color chart with hex code and color
names. I keep it handy while I'm makin' Bacon' Wink

The attached is the source and a compiled (standalone) version of bacon3G.

rod
bacon3g.tar.gz
Description  bacon3G source and standalone bin
gz

 Download 
Filename  bacon3g.tar.gz 
Filesize  82.54 KB 
Downloaded  280 Time(s) 
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5042
Location: Arizona, U.S.A.

PostPosted: Mon 12 Sep 2011, 00:05    Post subject:  

Just dnlded it as soon as I saw it... Another Q here.

Compile gives error: Could not parse line. ( At the first CASE )
Code:
                     ' error messages
SUB errMSG(STRING Err$)
   SELECT Err$
      CASE "pet"
         Msg$ = "ERROR: Failed making .pet package!"
      CASE "squ"
         Msg$ = "ERROR: Failed making .sfs package!"
      CASE "sqa"
         Msg$ = "ERROR: Failed making .sq(n) package!"
   END SELECT
   TEXT(msgERR_,Msg$)
   SHOW(msgERR_)
END SUB
                     ' make Puppy ".pet" package
SUB btnPET
   SYSTEM pkg2pet inDir$ outFile$
   IF RETVAL > 0 THEN errMSG "pet"
END SUB

The calling sub is at the bottom.
The SELECT statement looks just like the one in the BaCon docs.!

Apparently you can`t "one line" the: CASE "pet" : Msg$ = "ERROR: ...

I`m still a little vague about passing variables ( "pet" > Err$ ).
Is what I have correct? Or do I: Err = "pet" and then call: errMSG ?

And do I need to hide the MSGDIALOG before or after I make it?

Thanks...

Last edited by sunburnt on Mon 12 Sep 2011, 00:29; edited 4 times in total
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5042
Location: Arizona, U.S.A.

PostPosted: Mon 12 Sep 2011, 00:20    Post subject:  

GatorDog; Your Bacon3G has missing icons.

BTN 2 "Discard", BTN 3 All below "Zoom In" "Zoom Out" "Best Fit".

But maybe they`re just missing on my PC...

It looks like there`s another tab to the right of MEMO, but it`s off the GUI.

Looks really useful, thanks for the effort on your part.!
Thought I`d tell you... Terry
Back to top
View user's profile Send private message 
GatorDog


Joined: 12 Sep 2006
Posts: 136

PostPosted: Mon 12 Sep 2011, 01:20    Post subject:  

Hi sunburnt,
sunburnt wrote:
GatorDog; Your Bacon3G has missing icons.

BTN 2 "Discard", BTN 3 All below "Zoom In" "Zoom Out" "Best Fit".

Missing for me also. I don't know if they are missing in Puppy or there's a problem with gtk Question
I included them so it can be seen first off that the icon isn't working; rather than finding it out over and over again the hard way.
Quote:
It looks like there`s another tab to the right of MEMO, but it`s off the GUI.

Ok thanks for feedback. Did you by chance recompile and change the font size or dpi?
I used the sizes that Barry recommended for use in Puppy, which seems to work well for me.
ie. HUGOPTIONS("BASEXFTDPI 78") and HUGOPTIONS("FONT DejaVu Sans 12")
I think the reason Barry came up with those HUGOPTIONS is so that a GUI would
look good regardless of what "theme" the user is running.
But it would be good to know if there is a problem with them.

You can change "CONST Mainwin_width = 525" to something a little wider (550 for example)
and recompile. Be sure to use at least Bacon beta 24 and hug 61 from a previous post above
or grab the latest beta's from here. Although it doesn't look like HUG is in the beta dir right now.
Or I can recompile one for you with a wider setting.

rod
Back to top
View user's profile Send private message 
GatorDog


Joined: 12 Sep 2006
Posts: 136

PostPosted: Mon 12 Sep 2011, 01:32    Post subject:  

Terry,
Quote:
Compile gives error: Could not parse line. ( At the first CASE )
Try changing
Code:
   IF RETVAL > 0 THEN errMSG "pet"
to
Code:
   IF RETVAL > 0 THEN errMSG( "pet" )

- add "(" and ")"

rod
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5042
Location: Arizona, U.S.A.

PostPosted: Mon 12 Sep 2011, 12:22    Post subject:  

Ahhh yes... "Passing an argument" is different for subs than for running files.
Different syntax () for the same thing, both are position dependent I assume?

Another problem with the same set of subs:

SYSTEM "pkg2pet" inDir$ outFile$

# Cause: expected ')' before inDir$

Again, this looks exactly like the Bacon docs.
Thanks one more time!
Back to top
View user's profile Send private message 
GatorDog


Joined: 12 Sep 2006
Posts: 136

PostPosted: Mon 12 Sep 2011, 14:33    Post subject:  

Code:
SYSTEM "pkg2pet" inDir$ outFile$
For that I think you'll need something like:
Code:
myCmd$ = CONCAT$("pkg2pet", " ", inDir$, " ", outFile$ )
SYSTEM myCmd$

rod
add-
In this case, I think this will work also:
Code:
SYSTEM CONCAT$("pkg2pet", " ", inDir$, " ", outFile$ )
But generally I've been trying not to get carried away with making long compounded statements.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 4 of 12 [168 Posts]   Goto page: Previous 1, 2, 3, 4, 5, 6, ..., 10, 11, 12 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1841s ][ Queries: 13 (0.0116s) ][ GZIP on ]