Hi all,
For my uinversity project, I need to make a simple remote oscilloscope by
android. The idea is a microcontroller with wifi ability will stream bits of
a waveform to an android phone and the phone should show the waveform
(Reconstracting the waveform out of bits, some sort of digiral to analog
conversion).
First I wanted to know if Mono for android has libraries to use wifi data?
Second, I am not sure what is the best way to draw waveform animation on the
phone. I would really stay away from OpenGL since I have no idea how it
works, But coming from C# background I know a good amount about Graphics.
What I did so far is I made a View and now I want to animate a simple
hardcoded (sine wave) waveform on my view:
#define DEBUG
using System;
using Android.Content;
using Android.Graphics;
using Android.Util;
using Android.Views;
namespace MiniScope.Views
{
public class ScopeCanvas : View
{
public ScopeCanvas(Context context, IAttributeSet attrs) :
base(context, attrs)
{
}
public ScopeCanvas(Context context, IAttributeSet attrs, int
defStyle) :
base(context, attrs, defStyle)
{
}
protected override void OnDraw(Android.Graphics.Canvas canvas)
{
base.OnDraw(canvas);
var bounds = canvas.ClipBounds;
var penAxis = MakePen(1, Color.LightGray); //Main center axis
pen
var penGrid = MakePen(0.5F, Color.LightPink); //Grid pens
#if DEBUG
Console.WriteLine("SCOPE AREA");
Console.WriteLine("Width: {0} Height: {1} CenterX: {2} CenterY:
{3}", bounds.Width(), bounds.Height(), bounds.ExactCenterX(),
bounds.ExactCenterY());
#endif
//Drawing a background color
canvas.DrawColor(Color.Black);
//Drawing center coodinate lines
canvas.DrawLine(0, bounds.ExactCenterY(), bounds.Width(),
bounds.ExactCenterY(), penAxis);
canvas.DrawLine(bounds.ExactCenterX(), 0, bounds.ExactCenterX(),
bounds.Height(), penAxis);
//Drawing horizontal grids (Voltage divisions)
var divisionHeight = bounds.Height() / 10F;
var startY = divisionHeight;
for (var i = 0; i < 10; i++)
{
if (startY == bounds.ExactCenterY())
{
startY += divisionHeight;
continue;
}
if(startY == bounds.Height())
{
continue;
}
canvas.DrawLine(0, startY, bounds.Width(), startY, penGrid);
#if DEBUG
Console.WriteLine("Drawing horizontal line #{0} at Y={1}",
i, startY);
#endif
startY += divisionHeight;
}
//Drawing vertical grids (Time)
var divisionWidth = bounds.Width() / 10F;
var startX = divisionWidth;
for (var i = 0; i < 10; i++)
{
if (startX == bounds.ExactCenterX())
{
startX += divisionWidth;
continue;
}
if(startX == bounds.Width())
{
continue;
}
canvas.DrawLine(startX, 0, startX, bounds.Height(),
penGrid);
#if DEBUG
Console.WriteLine("Drawing vertical line #{0} at X={1}", i,
startX);
#endif
startX += divisionWidth;
}
//Disposing pens
penAxis.Dispose();
penGrid.Dispose();
}
/// <summary>
/// Making a pen using Paint
/// </summary>
/// Width of the pen
/// Color
/// Style
/// Path effect
/// <returns>A Pen object using Paint</returns>
private static Paint MakePen(float? width = null,Color? color =
null, Paint.Style style = null, PathEffect pathEffect = null)
{
if(width == null)
{
width = 2;
}
if(color == null)
{
color = Color.Red;
}
if(style == null)
{
style = Paint.Style.Stroke;
}
var pen = new Paint();
if(pathEffect == null)
{
pen.Color = (Color) color;
pen.StrokeWidth = (float) width;
pen.SetStyle(style);
}
else
{
pen.SetPathEffect(pathEffect);
}
return pen;
}
}
}
This will just draw the lines. How can I animate a view?
Any kind of help will be appriciated!
Regards,
Saeid.
--
View this message in context:
http://mono-for-android.1047100.n5.nabble.com/Animating-using-canvas-tp5700982.html
Sent from the Mono for Android mailing list archive at Nabble.com.
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid