Skip to content

Commit

Permalink
v1.9 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
xioTechnologies committed Dec 3, 2017
1 parent ecbe717 commit 5ef6fbe
Show file tree
Hide file tree
Showing 19 changed files with 519 additions and 108 deletions.
Binary file modified Libraries/Rug.LiteGL.dll
Binary file not shown.
7 changes: 5 additions & 2 deletions NGIMU.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2002
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NgimuGui", "NgimuGui\NgimuGui.csproj", "{1E1AB79E-3664-4195-82F9-3907CDA71882}"
ProjectSection(ProjectDependencies) = postProject
Expand Down Expand Up @@ -70,4 +70,7 @@ Global
{9C9008A5-82A8-4DF3-8667-81460C23999D} = {5429C2B9-EBAA-4907-8971-BA561AAF150D}
{BA6D9EF7-40B1-4E7C-993A-F7F31F0B0504} = {5429C2B9-EBAA-4907-8971-BA561AAF150D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2BBD96EF-1328-4C93-8CCF-8147DC23A45F}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ public override void Dispose()

public override void Send(OscPacket packet)
{
oscSerial.Send(packet);
try
{
oscSerial.Send(packet);
}
catch (TimeoutException ex)
{

}
}

public override void Start()
Expand Down
6 changes: 4 additions & 2 deletions NgimuApi/Data/BatteryData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ internal override string CsvHeader
"Percentage (%)",
"Time To Empty (minutes)",
"Voltage (V)",
"Current (mA)"
"Current (mA)",
"Is Charger Connected (Boolean)"
);
}
}
Expand All @@ -123,7 +124,8 @@ internal override string ToCsv(OscTimeTag firstTimestamp)
Percentage,
TimeToEmpty,
Voltage,
Current
Current,
IsChargerConnected
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions NgimuApi/Data/CtsDataBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ internal override string CsvHeader
{
return Helper.ToCsv(
"Time (s)",
"State");
"State (Boolean)");
}
}

internal override string ToCsv(OscTimeTag firstTimestamp)
{
return Helper.ToCsv(
CreateTimestampString(firstTimestamp),
State ? 1 : 0
State
);
}

Expand Down
16 changes: 13 additions & 3 deletions NgimuApi/Helper/Helper.Csv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private static void CellToString(StringBuilder sb, object obj)
{
if (obj is bool)
{
sb.Append(((bool)obj).ToString(CultureInfo.InvariantCulture));
sb.Append((bool)obj == true ? "1" : "0");
}
else if (obj is int)
{
Expand Down Expand Up @@ -122,11 +122,21 @@ private static void CellToString(StringBuilder sb, object obj)
}
else if (obj is float)
{
sb.Append(((float)obj).ToString(CultureInfo.InvariantCulture));
float value = (float)obj;
if (float.IsInfinity(value) || float.IsNaN(value))
{
value = 0;
}
sb.Append(value.ToString(CultureInfo.InvariantCulture));
}
else if (obj is double)
{
sb.Append(((double)obj).ToString(CultureInfo.InvariantCulture));
double value = (double)obj;
if (double.IsInfinity(value) || double.IsNaN(value))
{
value = 0;
}
sb.Append(value.ToString(CultureInfo.InvariantCulture));
}
else if (obj is decimal)
{
Expand Down
2 changes: 1 addition & 1 deletion NgimuApi/Settings/Settings.FirmwareVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ partial class Settings
/// <summary>
/// The expected firmware version.
/// </summary>
public const string ExpectedFirmwareVersion = "v1.6 (Oct 30 2017 16:26:07)";
public const string ExpectedFirmwareVersion = "v1.7 (Nov 30 2017 21:42:56)";

/// <summary>
/// Checks the firmware compatibility.
Expand Down
20 changes: 17 additions & 3 deletions NgimuForms/Controls/ControlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,13 @@ private static bool IsValidForInvoke(this Control control)
return control.IsHandleCreated == true && control.Disposing == false && control.IsDisposed == false;
}

public static void ShowIncompatableFirmwareWarning(this Control control, Settings settings)
public static bool TryGetIncompatableFirmwareWarningMessage(this Control control, Settings settings, out string message)
{
if (settings.CheckFirmwareCompatibility() != FirmwareCompatibility.NotCompatible)
{
return;
message = null;

return false;
}

StringBuilder dialogString = new StringBuilder();
Expand All @@ -165,7 +167,19 @@ public static void ShowIncompatableFirmwareWarning(this Control control, Setting
dialogString.AppendLine($"Expected firmware version: {Settings.ExpectedFirmwareVersion}");
dialogString.AppendLine($"Software version: v{assembly.GetName().Version.Major}.{assembly.GetName().Version.Minor}");

control.InvokeShowWarning(dialogString.ToString().TrimEnd());
message = dialogString.ToString().TrimEnd();

return true;
}

public static void ShowIncompatableFirmwareWarning(this Control control, Settings settings)
{
if (TryGetIncompatableFirmwareWarningMessage(control, settings, out string message) == false)
{
return;
}

control.InvokeShowWarning(message);
}
}
}
223 changes: 223 additions & 0 deletions NgimuForms/Controls/TextAndIconColumn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NgimuForms.Controls
{
public class IconInfo
{
public MessageBoxIcon MessageIcon { get; set; }

public Image Image { get; set; }

public string Message { get; set; }

public bool Visible { get; set; }
}

public class TextAndIconColumn : DataGridViewTextBoxColumn
{
public TextAndIconColumn()
{
this.CellTemplate = new TextAndIconCell();
}

/// <summary>
/// Resize the image to the specified width and height.
/// </summary>
/// <param name="image">The image to resize.</param>
/// <param name="width">The width to resize to.</param>
/// <param name="height">The height to resize to.</param>
/// <returns>The resized image.</returns>
public static Bitmap ResizeImage(Image image, int width, int height)
{
var destRect = new Rectangle(0, 0, width, height);
var destImage = new Bitmap(width, height);

destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);

using (var graphics = Graphics.FromImage(destImage))
{
graphics.CompositingMode = CompositingMode.SourceCopy;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

using (var wrapMode = new ImageAttributes())
{
wrapMode.SetWrapMode(WrapMode.TileFlipXY);
graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
}
}

return destImage;
}
}

public class TextAndIconCell : DataGridViewTextBoxCell
{
private readonly List<IconInfo> icons = new List<IconInfo>();
private Rectangle cellBounds;

public override object Clone()
{
TextAndIconCell c = base.Clone() as TextAndIconCell;

c.icons.AddRange(this.icons);

return c;
}

public int Count => icons.Count;

public IconInfo this[int index] => icons[index];

public void Add(IconInfo icon)
{
icons.Add(icon);
}

//public Image Image
//{
// get
// {
// if (this.OwningColumn == null ||
// this.OwningTextAndImageColumn == null)
// {

// return imageValue;
// }
// else if (this.imageValue != null)
// {
// return this.imageValue;
// }
// else
// {
// return this.OwningTextAndImageColumn.Image;
// }
// }
// set
// {
// if (this.imageValue == value)
// {
// return;
// }

// this.imageValue = value;
// this.imageSize = value.Size;

// Padding inheritedPadding = this.InheritedStyle.Padding;

// this.Style.Padding = new Padding(inheritedPadding.Left,
// inheritedPadding.Top, inheritedPadding.Right - (imageSize.Width + 4),
// inheritedPadding.Bottom);
// }
//}

protected override void Paint(Graphics graphics, Rectangle clipBounds,
Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState,
object value, object formattedValue, string errorText,
DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts)
{
this.cellBounds = cellBounds;

int offset = 4;

foreach (IconInfo info in icons)
{
if (info.Visible == false)
{
continue;
}

offset += info.Image.Width + 4;
}

Padding inheritedPadding = this.InheritedStyle.Padding;

this.Style.Padding = new Padding(inheritedPadding.Left,
inheritedPadding.Top, inheritedPadding.Right - offset,
inheritedPadding.Bottom);

// Paint the base content
base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState,
value, formattedValue, errorText, cellStyle,
advancedBorderStyle, paintParts);

// Draw the image clipped to the cell.
System.Drawing.Drawing2D.GraphicsContainer container = graphics.BeginContainer();

graphics.SetClip(cellBounds);

int x = cellBounds.Right - offset;

foreach (IconInfo info in icons)
{
if (info.Visible == false)
{
continue;
}

float vOffset = (cellBounds.Top + (cellBounds.Height * 0.5f)) - (info.Image.Height * 0.5f);

graphics.DrawImageUnscaled(info.Image, x, (int) vOffset);

x += info.Image.Width + 4;
}

graphics.EndContainer(container);
}

public bool TryClick(Point mouse, out IconInfo iconInfo)
{
int offset = 4;

foreach (IconInfo info in icons)
{
if (info.Visible == false)
{
continue;
}

offset += info.Image.Width + 4;
}

int x = cellBounds.Right - offset;

foreach (IconInfo info in icons)
{
if (info.Visible == false)
{
continue;
}

float vOffset = (cellBounds.Top + (cellBounds.Height * 0.5f)) - (info.Image.Height * 0.5f);

Rectangle imageRect = new Rectangle(x, (int)vOffset, info.Image.Width, info.Image.Height);

if (imageRect.Contains(mouse) == true)
{
iconInfo = info;

return true;
}

x += info.Image.Width + 4;
}

iconInfo = null;

return false;
}

private TextAndIconColumn OwningTextAndImageColumn => this.OwningColumn as TextAndIconColumn;
}
}
1 change: 1 addition & 0 deletions NgimuForms/NgimuForms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<Compile Include="Controls\PathSelector.Designer.cs">
<DependentUpon>PathSelector.cs</DependentUpon>
</Compile>
<Compile Include="Controls\TextAndIconColumn.cs" />
<Compile Include="Controls\TextBoxWithHelpText.cs">
<SubType>Component</SubType>
</Compile>
Expand Down
Loading

0 comments on commit 5ef6fbe

Please sign in to comment.