commit cc6072d2dc3785c8a2f042cc8f97714bee587ee4 Author: dennydai <10000@daihan.me> Date: Thu Feb 27 10:51:40 2020 -0500 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a57fdbb --- /dev/null +++ b/.gitignore @@ -0,0 +1,353 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*[.json, .xml, .info] + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ \ No newline at end of file diff --git a/iClicker.sln b/iClicker.sln new file mode 100644 index 0000000..71ac335 --- /dev/null +++ b/iClicker.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29613.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "iClicker", "iClicker\iClicker.csproj", "{F940473E-21CD-4B50-A0C9-FACA9B2C8514}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F940473E-21CD-4B50-A0C9-FACA9B2C8514}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F940473E-21CD-4B50-A0C9-FACA9B2C8514}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F940473E-21CD-4B50-A0C9-FACA9B2C8514}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F940473E-21CD-4B50-A0C9-FACA9B2C8514}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0E5CE50C-09C4-4BF8-AA95-D564C0DC1915} + EndGlobalSection +EndGlobal diff --git a/iClicker/App.config b/iClicker/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/iClicker/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/iClicker/Program.cs b/iClicker/Program.cs new file mode 100644 index 0000000..22f1457 --- /dev/null +++ b/iClicker/Program.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections; +using System.Drawing; +using System.IO.Ports; +using System.Runtime.InteropServices; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace iClicker { + class Program { + static ArrayList[] answerLists = new ArrayList[5]; + static bool answerListsUpdated = true; + static int mostAnswer; + + static NotifyIcon notifyIcon = new NotifyIcon(); + static bool consoleVisibility = true; + static String channel = "#AA"; + static void Main(String[] args) { + if (args.Length < 1) return; + if (args.Length == 2) channel = "#" + args[1].ToUpper(); + + for (int i = 0; i < 5; i++) answerLists[i] = new ArrayList(); + + // notify icon menu + notifyIcon.Visible = true; + SetConsoleWindowVisibility(false); + notifyIcon.DoubleClick += (s, e) => { consoleVisibility = !consoleVisibility; SetConsoleWindowVisibility(consoleVisibility); }; + var contextMenu = new ContextMenuStrip(); + contextMenu.Items.Add("Reset", null, (s, e) => { for (int i = 0; i < 5; i++) answerLists[i].Clear(); answerListsUpdated = true; }); + contextMenu.Items.Add("Exit", null, (s, e) => { Application.Exit(); }); + notifyIcon.ContextMenuStrip = contextMenu; + + SerialPort mySerialPort = new SerialPort(args[0].ToUpper()); + + mySerialPort.BaudRate = 115200; + mySerialPort.Parity = Parity.None; + mySerialPort.StopBits = StopBits.One; + mySerialPort.DataBits = 8; + mySerialPort.Handshake = Handshake.None; + mySerialPort.RtsEnable = true; + mySerialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler); + + mySerialPort.Open(); + + mySerialPort.WriteLine(channel); + + System.Timers.Timer timer = new System.Timers.Timer(1000); + timer.Elapsed += async (sender, e) => await Task.Run(() => updateResult()); + timer.Start(); + + Application.Run(); + mySerialPort.Close(); + } + private static void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e) { + SerialPort sp = (SerialPort)sender; + String indata = sp.ReadExisting(); + if (indata[0] == '$') { // received answer + char ans = indata[1]; + String id = indata.Substring(2, 8); + if (ans >= 'A' && ans <= 'E') { + for (int i = 0; i < 5; i++) answerLists[i].Remove(id); + answerLists[ans - 'A'].Add(id); + answerListsUpdated = true; + } + } + } + private static void updateResult() { + if (!answerListsUpdated) return; + Console.Clear(); + notifyIcon.Text = ""; + int total = answerLists[0].Count + answerLists[1].Count + answerLists[2].Count + answerLists[3].Count + answerLists[4].Count; + if (total == 0) total = 1; + + mostAnswer = 0; + for (int i = 1; i < 5; i++) + if (answerLists[i].Count > answerLists[mostAnswer].Count) mostAnswer = i; + + for (int i = 0; i < 5; i++) { + if (i == mostAnswer) Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("{0}: {1}\t{2} {3:F}%", (char)(i + 'A'), answerLists[i].Count, new String('▄', answerLists[i].Count * 50 / total), answerLists[i].Count * 100.0 / total); + if (i == mostAnswer) Console.ForegroundColor = ConsoleColor.White; + } + + for (int i = 0; i < 5; i++) { + if (i == mostAnswer) notifyIcon.Text += String.Format(" - "); + notifyIcon.Text += String.Format("{0}: {1:F}%\n", (char)(i + 'A'), answerLists[i].Count * 100.0 / total); + } + + updateIcon(((char)(mostAnswer + 'A')).ToString(), answerLists[mostAnswer].Count * 100 / total + "%"); + + answerListsUpdated = false; + } + public static void SetConsoleWindowVisibility(bool visible) { + IntPtr hWnd = FindWindow(null, Console.Title); + if (hWnd != IntPtr.Zero) { + if (visible) ShowWindow(hWnd, 1); //1 = SW_SHOWNORMAL + else ShowWindow(hWnd, 0); //0 = SW_HIDE + } + } + + public static void updateIcon(String line1, String line2) { + Font line1Font = new Font("Arial Black", 128, FontStyle.Regular, GraphicsUnit.Pixel); + Font line2Font = new Font("Arial Black", 104, FontStyle.Regular, GraphicsUnit.Pixel); + Brush brushToUse = new SolidBrush(Color.White); + Bitmap bitmapText = new Bitmap(256, 256); + Graphics g = System.Drawing.Graphics.FromImage(bitmapText); + + IntPtr hIcon; + + g.Clear(Color.Transparent); + g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit; + g.DrawString(line1, line1Font, brushToUse, 56, 0); + g.DrawString(line2, line2Font, brushToUse, 0, 140); + hIcon = (bitmapText.GetHicon()); + notifyIcon.Icon = System.Drawing.Icon.FromHandle(hIcon); + } + + [DllImport("user32.dll")] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); + [DllImport("user32.dll")] static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); + + } +} \ No newline at end of file diff --git a/iClicker/Properties/AssemblyInfo.cs b/iClicker/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..f17a779 --- /dev/null +++ b/iClicker/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("iClicker")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("iClicker")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("f940473e-21cd-4b50-a0c9-faca9b2c8514")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/iClicker/Properties/Resources.Designer.cs b/iClicker/Properties/Resources.Designer.cs new file mode 100644 index 0000000..6678521 --- /dev/null +++ b/iClicker/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace iClicker.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("iClicker.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/iClicker/Properties/Resources.resx b/iClicker/Properties/Resources.resx new file mode 100644 index 0000000..4fdb1b6 --- /dev/null +++ b/iClicker/Properties/Resources.resx @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/iClicker/TextTemplate.ico b/iClicker/TextTemplate.ico new file mode 100644 index 0000000..0925e56 Binary files /dev/null and b/iClicker/TextTemplate.ico differ diff --git a/iClicker/iClicker.csproj b/iClicker/iClicker.csproj new file mode 100644 index 0000000..a045cb4 --- /dev/null +++ b/iClicker/iClicker.csproj @@ -0,0 +1,103 @@ + + + + + Debug + AnyCPU + {F940473E-21CD-4B50-A0C9-FACA9B2C8514} + Exe + iClicker + iClicker + v4.7.2 + 512 + true + true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + True + True + Resources.resx + + + + + + + + + + + False + Microsoft .NET Framework 4.7.2 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + \ No newline at end of file