-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
139 lines (120 loc) · 5.17 KB
/
Program.cs
File metadata and controls
139 lines (120 loc) · 5.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using System;
using System.Drawing;
using System.Linq;
using System.Threading;
using Unosquare.RaspberryIO;
using Unosquare.WiringPi;
namespace Celones.DisplayManager
{
class Program
{
static LcdScreen Lcd;
static ONUI.IHardwareButton ButtonA, ButtonB, ButtonC, ButtonD;
static Color ClearColor;
static void Main(string[] args)
{
Console.WriteLine("Celones SmartLED Display Manager");
// Simulation initialization
if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
{
System.Windows.Forms.Application.EnableVisualStyles();
var ctl = new Simulation.Nokia5110Lcd();
var sim = new Simulation.ControlPanel();
Console.WriteLine("Simulator for Windows");
Thread thread = new Thread((object form) => System.Windows.Forms.Application.Run((System.Windows.Forms.Form)form));
thread.SetApartmentState(ApartmentState.STA);
thread.IsBackground = false;
thread.Start(sim);
Lcd = new LcdScreen(new Device.Pcd8544(ctl, ctl, ctl));
Lcd.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
ButtonA = sim.aButton;
ButtonB = sim.bButton;
ButtonC = sim.cButton;
ButtonD = sim.dButton;
sim.screenImage.Image = ctl.Image;
sim.screenImage.BackColor = Color.CadetBlue;
}
// Hardware initialization
else
{
Pi.Init<BootstrapWiringPi>();
Pins.Init();
Console.WriteLine(Pi.Info.ToString());
Lcd = new LcdScreen(new Device.Pcd8544(Pi.Spi.Channel0, Pins.LcdReset, Pins.LcdDc), (GpioPin)Pins.LcdBacklight);
ButtonA = new Button(Pins.ButtonA);
ButtonB = new Button(Pins.ButtonB);
ButtonC = new Button(Pins.ButtonC);
ButtonD = new Button(Pins.ButtonD);
}
ButtonA.Pressed += ButtonA_Pressed;
Lcd.Init();
Lcd.Clear();
for (double brightness = 0.0; brightness <= 1.0; brightness += 0.1)
{
Lcd.Brightness = brightness;
Lcd.Contrast = brightness;
Thread.Sleep(50);
}
// Graphics demo
var pen = new Pen(Color.Black);
var brush = new SolidBrush(Color.Black);
Lcd.Clear();
Lcd.Graphics.DrawRectangle(pen, new Rectangle(0, 0, Lcd.Width - 1, Lcd.Height - 1));
Lcd.Update();
for (int i = 1; i <= 6; i++)
{
pen.Width = i;
Lcd.Graphics.DrawLine(pen, new Point(i * 10, 5), new Point(i * 10, 20));
Lcd.Graphics.DrawLine(pen, new Point(i * 10, 5), new Point(i * 10 - 5, 10));
Lcd.Update();
Thread.Sleep(750);
}
Lcd.Graphics.FillRectangle(brush, new Rectangle(0, Lcd.Height / 2, Lcd.Width, Lcd.Height / 2));
pen.Color = Color.White;
for (int i = 1; i <= 6; i++)
{
pen.Width = i;
Lcd.Graphics.DrawLine(pen, new Point(i * 10, 30), new Point(i * 10, 45));
Lcd.Graphics.DrawLine(pen, new Point(i * 10, 30), new Point(i * 10 - 5, 35));
Lcd.Update();
Thread.Sleep(750);
}
// Font demo
var fonts = new System.Drawing.Text.InstalledFontCollection();
fonts.Families
.Where(family => family.IsStyleAvailable(FontStyle.Regular))
.OrderBy(family => family.Name)
.ToList().ForEach(family => {
var font = new Font(family, 8);
Lcd.Clear();
Lcd.Graphics.DrawString(family.Name, font, brush, new RectangleF(0, 0, Lcd.Width, Lcd.Height));
Lcd.Update();
Thread.Sleep(1500);
});
// Menu demo
var ui = new ONUI.UI(AssemblyDirectory + "/Assets/MainMenu.xaml");
ui.Display = Lcd;
ui.BackButton = ButtonA;
ui.OkButton = ButtonB;
ui.DownButton = ButtonC;
ui.UpButton = ButtonD;
ui.Show();
}
static void ButtonA_Pressed(object sender, EventArgs e)
{
Lcd.Graphics.Clear(ClearColor);
Lcd.Update();
ClearColor = ClearColor == Color.Black ? Color.White : Color.Black;
}
public static string AssemblyDirectory
{
get
{
string codeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return System.IO.Path.GetDirectoryName(path);
}
}
}
}