' Floating-point viewer with segment LED
' Copyright (c) 2012 Nonki Takahashi. All right reserved.
'
' History :
' 0.1 2012/07/16 Created.
'
GraphicsWindow.Title = "Floating-point viewer 0.1"
GraphicsWindow.BackgroundColor = "Silver"
nFrac = 6 ' number of fractional digits
nExp = 2 ' number of exponential digits
x = 10 ' left position for segment LED
y = 10 ' top position for segment LED
w = 30 ' width of one segment LED
h = 60 ' height of segment LED
nDigits = nFrac + nExp + 4 ' 3 for a decimal point, E and two signs
GraphicsWindow.Width = 2 * x + nDigits * w
GraphicsWindow.Height = 3 * y + h + 20 ' 20 means height of textbox
GraphicsWindow.BrushColor = "Black"
oNum = Controls.AddTextBox(x, 2 * y + h)
InitLED()
digits = Array.GetAllIndices(seg)
Stack.PushValue("local", x)
For i = 1 To nDigits
n = digits[i]
DrawLED()
x = x + w
EndFor
x = Stack.PopValue("local")
typed = "False"
Controls.TextTyped = OnTextTyped
While "True"
If typed Then
typed = "False"
num = Controls.GetTextBoxText(oNum)
If Text.GetLength(num) > nDigits Then
Num2FP()
DrawFP()
Else
DrawNum()
EndIf
EndIf
EndWhile
Sub DrawLED
' param x, y - position
' param w, h - size
' param n - number 0..9
Stack.PushValue("local", i)
GraphicsWindow.BrushColor = clrLED["Base"]
GraphicsWindow.FillRectangle(x, y, w, h)
GraphicsWindow.BrushColor = clrLED["Off"]
For i = 1 To nSegs
If seg[n][segNames[i]] Then
GraphicsWindow.BrushColor = clrLED["On"]
Else
GraphicsWindow.BrushColor = clrLED["Off"]
EndIf
xs = x + segPos[segNames[i]]["x"] * w
ys = y + segPos[segNames[i]]["y"] * h
ws = w * segPos[segNames[i]]["w"]
hs = h * segPos[segNames[i]]["h"]
GraphicsWindow.FillRectangle(xs, ys, ws, hs)
EndFor
i = Stack.PopValue("local")
EndSub
Sub DrawNum
' param num
len = Text.GetLength(num)
If len > nDigits Then
num = "ERR1" ' Error 1 : overflow
TextWindow.WriteLine("ERR2:len=" + len)
len = 4
EndIf
Stack.PushValue("local", x)
For i = 1 To len
n = Text.GetSubText(num, i, 1)
DrawLED()
x = x + w
EndFor
For i = len + 1 To nDigits
n = ""
DrawLED()
x = x + w
EndFor
x = Stack.PopValue("local")
EndSub
Sub DrawFP
' param fp - floating point number
Stack.PushValue("local", num)
num = fp
DrawNum()
num = Stack.PopValue("local")
EndSub