
set MAX_ENTRY 10

proc smenu_loop {widget line} {
	global VERSION
	global SYSINFO
	global MAX_ENTRY
		if {[string match "SYSINFO:*" $line]} {
			set SYSINFO [lrange [split $line ":"] 1 end]
			set VERSION [lindex [split $SYSINFO "/"] 3]
			wm title . "RCOPEN24 Serial-Menu ($SYSINFO)"

			catch {eval $widget.bl configure -text \"$SYSINFO\"}

		} elseif {[string match "MT:*:*" $line]} {
			set STAT [lindex [split $line ":"] 1]
			set TITLE [lindex [split $line ":"] 2]
			eval $widget.frame_list.space configure -text \"TX: $TITLE ($STAT)\"

			set N [expr $MAX_ENTRY + 1]
			while {$N < 10} {
				catch {
					eval $widget.frame_list.me$N.n configure -text \"\"
					eval $widget.frame_list.me$N.v configure -text \"\"
					eval $widget.frame_list.me$N.n configure -relief flat
					eval $widget.frame_list.me$N.s configure -relief flat
					eval $widget.frame_list.me$N.v configure -relief flat
				}
				incr N
			}
			set MAX_ENTRY 0

		} elseif {[string match "RMT:*:*" $line]} {
			set STAT [lindex [split $line ":"] 1]
			set TITLE [lindex [split $line ":"] 2]
			eval $widget.frame_list.space configure -text \"RX: $TITLE ($STAT)\"

			set N [expr $MAX_ENTRY + 1]
			while {$N < 10} {
				catch {
					eval $widget.frame_list.me$N.n configure -text \"\"
					eval $widget.frame_list.me$N.v configure -text \"\"
					eval $widget.frame_list.me$N.n configure -relief flat
					eval $widget.frame_list.me$N.s configure -relief flat
					eval $widget.frame_list.me$N.v configure -relief flat
				}
				incr N
			}
			set MAX_ENTRY 0

		} elseif {[string match "ME:*:*" $line]} {
			set TEXT [lindex [split [lrange [split $line ":"] 2 end] "="] 0]
			set VALUE [lrange [split [lrange [split $line ":"] 2 end] "="] 1 end]
			set ID [lindex [split $line ":"] 1]
			set MAX_ENTRY $ID
			if {[lindex $TEXT 0] == " "} {
				set TEXT "";
			}
			catch {
				eval $widget.frame_list.me$ID.n configure -text \"$TEXT\"
				eval $widget.frame_list.me$ID.v configure -text \"$VALUE\"
			}

#			.mainframe.a.menu.screen itemconfigure a.menu[expr $ID + 1] -text "$TEXT $VALUE"

			if {[string match ">*" $TEXT]} {
				set N 0
				while {$N < 10} {
					catch {
						eval $widget.frame_list.me$N.n configure -relief flat
						eval $widget.frame_list.me$N.s configure -relief flat
						eval $widget.frame_list.me$N.v configure -relief flat
					}
					incr N
				}
				catch {
					eval $widget.frame_list.me$ID.n configure -relief raised
					eval $widget.frame_list.me$ID.s configure -relief raised
					eval $widget.frame_list.me$ID.v configure -relief raised
				}
			}
		}
}


proc smenu_init {widget} {

	frame $widget -border 5 -relief sunken
	pack $widget -side top -fill none -expand no

	frame $widget.frame_list
	pack $widget.frame_list -side top -fill x

		label $widget.frame_list.space -text ""
		pack $widget.frame_list.space -side top -fill x -expand yes

		set N 0
		while {$N < 10} {
			frame $widget.frame_list.me$N
			pack $widget.frame_list.me$N -side top -fill x

				label $widget.frame_list.me$N.n -text "" -border 1
				pack $widget.frame_list.me$N.n -side left -fill x -expand no

				label $widget.frame_list.me$N.s -text "" -border 1
				pack $widget.frame_list.me$N.s -side left -fill x -expand yes

				label $widget.frame_list.me$N.v -text "" -border 1
				pack $widget.frame_list.me$N.v -side right -fill x -expand no

			incr N
		}

	frame $widget.frameB
	pack $widget.frameB -side top -fill both -expand yes

		button $widget.frameB.m -text "Left" -border 1 -command {
			send_cmd "1"
		}
		pack $widget.frameB.m -side left -fill both -expand yes

		frame $widget.frameB.frame3
		pack $widget.frameB.frame3 -side left -fill both -expand yes
	
			button $widget.frameB.frame3.up -text "Up" -border 1 -command {
				send_cmd "8"
			}
			pack $widget.frameB.frame3.up -side top -fill both -expand yes
	
			button $widget.frameB.frame3.down -text "Down" -border 1 -command {
				send_cmd "2"
			}
			pack $widget.frameB.frame3.down -side bottom -fill both -expand yes
	
			button $widget.frameB.frame3.left -text "-" -border 1 -command {
				send_cmd "4"
			}
			pack $widget.frameB.frame3.left -side left -fill x -expand yes
	
			button $widget.frameB.frame3.lr -text "L/R" -border 1 -command {
				send_cmd "5"
			}
			pack $widget.frameB.frame3.lr -side left -fill x -expand yes
	
			button $widget.frameB.frame3.right -text "+" -border 1 -command {
				send_cmd "6"
			}
			pack $widget.frameB.frame3.right -side right -fill x -expand yes

			button $widget.frameB.p -text "Right" -border 1 -command {
				send_cmd "3"
			}
			pack $widget.frameB.p -side right -fill both -expand yes

		label $widget.bl -text "--" -border 1 -relief sunken
		pack $widget.bl -side bottom -fill both -expand yes

}


