Skip to content

Commit

Permalink
release
Browse files Browse the repository at this point in the history
  • Loading branch information
import-tiago committed Nov 24, 2024
1 parent e854dd1 commit ea5e56c
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 25 deletions.
Binary file added Assets/logo-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Release/Win64-installer.rar
Binary file not shown.
13 changes: 11 additions & 2 deletions WindowsApp/Data/DbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@ namespace PartsHunter.Data {
public class PartsHunterContext : DbContext {
public DbSet<ComponentEntity> Components { get; set; }
public DbSet<HardwareDeviceEntity> HardwareDevice { get; set; }
private string dbPath = "Data\\Tables\\PartsHunter.db";

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
optionsBuilder.UseSqlite("Data Source=PartsHunter.db");
// Create directories if they do not exist
var directory = Path.GetDirectoryName(dbPath);
if (!Directory.Exists(directory)) {
Directory.CreateDirectory(directory);
}

optionsBuilder.UseSqlite($"Data Source={dbPath}");
}

protected override void OnModelCreating(ModelBuilder modelBuilder) {
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<HardwareDeviceEntity>().ToTable("HardwareDevice");
}
}
}
}
Binary file not shown.
4 changes: 2 additions & 2 deletions WindowsApp/How to Regenerate the Database in EF Core.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Remove the following directories and files from your project:
Any existing *.db files (your database file).
Clean the Solution:

In your IDE (e.g., Visual Studio), navigate to Build → Clean Solution to remove temporary files and ensure a clean build.
In Visual Studio, navigate to Build → Clean Solution to remove temporary files and ensure a clean build.
Open the Package Manager Console:

Go to Tools → NuGet Package Manager → Package Manager Console.
Expand All @@ -26,4 +26,4 @@ Confirm that the new database and schema are created as expected.
Notes:
Make sure your DbContext and entity classes are correctly set up before regenerating the database.
Use meaningful migration names instead of InitialCreate when adding migrations for clarity in version control.
If using a source control system, commit your changes to the migration folder after verifying the database generation.
If using a source control system, commit your changes to the migration folder after verifying the database generation.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace PartsHunter.Migrations
{
/// <inheritdoc />
public partial class MyStock : Migration
public partial class MyComponents : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
Expand Down
35 changes: 35 additions & 0 deletions WindowsApp/PartsHunter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<StartupObject>PartsHunter.Program</StartupObject>
<Title>PartsHunter</Title>
<Authors>Tiago Silva</Authors>
<Company>Controlando Elétrons</Company>
<Description>PartsHunter is an electronic component organization system designed for efficiency and precision. It consists of three core modules:

Windows Application: A user-friendly interface for searching and managing components by description.
Hardware Device: A communication module that interacts with the Windows application to activate LEDs, pinpointing the location of each component.
Mechanical Assembly: A storage system that organizes components across dedicated slots.</Description>
<PackageProjectUrl>https://github.com/import-tiago/PartsHunter</PackageProjectUrl>
<PackageIcon>logo-image.png</PackageIcon>
<RepositoryUrl>https://github.com/import-tiago/PartsHunter</RepositoryUrl>
<ApplicationIcon>logo_icon.ico</ApplicationIcon>
</PropertyGroup>

Expand All @@ -28,6 +40,11 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
Expand All @@ -37,4 +54,22 @@
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<Folder Include="Data\Tables\" />
</ItemGroup>

<ItemGroup>
<None Include="..\Assets\logo-image.png">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>

<ItemGroup>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>

</Project>
26 changes: 26 additions & 0 deletions WindowsApp/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions WindowsApp/Properties/Settings.settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
</SettingsFile>
29 changes: 18 additions & 11 deletions WindowsApp/Services/HardwareDeviceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,27 @@ public async void turn_on_pixels(List<int> pixels) {

}
}
public async Task clear_pixels() {
try {
var endpoint = $"http://{ip_addr}/clear";
var response = await httpClient.PostAsync(endpoint, null);
if (response.IsSuccessStatusCode) {
Debug.WriteLine("Pixels cleared successfully!");
public async Task<bool> clear_pixels(int retries = 3, int delay = 2000) {

for (int attempt = 0; attempt < retries; attempt++) {
try {
var endpoint = $"http://{ip_addr}/clear";
var response = await httpClient.PostAsync(endpoint, null);

if (response.IsSuccessStatusCode) {
return true;
}
else {
Debug.WriteLine($"Attempt {attempt + 1} failed: Status code {response.StatusCode}");
}
}
else {
Debug.WriteLine($"Failed to clear pixels. Status code: {response.StatusCode}");
catch (Exception ex) {
Debug.WriteLine($"Attempt {attempt + 1} exception: {ex.Message}");
}

await Task.Delay(delay);
}
catch (Exception ex) {
Debug.WriteLine($"Exception occurred: {ex.Message}");
}
return false;
}
}
}
1 change: 1 addition & 0 deletions WindowsApp/Views/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions WindowsApp/Views/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ private void trackBarBright_ValueChanged(object sender, EventArgs e) {
private void buttonClear_Click(object sender, EventArgs e) {
hardware_device.clear_pixels();
}

int selected_database_id;
private void dgvStock_SelectionChanged(object sender, EventArgs e) {

Expand Down Expand Up @@ -307,8 +306,8 @@ private async void btnShowAll_Click(object sender, EventArgs e) {

foreach (DataGridViewRow row in dgvBoM.Rows) {
if (row.Cells["SlotID"].Value != null) {
int slotId = Convert.ToInt32(row.Cells["SlotID"].Value);
pixels.Add(slotId);
int pixel = Convert.ToInt32(row.Cells["SlotID"].Value) - 1;
pixels.Add(pixel);
}
}
hardware_device.turn_on_pixels(pixels);
Expand Down Expand Up @@ -395,7 +394,6 @@ private void buttonSaveFromFile_Click(object sender, EventArgs e) {
MessageBox.Show("Please specify a valid .txt file.");
}
}

public bool is_ip_valid(string ip_addr) {
string pattern = @"^((25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)$";
return Regex.IsMatch(ip_addr, pattern);
Expand Down Expand Up @@ -423,10 +421,12 @@ private void pictureBoxEditIP_Click(object sender, EventArgs e) {
edit_ip = !edit_ip;
tbIP.Enabled = edit_ip;
}

private async void Form1_FormClosing(object sender, FormClosingEventArgs e) {
await hardware_device.clear_pixels();
Task.Delay(5000).Wait(); // Wait synchronously for demonstration
bool pixelsCleared = await hardware_device.clear_pixels();
if (!pixelsCleared) {
Debug.WriteLine("Failed to clear pixels after multiple attempts.");
}
await Task.Delay(5000);
}
}
}

0 comments on commit ea5e56c

Please sign in to comment.