• We just launched and are currently in beta. Join us as we build and grow the community.

Android Oscillator Application Using Basic4Android - Tutorial Part 2

Horizzon

Crash Log Analyst
H Rep
0
0
0
Rep
0
H Vouches
0
0
0
Vouches
0
Posts
87
Likes
99
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
This is the 2nd part of my tutorial in creating an Oscillator Application in Android.

Note that in the first part we haven't initialized to make a grid as a background to our curves. So here is the code for that.

  1. Sub

    InitGrid
  2. Dim

    i As

    Int
  3. Dim

    x, y As

    Float

  4. cvsScreen.DrawRect(rectScreen, ScreenCol, True

    , 1)
  5. For

    i = 0 To

    NbDivY
  6. y = GridX0 + i * Div
  7. cvsScreen.DrawLine(GridX0, y, GridX1, y, GridLineCol, 1dip)
  8. Next

  9. For

    i = 0 To

    NbDivX
  10. x = GridY0 + i * Div
  11. cvsScreen.DrawLine(x, GridY0, x, GridY1, GridLineCol, 1dip)
  12. Next
  13. pnlScreen.Invalidate

  14. cvsGraph.DrawRect(rectGrid, Colors.Transparent, True

    , 1)
  15. pnlGraph.Invalidate

  16. cvsCursor.DrawRect(rectGrid, Colors.Transparent, True

    , 1)
  17. pnlCursor.Invalidate
  18. End

    Sub

After initializing our grid as the background of our curves. We will also initialize a cursor in the panel that can be touched. Follow the code below:
  1. Sub

    pnlCursor_Touch (Action As

    Int, X As

    Float, Y As

    Float) As

    Boolean

    'Return True to consume the event
  2. If

    Stopped = False

    Then
  3. Return
  4. End

    If

  5. Select

    Action
  6. Case

    Activity.ACTION_DOWN
  7. pnlDispValues.Visible = True
  8. cx = X
  9. If

    X >= 0 AND

    X <= GridW Then
  10. DrawCursor(X)
  11. DispValues(X)
  12. End

    If
  13. Case

    Activity.ACTION_MOVE
  14. If

    X >= 0 AND

    X <= GridW Then
  15. DrawCursor(X)
  16. DispValues(X)
  17. End

    If
  18. Case

    Activity.ACTION_UP
  19. cvsCursor.DrawLine(cx, 0, cx, GridH, Colors.Transparent, 1)
  20. pnlCursor.Invalidate
  21. pnlDispValues.Visible = False
  22. End

    Select
  23. Return True
  24. End

    Sub

Then, we shall code for our spinners in the Scale, TimeScale, and the SignalScale for the change of values to our curves. Type the code below:

  1. Sub

    spnTimeScale_ItemClick (Position As

    Int, Value As

    Object

    )
  2. dt = Value / 10
  3. t = 0
  4. Timer1.Initialize("Timer1"

    , dt * 1000)
  5. End

    Sub

  6. Sub

    spnScale_ItemClick (Position As

    Int, Value As

    Object

    )
  7. Dim

    spn As

    Spinner

  8. spn = Sender
  9. Curve(spn.Tag).Scale = Div / Value
  10. End

    Sub

Next we will code for our RadiobuttonScale. Here's the code below:

  1. Sub

    rbtScope_CheckedChange(Checked As

    Boolean

    )
  2. Dim

    rbt As

    RadioButton

  3. btnStop_Click
  4. rbt = Sender
  5. ScopeMode = rbt.Tag
  6. btnStart_Click
  7. End

    Sub

We will code also for our textbox if the curves will change its scale for the offset. Type this one:
  1. Sub

    edtOffset_FocusChanged (HasFocus As

    Boolean

    )
  2. Dim

    edt As

    EditText
  3. Dim

    val As

    Double

  4. If

    HasFocus = False

    Then
  5. edt = Sender
  6. Curve(edt.Tag).Offset = edt.Text
  7. End

    If
  8. End

    Sub

Next, we will now put an Event Name in our three buttons for the btnStart, btnStop, and btnSingleShot. In the btnStart, once the user will click this button, it will automatically start the curves to cast signal. This is the code for that:
  1. Sub

    btnStart_Click
  2. Timer1.Enabled = True
  3. SingleShot = False
  4. Stopped = False
  5. ii = -1
  6. xx = -dx
  7. EraseCurves
  8. End

    Sub

Then this is the code for the stopping the curves to move:

  1. Sub

    btnStop_Click
  2. Timer1.Enabled = False
  3. SingleShot = False
  4. Stopped = True
  5. End

    Sub

And this one is for the single shot to make the only one curves showed in the Oscillator:
  1. Sub

    btnSingleShot_Click
  2. Timer1.Enabled = True
  3. SingleShot = True
  4. Stopped = False
  5. ii = -1
  6. xx = -dx
  7. EraseCurves
  8. End

    Sub

And to fully end this tutorial, we will have our Activity_Create code:

  1. Sub

    Activity_Create(FirstTime As

    Boolean

    )

  2. dt = 0.01
  3. t = 0
  4. Timer1.Initialize("Timer1"

    , dt * 1000)

  5. NbDivX = 10
  6. NbDivY = 8

  7. Div = Floor(80%y / NbDivY)
  8. xx = 0
  9. dx = Div / 10
  10. GridW = Div * NbDivX
  11. GridH = Div * NbDivY
  12. Border = 6dip

  13. ScreenY0 = 0
  14. ScreenH = GridH + 2 * Border
  15. ScreenY1 = ScreenY0 + ScreenH

  16. ScreenX0 = 0
  17. ScreenW = GridW + 2 * Border
  18. ScreenX1 = ScreenX0 + ScreenW

  19. GridY0 = Border
  20. GridY1 = GridY0 + GridH
  21. GridX0 = Border
  22. GridX1 = GridX0 + GridW
  23. GridYm = GridH / 2

  24. rectGrid.Initialize(0, 0, GridW, GridH)
  25. rectScreen.Initialize(0, 0, ScreenW, ScreenH)

  26. ScreenCol = Colors.White
  27. GridLineCol = Colors.Gray

  28. pnlOcilloscope.Initialize(""

    )
  29. Activity.AddView(pnlOcilloscope, 0, 0, 100%x, 100%y)

  30. pnlScreen.Initialize(""

    )
  31. pnlOcilloscope.AddView(pnlScreen, ScreenX0, ScreenY0, ScreenW, ScreenH)
  32. cvsScreen.Initialize(pnlScreen)

  33. pnlGraph.Initialize(""

    )
  34. pnlOcilloscope.AddView(pnlGraph, GridX0, GridY0, GridW, GridH)
  35. cvsGraph.Initialize(pnlGraph)

  36. pnlCursor.Initialize("pnlCursor"

    )
  37. pnlOcilloscope.AddView(pnlCursor, GridX0, GridY0, GridW, GridH)
  38. cvsCursor.Initialize(pnlCursor)

  39. pnlControl.Initialize(""

    )
  40. Activity.AddView(pnlControl, ScreenX1, 0, 100%x - ScreenX1, 54dip)
  41. Dim

    cbg As

    ColorDrawable
  42. cbg.Initialize(Colors.RGB(255, 196, 196), 0)
  43. pnlControl.Background = cbg

  44. Dim

    w1, w2, w3, t1, h1 As

    Int
  45. w1 = 4dip
  46. w2 = (pnlControl.Width - 4 * w1) / 3
  47. w3 = w1 + w2
  48. t1 = 4dip
  49. h1 = 52dip
  50. btnStart.Initialize("btnStart"

    )
  51. pnlControl.AddView(btnStart, w1, t1, w2, h1)
  52. btnStart.Text = "Start"

  53. btnStop.Initialize("btnStop"

    )
  54. pnlControl.AddView(btnStop, w1 + w3, t1, w2, h1)
  55. btnStop.Text = "Stop"

  56. btnSingleShot.Initialize("btnSingleShot"

    )
  57. pnlControl.AddView(btnSingleShot, w1 + 2 * w3, t1, w2, h1)
  58. btnSingleShot.Text = "Single Shot"

  59. scvControl.Initialize(480dip)
  60. pnlOcilloscope.AddView(scvControl, ScreenX1, pnlControl.Height, 100%x - ScreenX1, 100%y - pnlControl.Height)
  61. scvControl.Panel.LoadLayout("controls"

    )
  62. scvControl.Panel.Width = scvControl.Width
  63. Dim

    cbg As

    ColorDrawable
  64. cbg.Initialize(Colors.RGB(196, 196, 255), 0)
  65. scvControl.Panel.Background = cbg
  66. scvControl.Color = Colors.RGB(196, 196, 255)

  67. pnlCurveTools.Initialize(""

    )
  68. pnlOcilloscope.AddView(pnlCurveTools, 0, ScreenY1, ScreenX1, 100%y - ScreenY1)
  69. Dim

    cbg As

    ColorDrawable
  70. cbg.Initialize(Colors.RGB(255, 196, 196), 0)
  71. pnlCurveTools.Background = cbg

  72. pnlDispValues.Initialize(""

    )
  73. pnlOcilloscope.AddView(pnlDispValues, 0, ScreenY1, ScreenX1, 100%y - ScreenY1)
  74. Dim

    cbg As

    ColorDrawable
  75. cbg.Initialize(Colors.RGB(255, 236, 153), 0)
  76. pnlDispValues.Background = cbg
  77. pnlDispValues.Visible = False

  78. InitCurves
  79. InitCalcCurves
  80. InitSpinners

  81. Dim

    ww As

    Float
  82. ww = pnlDispValues.Width / 4
  83. lblValue0.Initialize(""

    )
  84. pnlDispValues.AddView(lblValue0, 0, 0, ww, pnlDispValues.Height)
  85. lblValue0.TextColor = Curve(0).Color
  86. lblValue0.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL

  87. lblValue1.Initialize(""

    )
  88. pnlDispValues.AddView(lblValue1, ww, 0, ww, pnlDispValues.Height)
  89. lblValue1.TextColor = Curve(1).Color
  90. lblValue1.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL

  91. lblValue2.Initialize(""

    )
  92. pnlDispValues.AddView(lblValue2, 2 * ww, 0, ww, pnlDispValues.Height)
  93. lblValue2.TextColor = Curve(2).Color
  94. lblValue2.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL

  95. lblValue3.Initialize(""

    )
  96. pnlDispValues.AddView(lblValue3, 3 * ww, 0, ww, pnlDispValues.Height)
  97. lblValue3.TextColor = Curve(3).Color
  98. lblValue3.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL

  99. For

    i = 0 To

    3
  100. Dim

    cbx As

    CheckBox
  101. cbx.Initialize("cbxDrawCurve"

    )
  102. pnlCurveTools.AddView(cbx, 6dip + i * 66dip, 0, 60dip, 50dip)
  103. cbx.Tag = i
  104. cbx.Text = " "

    & (i + 1)
  105. cbx.Typeface = Typeface.DEFAULT_BOLD
  106. cbx.Color = Curve(i).Color
  107. cbx.Checked = True
  108. Next
  109. lblScale0.Color = Curve(0).Color
  110. lblScale1.Color = Curve(1).Color
  111. lblScale2.Color = Curve(2).Color
  112. lblScale3.Color = Curve(3).Color

  113. lblOffset0.Color = Curve(0).Color
  114. lblOffset1.Color = Curve(1).Color
  115. lblOffset2.Color = Curve(2).Color
  116. lblOffset3.Color = Curve(3).Color

  117. edtOffset0.Text = Curve(0).Offset
  118. edtOffset1.Text = Curve(1).Offset
  119. edtOffset2.Text = Curve(2).Offset
  120. edtOffset3.Text = Curve(3).Offset

  121. Select

    ScopeMode
  122. Case

    "SCOPE"
  123. rbtScopeScope.Checked = True
  124. Case

    "MEM"
  125. rbtScopeMEM.Checked = True
  126. Case

    "ROLL"
  127. rbtScopeROLL.Checked = True
  128. End

    Select
  129. End

    Sub

So here is now our complete code for this tutorial:

  1. 'Activity module
  2. Sub

    Process_Globals
  3. 'These global variables will be declared once when the application starts.
  4. 'These variables can be accessed from all modules.
  5. Dim

    Timer1 As

    Timer
  6. Type

    Curves (Name As

    String

    , Color As

    Int, Width As

    Float, Scale As

    Double

    , Offset As

    Double

    , Draw As

    Boolean

    )
  7. Dim

    CurveVal(4, 101) As

    Double
  8. Dim

    ScreenX0, ScreenX1, ScreenY0, ScreenY1, ScreenW, ScreenH, Border As

    Int
  9. Dim

    GridX0, GridX1, GridY0, GridY1, GridYm, GridW, GridH, Div As

    Int
  10. Dim

    NbDivX, NbDivY As

    Int
  11. Dim

    ScreenCol, GridLineCol As

    Int

  12. Dim

    t, dt As

    Double
  13. Dim

    dx, xx, cx As

    Float
  14. Dim

    ii As

    Int
  15. Dim

    CurveI As

    Int ' curve index
  16. Dim

    Curve(4) As

    Curves
  17. Dim

    CurvesI(4) As

    Int
  18. Dim

    CurvesNb As

    Int : CurvesNb = 3
  19. Dim

    CurvesNbDisp As

    Int
  20. Dim

    y1(4) As

    Float
  21. Dim

    y2(4) As

    Float
  22. Dim

    SingleShot As

    Boolean

    : SingleShot = False
  23. Dim

    Stopped As

    Boolean

    : Stopped = True
  24. Dim

    ScopeMode As

    String

    : ScopeMode = "ROLL"
  25. Dim

    ScopeRolling As

    Boolean

    : ScopeRolling = False
  26. Dim

    w(4) As

    Double
  27. Dim

    a(4) As

    Double
  28. Dim

    TimeScale(10) As

    Double
  29. Dim

    SignalScale(10) As

    Double

  30. End

    Sub

  31. Sub

    Globals
  32. 'These global variables will be redeclared each time the activity is created.
  33. 'These variables can only be accessed from this module.
  34. Dim

    btnStart, btnStop, btnSingleShot As

    Button
  35. Dim

    pnlOcilloscope, pnlScreen, pnlGraph, pnlCursor, pnlControl As

    Panel
  36. Dim

    pnlCurveTools, pnlDispValues As

    Panel
  37. Dim

    cvsScreen, cvsGraph, cvsCursor As

    Canvas
  38. Dim

    rectScreen, rectGrid As

    Rect
  39. Dim

    spnTimeScale As

    Spinner
  40. Dim

    spnScale0, spnScale1, spnScale2, spnScale3 As

    Spinner
  41. Dim

    lblScale0, lblScale1, lblScale2, lblScale3 As

    Label
  42. Dim

    lblValue0, lblValue1, lblValue2, lblValue3 As

    Label
  43. Dim

    lblOffset0, lblOffset1, lblOffset2, lblOffset3 As

    Label
  44. Dim

    edtOffset0, edtOffset1, edtOffset2, edtOffset3 As

    EditText
  45. Dim

    rbtScopeScope, rbtScopeMEM, rbtScopeROLL As

    RadioButton
  46. Dim

    scvControl As

    ScrollView
  47. Dim

    bmpRoll As

    Bitmap
  48. End

    Sub

  49. Sub

    Activity_Create(FirstTime As

    Boolean

    )

  50. dt = 0.01
  51. t = 0
  52. Timer1.Initialize("Timer1"

    , dt * 1000)

  53. NbDivX = 10
  54. NbDivY = 8

  55. Div = Floor(80%y / NbDivY)
  56. xx = 0
  57. dx = Div / 10
  58. GridW = Div * NbDivX
  59. GridH = Div * NbDivY
  60. Border = 6dip

  61. ScreenY0 = 0
  62. ScreenH = GridH + 2 * Border
  63. ScreenY1 = ScreenY0 + ScreenH

  64. ScreenX0 = 0
  65. ScreenW = GridW + 2 * Border
  66. ScreenX1 = ScreenX0 + ScreenW

  67. GridY0 = Border
  68. GridY1 = GridY0 + GridH
  69. GridX0 = Border
  70. GridX1 = GridX0 + GridW
  71. GridYm = GridH / 2

  72. rectGrid.Initialize(0, 0, GridW, GridH)
  73. rectScreen.Initialize(0, 0, ScreenW, ScreenH)

  74. ScreenCol = Colors.White
  75. GridLineCol = Colors.Gray

  76. pnlOcilloscope.Initialize(""

    )
  77. Activity.AddView(pnlOcilloscope, 0, 0, 100%x, 100%y)

  78. pnlScreen.Initialize(""

    )
  79. pnlOcilloscope.AddView(pnlScreen, ScreenX0, ScreenY0, ScreenW, ScreenH)
  80. cvsScreen.Initialize(pnlScreen)

  81. pnlGraph.Initialize(""

    )
  82. pnlOcilloscope.AddView(pnlGraph, GridX0, GridY0, GridW, GridH)
  83. cvsGraph.Initialize(pnlGraph)

  84. pnlCursor.Initialize("pnlCursor"

    )
  85. pnlOcilloscope.AddView(pnlCursor, GridX0, GridY0, GridW, GridH)
  86. cvsCursor.Initialize(pnlCursor)

  87. pnlControl.Initialize(""

    )
  88. Activity.AddView(pnlControl, ScreenX1, 0, 100%x - ScreenX1, 54dip)
  89. Dim

    cbg As

    ColorDrawable
  90. cbg.Initialize(Colors.RGB(255, 196, 196), 0)
  91. pnlControl.Background = cbg

  92. Dim

    w1, w2, w3, t1, h1 As

    Int
  93. w1 = 4dip
  94. w2 = (pnlControl.Width - 4 * w1) / 3
  95. w3 = w1 + w2
  96. t1 = 4dip
  97. h1 = 52dip
  98. btnStart.Initialize("btnStart"

    )
  99. pnlControl.AddView(btnStart, w1, t1, w2, h1)
  100. btnStart.Text = "Start"

  101. btnStop.Initialize("btnStop"

    )
  102. pnlControl.AddView(btnStop, w1 + w3, t1, w2, h1)
  103. btnStop.Text = "Stop"

  104. btnSingleShot.Initialize("btnSingleShot"

    )
  105. pnlControl.AddView(btnSingleShot, w1 + 2 * w3, t1, w2, h1)
  106. btnSingleShot.Text = "Single Shot"

  107. scvControl.Initialize(480dip)
  108. pnlOcilloscope.AddView(scvControl, ScreenX1, pnlControl.Height, 100%x - ScreenX1, 100%y - pnlControl.Height)
  109. scvControl.Panel.LoadLayout("controls"

    )
  110. scvControl.Panel.Width = scvControl.Width
  111. Dim

    cbg As

    ColorDrawable
  112. cbg.Initialize(Colors.RGB(196, 196, 255), 0)
  113. scvControl.Panel.Background = cbg
  114. scvControl.Color = Colors.RGB(196, 196, 255)

  115. pnlCurveTools.Initialize(""

    )
  116. pnlOcilloscope.AddView(pnlCurveTools, 0, ScreenY1, ScreenX1, 100%y - ScreenY1)
  117. Dim

    cbg As

    ColorDrawable
  118. cbg.Initialize(Colors.RGB(255, 196, 196), 0)
  119. pnlCurveTools.Background = cbg

  120. pnlDispValues.Initialize(""

    )
  121. pnlOcilloscope.AddView(pnlDispValues, 0, ScreenY1, ScreenX1, 100%y - ScreenY1)
  122. Dim

    cbg As

    ColorDrawable
  123. cbg.Initialize(Colors.RGB(255, 236, 153), 0)
  124. pnlDispValues.Background = cbg
  125. pnlDispValues.Visible = False

  126. InitCurves
  127. InitCalcCurves
  128. InitSpinners

  129. Dim

    ww As

    Float
  130. ww = pnlDispValues.Width / 4
  131. lblValue0.Initialize(""

    )
  132. pnlDispValues.AddView(lblValue0, 0, 0, ww, pnlDispValues.Height)
  133. lblValue0.TextColor = Curve(0).Color
  134. lblValue0.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL

  135. lblValue1.Initialize(""

    )
  136. pnlDispValues.AddView(lblValue1, ww, 0, ww, pnlDispValues.Height)
  137. lblValue1.TextColor = Curve(1).Color
  138. lblValue1.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL

  139. lblValue2.Initialize(""

    )
  140. pnlDispValues.AddView(lblValue2, 2 * ww, 0, ww, pnlDispValues.Height)
  141. lblValue2.TextColor = Curve(2).Color
  142. lblValue2.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL

  143. lblValue3.Initialize(""

    )
  144. pnlDispValues.AddView(lblValue3, 3 * ww, 0, ww, pnlDispValues.Height)
  145. lblValue3.TextColor = Curve(3).Color
  146. lblValue3.Gravity = Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL

  147. For

    i = 0 To

    3
  148. Dim

    cbx As

    CheckBox
  149. cbx.Initialize("cbxDrawCurve"

    )
  150. pnlCurveTools.AddView(cbx, 6dip + i * 66dip, 0, 60dip, 50dip)
  151. cbx.Tag = i
  152. cbx.Text = " "

    & (i + 1)
  153. cbx.Typeface = Typeface.DEFAULT_BOLD
  154. cbx.Color = Curve(i).Color
  155. cbx.Checked = True
  156. Next
  157. lblScale0.Color = Curve(0).Color
  158. lblScale1.Color = Curve(1).Color
  159. lblScale2.Color = Curve(2).Color
  160. lblScale3.Color = Curve(3).Color

  161. lblOffset0.Color = Curve(0).Color
  162. lblOffset1.Color = Curve(1).Color
  163. lblOffset2.Color = Curve(2).Color
  164. lblOffset3.Color = Curve(3).Color

  165. edtOffset0.Text = Curve(0).Offset
  166. edtOffset1.Text = Curve(1).Offset
  167. edtOffset2.Text = Curve(2).Offset
  168. edtOffset3.Text = Curve(3).Offset

  169. Select

    ScopeMode
  170. Case

    "SCOPE"
  171. rbtScopeScope.Checked = True
  172. Case

    "MEM"
  173. rbtScopeMEM.Checked = True
  174. Case

    "ROLL"
  175. rbtScopeROLL.Checked = True
  176. End

    Select
  177. End

    Sub

  178. Sub

    Activity_Resume
  179. InitGrid
  180. End

    Sub

  181. Sub

    Activity_Pause (UserClosed As

    Boolean

    )
  182. btnStop_Click
  183. End

    Sub

  184. Sub

    InitGrid
  185. Dim

    i As

    Int
  186. Dim

    x, y As

    Float

  187. cvsScreen.DrawRect(rectScreen, ScreenCol, True

    , 1)
  188. For

    i = 0 To

    NbDivY
  189. y = GridX0 + i * Div
  190. cvsScreen.DrawLine(GridX0, y, GridX1, y, GridLineCol, 1dip)
  191. Next

  192. For

    i = 0 To

    NbDivX
  193. x = GridY0 + i * Div
  194. cvsScreen.DrawLine(x, GridY0, x, GridY1, GridLineCol, 1dip)
  195. Next
  196. pnlScreen.Invalidate

  197. cvsGraph.DrawRect(rectGrid, Colors.Transparent, True

    , 1)
  198. pnlGraph.Invalidate

  199. cvsCursor.DrawRect(rectGrid, Colors.Transparent, True

    , 1)
  200. pnlCursor.Invalidate
  201. End

    Sub

  202. Sub

    btnStart_Click
  203. Timer1.Enabled = True
  204. SingleShot = False
  205. Stopped = False
  206. ii = -1
  207. xx = -dx
  208. EraseCurves
  209. End

    Sub

  210. Sub

    btnStop_Click
  211. Timer1.Enabled = False
  212. SingleShot = False
  213. Stopped = True
  214. End

    Sub

  215. Sub

    btnSingleShot_Click
  216. Timer1.Enabled = True
  217. SingleShot = True
  218. Stopped = False
  219. ii = -1
  220. xx = -dx
  221. EraseCurves
  222. End

    Sub

  223. Sub

    spnTimeScale_ItemClick (Position As

    Int, Value As

    Object

    )
  224. dt = Value / 10
  225. t = 0
  226. Timer1.Initialize("Timer1"

    , dt * 1000)
  227. End

    Sub

  228. Sub

    spnScale_ItemClick (Position As

    Int, Value As

    Object

    )
  229. Dim

    spn As

    Spinner

  230. spn = Sender
  231. Curve(spn.Tag).Scale = Div / Value
  232. End

    Sub

  233. Sub

    edtOffset_FocusChanged (HasFocus As

    Boolean

    )
  234. Dim

    edt As

    EditText
  235. Dim

    val As

    Double

  236. If

    HasFocus = False

    Then
  237. edt = Sender
  238. Curve(edt.Tag).Offset = edt.Text
  239. End

    If
  240. End

    Sub

  241. Sub

    rbtScope_CheckedChange(Checked As

    Boolean

    )
  242. Dim

    rbt As

    RadioButton

  243. btnStop_Click
  244. rbt = Sender
  245. ScopeMode = rbt.Tag
  246. btnStart_Click
  247. End

    Sub

  248. Sub

    Timer1_Tick
  249. Dim

    i, j As

    Int

  250. t = t + dt
  251. xx = xx + dx
  252. ii = ii + 1
  253. If

    ii > 100 Then
  254. If

    SingleShot = True

    Then
  255. Timer1.Enabled = False
  256. SingleShot = False
  257. Stopped = True
  258. Return
  259. Else
  260. Select

    ScopeMode
  261. Case

    "MEM"
  262. xx = 0
  263. ii = 0
  264. GetValues
  265. DrawCurves
  266. Case

    "SCOPE"
  267. EraseCurves
  268. xx = 0
  269. ii = 0
  270. GetValues
  271. DrawCurves
  272. Case

    "ROLL"
  273. ii = 100
  274. xx = 100 * dx
  275. For

    i = 0 To

    3
  276. For

    j = 0 To

    99
  277. CurveVal(i, j) = CurveVal(i, j + 1)
  278. Next
  279. Next
  280. ScopeRolling = True
  281. GetValues
  282. DrawCurves
  283. End

    Select
  284. Return
  285. End

    If
  286. End

    If
  287. GetValues
  288. DrawCurves
  289. End

    Sub

  290. Sub

    DrawCurves
  291. Dim

    i, j As

    Int
  292. Dim

    r1, r2 As

    Rect
  293. Dim

    x, yy1(4), yy2(4) As

    Float

  294. If

    SingleShot = False

    Then
  295. Select

    ScopeMode
  296. Case

    "MEM"
  297. r1.Initialize(xx, 0, xx + dx, GridH)
  298. cvsGraph.DrawRect(r1, Colors.Transparent, True

    , 1)
  299. Case

    "ROLL"
  300. If

    ScopeRolling = True

    Then
  301. cvsGraph.DrawRect(rectGrid, Colors.Transparent, True

    , 1)
  302. For

    i = 0 To

    CurvesNb
  303. If

    Curve(i).Draw = True

    Then
  304. yy1(i) = GridYm + (-Curve(i).Offset - CurveVal(i, 0)) * Curve(i).Scale
  305. For

    j = 1 To

    99
  306. x = j * dx
  307. yy2(i) = GridYm + (-Curve(i).Offset - CurveVal(i, j)) * Curve(i).Scale
  308. cvsGraph.DrawLine(x - dx, yy1(i), x, yy2(i), Curve(i).Color, Curve(i).Width)
  309. yy1(i) = yy2(i)
  310. Next
  311. End

    If
  312. Next
  313. End

    If
  314. End

    Select
  315. End

    If
  316. For

    i = 0 To

    CurvesNb
  317. If

    Curve(i).Draw = True

    Then
  318. y2(i) = GridYm + (-Curve(i).Offset - CurveVal(i, ii)) * Curve(i).Scale
  319. If

    ii > 0 Then
  320. cvsGraph.DrawLine(xx - dx, y1(i), xx, y2(i), Curve(i).Color, Curve(i).Width)
  321. End

    If
  322. y1(i) = y2(i)
  323. End

    If
  324. Next
  325. pnlGraph.Invalidate
  326. DoEvents
  327. End

    Sub

  328. Sub

    GetValues
  329. Dim

    i As

    Int

  330. For

    i = 0 To

    CurvesNb
  331. CurveVal(i, ii) = a(i) * Sin(w(i) * t)
  332. Next
  333. End

    Sub

  334. Sub

    EraseCurves
  335. cvsGraph.DrawRect(rectGrid, Colors.Transparent, True

    , 1)
  336. End

    Sub

  337. Sub

    cbxDrawCurve_CheckedChange(Checked As

    Boolean

    )
  338. Dim

    cbx As

    CheckBox
  339. cbx = Sender
  340. Curve(cbx.Tag).Draw = Checked
  341. End

    Sub

  342. Sub

    pnlCursor_Touch (Action As

    Int, X As

    Float, Y As

    Float) As

    Boolean

    'Return True to consume the event
  343. If

    Stopped = False

    Then
  344. Return
  345. End

    If

  346. Select

    Action
  347. Case

    Activity.ACTION_DOWN
  348. pnlDispValues.Visible = True
  349. cx = X
  350. If

    X >= 0 AND

    X <= GridW Then
  351. DrawCursor(X)
  352. DispValues(X)
  353. End

    If
  354. Case

    Activity.ACTION_MOVE
  355. If

    X >= 0 AND

    X <= GridW Then
  356. DrawCursor(X)
  357. DispValues(X)
  358. End

    If
  359. Case

    Activity.ACTION_UP
  360. cvsCursor.DrawLine(cx, 0, cx, GridH, Colors.Transparent, 1)
  361. pnlCursor.Invalidate
  362. pnlDispValues.Visible = False
  363. End

    Select
  364. Return True
  365. End

    Sub

  366. Sub

    DrawCursor(x As

    Float)
  367. cvsCursor.DrawLine(cx, 0, cx, GridH, Colors.Transparent, 1)
  368. cx = x
  369. cvsCursor.DrawLine(cx, 0, cx, GridH, Colors.Red, 1)
  370. pnlCursor.Invalidate
  371. End

    Sub

  372. Sub

    DispValues(x As

    Int)
  373. Dim

    i As

    Int

  374. i = 100 / GridW * x
  375. lblValue0.Text = NumberFormat(CurveVal(0, i), 1, 6)
  376. lblValue1.Text = NumberFormat(CurveVal(1, i), 1, 6)
  377. lblValue2.Text = NumberFormat(CurveVal(2, i), 1, 6)
  378. lblValue3.Text = NumberFormat(CurveVal(3, i), 1, 6)
  379. End

    Sub

  380. Sub

    InitCurves
  381. Curve(0).Color = Colors.Red
  382. Curve(1).Color = Colors.Blue
  383. Curve(2).Color = Colors.Black
  384. Curve(3).Color = Colors.RGB(64, 192, 0)

  385. Curve(0).Width = 1dip
  386. Curve(1).Width = 1dip
  387. Curve(2).Width = 1dip
  388. Curve(3).Width = 1dip

  389. Curve(0).Scale = 20
  390. Curve(1).Scale = 20
  391. Curve(2).Scale = 20
  392. Curve(3).Scale = 20

  393. Curve(0).Offset = 0
  394. Curve(1).Offset = 1
  395. Curve(2).Offset = -1
  396. Curve(3).Offset = 2

  397. Curve(0).Draw = True
  398. Curve(1).Draw = True
  399. Curve(2).Draw = True
  400. Curve(3).Draw = True
  401. End

    Sub

  402. Sub

    InitCalcCurves
  403. w(0) = 2 * cPI * 2.1
  404. w(1) = 2 * cPI * 3.7
  405. w(2) = 2 * cPI * 4.3
  406. w(3) = 2 * cPI * 5.7

  407. a(0) = 1.0
  408. a(1) = 2.0
  409. a(2) = -1.0
  410. a(3) = 1.5
  411. End

    Sub

  412. Sub

    InitSpinners
  413. Dim

    i As

    Int

  414. TimeScale(0) = 10
  415. TimeScale(1) = 5
  416. TimeScale(2) = 2
  417. TimeScale(3) = 1
  418. TimeScale(4) = 0.5
  419. TimeScale(5) = 0.2
  420. TimeScale(6) = 0.1
  421. TimeScale(7) = 0.05
  422. TimeScale(8) = 0.02
  423. TimeScale(9) = 0.01

  424. SignalScale(0) = 10
  425. SignalScale(1) = 5
  426. SignalScale(2) = 2
  427. SignalScale(3) = 1
  428. SignalScale(4) = .5
  429. SignalScale(5) = .2
  430. SignalScale(6) = .1
  431. SignalScale(7) = .05
  432. SignalScale(8) = .02
  433. SignalScale(9) = .01

  434. For

    i = 0 To

    9
  435. spnTimeScale.Add(TimeScale(i))
  436. spnScale0.Add(SignalScale(i))
  437. spnScale1.Add(SignalScale(i))
  438. spnScale2.Add(SignalScale(i))
  439. spnScale3.Add(SignalScale(i))
  440. Next
  441. spnTimeScale.SelectedIndex = 6

  442. spnScale0.SelectedIndex = 3
  443. spnScale1.SelectedIndex = 3
  444. spnScale2.SelectedIndex = 3
  445. spnScale3.SelectedIndex = 3
  446. Curve(0).Scale = Div / spnScale0.SelectedItem
  447. Curve(1).Scale = Div / spnScale1.SelectedItem
  448. Curve(2).Scale = Div / spnScale2.SelectedItem
  449. Curve(3).Scale = Div / spnScale3.SelectedItem
  450. End

    Sub

Best regards,

Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
STI College - Surigao City
09126450702
[email protected]

Follow and add me in my Facebook Account: https://www.facebook.com/donzzsky

Visit my page on Facebook at: https://www.facebook.com/BermzISware


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

452,292

324,360

324,368

Top