├── .gitattributes ├── .gitignore ├── ASCOM ├── ASCOM.ico ├── ASCOM.png ├── Arduino FlatBox Setup.iss ├── Arduino FlatBox.csproj ├── Arduino Flatbox.sln ├── Arduino Flatbox.snk ├── CSharpASCOM.ico ├── Driver.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── Resources │ ├── ASCOM.bmp │ ├── LICENSE.txt │ ├── README.txt │ └── WizardImage.bmp ├── SetupDialogForm.cs ├── SetupDialogForm.designer.cs ├── SetupDialogForm.resx ├── app.config └── packages.config ├── Arduino_Sketch ├── ArduinoFlatBox │ └── ArduinoFlatBox.ino └── EEPROMex │ └── EEPROMex.cpp ├── LICENSE.txt ├── Protocol_Definitions.txt ├── README.md └── TODO.txt /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /ASCOM/ASCOM.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smgill75/ArduinoFlatbox/147e3d02d6b963719ea32f449ec0626344cf05c3/ASCOM/ASCOM.ico -------------------------------------------------------------------------------- /ASCOM/ASCOM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smgill75/ArduinoFlatbox/147e3d02d6b963719ea32f449ec0626344cf05c3/ASCOM/ASCOM.png -------------------------------------------------------------------------------- /ASCOM/Arduino FlatBox Setup.iss: -------------------------------------------------------------------------------- 1 | ; 2 | ; Script generated by the ASCOM Driver Installer Script Generator 6.5.1.0 3 | ; Generated by Steven Gill on 3/8/2022 (UTC) 4 | ; 5 | [Setup] 6 | AppID={{d7811816-a470-437d-8118-651271c0609f} 7 | AppName=ASCOM Arduino FlatBox CoverCalibrator Driver 8 | AppVerName=ASCOM Arduino FlatBox CoverCalibrator Driver 6.5 9 | AppVersion=6.5 10 | AppPublisher=Steven Gill 11 | AppPublisherURL=mailto:smgill75@gmail.com 12 | AppSupportURL=https://ascomtalk.groups.io/g/Help 13 | AppUpdatesURL=https://ascom-standards.org/ 14 | VersionInfoVersion=1.0.0 15 | MinVersion=6.1.7601 16 | DefaultDirName="{cf}\ASCOM\CoverCalibrator" 17 | DisableDirPage=yes 18 | DisableProgramGroupPage=yes 19 | OutputDir="." 20 | OutputBaseFilename="Arduino FlatBox Setup" 21 | Compression=lzma 22 | SolidCompression=yes 23 | ; Put there by Platform if Driver Installer Support selected 24 | WizardImageFile="Resources\WizardImage.bmp" 25 | LicenseFile="Resources\LICENSE.txt" 26 | ; {cf}\ASCOM\Uninstall\CoverCalibrator folder created by Platform, always 27 | UninstallFilesDir="{cf}\ASCOM\Uninstall\CoverCalibrator\Arduino FlatBox" 28 | 29 | [Languages] 30 | Name: "english"; MessagesFile: "compiler:Default.isl" 31 | 32 | [Dirs] 33 | Name: "{cf}\ASCOM\Uninstall\CoverCalibrator\Arduino FlatBox" 34 | ; TODO: Add subfolders below {app} as needed (e.g. Name: "{app}\MyFolder") 35 | 36 | [Files] 37 | Source: ".\bin\Release\ASCOM.ArduinoFlatbox.dll"; DestDir: "{app}" 38 | ; Require a read-me HTML to appear after installation, maybe driver's Help doc 39 | Source: ".\Resources\ReadMe.txt"; DestDir: "{app}"; Flags: isreadme 40 | ; TODO: Add other files needed by your driver here (add subfolders above) 41 | 42 | 43 | ; Only if driver is .NET 44 | [Run] 45 | ; Only for .NET assembly/in-proc drivers 46 | Filename: "{dotnet4032}\regasm.exe"; Parameters: "/codebase ""{app}\ASCOM.ArduinoFlatbox.dll"""; Flags: runhidden 32bit 47 | Filename: "{dotnet4064}\regasm.exe"; Parameters: "/codebase ""{app}\ASCOM.ArduinoFlatbox.dll"""; Flags: runhidden 64bit; Check: IsWin64 48 | 49 | 50 | 51 | 52 | ; Only if driver is .NET 53 | [UninstallRun] 54 | ; Only for .NET assembly/in-proc drivers 55 | Filename: "{dotnet4032}\regasm.exe"; Parameters: "-u ""{app}\ASCOM.ArduinoFlatbox.dll"""; Flags: runhidden 32bit 56 | ; This helps to give a clean uninstall 57 | Filename: "{dotnet4064}\regasm.exe"; Parameters: "/codebase ""{app}\ASCOM.ArduinoFlatbox.dll"""; Flags: runhidden 64bit; Check: IsWin64 58 | Filename: "{dotnet4064}\regasm.exe"; Parameters: "-u ""{app}\ASCOM.ArduinoFlatbox.dll"""; Flags: runhidden 64bit; Check: IsWin64 59 | 60 | 61 | 62 | 63 | [Code] 64 | const 65 | REQUIRED_PLATFORM_VERSION = 6.2; // Set this to the minimum required ASCOM Platform version for this application 66 | 67 | // 68 | // Function to return the ASCOM Platform's version number as a double. 69 | // 70 | function PlatformVersion(): Double; 71 | var 72 | PlatVerString : String; 73 | begin 74 | Result := 0.0; // Initialise the return value in case we can't read the registry 75 | try 76 | if RegQueryStringValue(HKEY_LOCAL_MACHINE_32, 'Software\ASCOM','PlatformVersion', PlatVerString) then 77 | begin // Successfully read the value from the registry 78 | Result := StrToFloat(PlatVerString); // Create a double from the X.Y Platform version string 79 | end; 80 | except 81 | ShowExceptionMessage; 82 | Result:= -1.0; // Indicate in the return value that an exception was generated 83 | end; 84 | end; 85 | 86 | // 87 | // Before the installer UI appears, verify that the required ASCOM Platform version is installed. 88 | // 89 | function InitializeSetup(): Boolean; 90 | var 91 | PlatformVersionNumber : double; 92 | begin 93 | Result := FALSE; // Assume failure 94 | PlatformVersionNumber := PlatformVersion(); // Get the installed Platform version as a double 95 | If PlatformVersionNumber >= REQUIRED_PLATFORM_VERSION then // Check whether we have the minimum required Platform or newer 96 | Result := TRUE 97 | else 98 | if PlatformVersionNumber = 0.0 then 99 | MsgBox('No ASCOM Platform is installed. Please install Platform ' + Format('%3.1f', [REQUIRED_PLATFORM_VERSION]) + ' or later from https://www.ascom-standards.org', mbCriticalError, MB_OK) 100 | else 101 | MsgBox('ASCOM Platform ' + Format('%3.1f', [REQUIRED_PLATFORM_VERSION]) + ' or later is required, but Platform '+ Format('%3.1f', [PlatformVersionNumber]) + ' is installed. Please install the latest Platform before continuing; you will find it at https://www.ascom-standards.org', mbCriticalError, MB_OK); 102 | end; 103 | 104 | // Code to enable the installer to uninstall previous versions of itself when a new version is installed 105 | procedure CurStepChanged(CurStep: TSetupStep); 106 | var 107 | ResultCode: Integer; 108 | UninstallExe: String; 109 | UninstallRegistry: String; 110 | begin 111 | if (CurStep = ssInstall) then // Install step has started 112 | begin 113 | // Create the correct registry location name, which is based on the AppId 114 | UninstallRegistry := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#SetupSetting("AppId")}' + '_is1'); 115 | // Check whether an extry exists 116 | if RegQueryStringValue(HKLM, UninstallRegistry, 'UninstallString', UninstallExe) then 117 | begin // Entry exists and previous version is installed so run its uninstaller quietly after informing the user 118 | MsgBox('Setup will now remove the previous version.', mbInformation, MB_OK); 119 | Exec(RemoveQuotes(UninstallExe), ' /SILENT', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode); 120 | sleep(1000); //Give enough time for the install screen to be repainted before continuing 121 | end 122 | end; 123 | end; 124 | 125 | -------------------------------------------------------------------------------- /ASCOM/Arduino FlatBox.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.30729 7 | 2.0 8 | {64308775-BD4A-469C-BCAB-3ED830B811AF} 9 | Library 10 | Properties 11 | ASCOM.ArduinoFlatbox 12 | ASCOM.ArduinoFlatbox 13 | 14 | 15 | 16 | 17 | 3.5 18 | v4.7.2 19 | ASCOM.ico 20 | true 21 | Arduino Flatbox.snk 22 | publish\ 23 | true 24 | Disk 25 | false 26 | Foreground 27 | 7 28 | Days 29 | false 30 | false 31 | true 32 | 0 33 | 1.0.0.%2a 34 | false 35 | false 36 | true 37 | 38 | 39 | 40 | 41 | true 42 | full 43 | false 44 | bin\Debug\ 45 | DEBUG;TRACE 46 | prompt 47 | 4 48 | true 49 | AnyCPU 50 | false 51 | 52 | 53 | pdbonly 54 | true 55 | bin\Release\ 56 | TRACE 57 | prompt 58 | 4 59 | AnyCPU 60 | false 61 | false 62 | 63 | 64 | 65 | packages\ASCOM.Platform.6.5.2\lib\net40\ASCOM.Astrometry.dll 66 | 67 | 68 | packages\ASCOM.Platform.6.5.2\lib\net40\ASCOM.Attributes.dll 69 | 70 | 71 | packages\ASCOM.Platform.6.5.2\lib\net40\ASCOM.Cache.dll 72 | 73 | 74 | packages\ASCOM.Platform.6.5.2\lib\net40\ASCOM.Controls.dll 75 | 76 | 77 | packages\ASCOM.Platform.6.5.2\lib\net40\ASCOM.DeviceInterfaces.dll 78 | 79 | 80 | packages\ASCOM.Platform.6.5.2\lib\net40\ASCOM.DriverAccess.dll 81 | 82 | 83 | packages\ASCOM.Platform.6.5.2\lib\net40\ASCOM.Exceptions.dll 84 | 85 | 86 | packages\ASCOM.Platform.6.5.2\lib\net40\ASCOM.Internal.Extensions.dll 87 | 88 | 89 | packages\ASCOM.Platform.6.5.2\lib\net40\ASCOM.SettingsProvider.dll 90 | 91 | 92 | packages\ASCOM.Platform.6.5.2\lib\net40\ASCOM.Utilities.dll 93 | 94 | 95 | packages\ASCOM.Platform.6.5.2\lib\net40\ASCOM.Utilities.Video.dll 96 | 97 | 98 | 99 | 100 | 101 | 3.5 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | True 114 | True 115 | Resources.resx 116 | 117 | 118 | True 119 | True 120 | Settings.settings 121 | 122 | 123 | Form 124 | 125 | 126 | SetupDialogForm.cs 127 | 128 | 129 | 130 | 131 | Designer 132 | ResXFileCodeGenerator 133 | Resources.Designer.cs 134 | 135 | 136 | SetupDialogForm.cs 137 | Designer 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | SettingsSingleFileGenerator 147 | Settings.Designer.cs 148 | 149 | 150 | 151 | 152 | 153 | 154 | False 155 | .NET Framework 3.5 SP1 Client Profile 156 | false 157 | 158 | 159 | False 160 | .NET Framework 3.5 SP1 161 | true 162 | 163 | 164 | False 165 | Windows Installer 3.1 166 | true 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 181 | -------------------------------------------------------------------------------- /ASCOM/Arduino Flatbox.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.32014.148 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Arduino FlatBox", "Arduino FlatBox.csproj", "{64308775-BD4A-469C-BCAB-3ED830B811AF}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Debug|x86 = Debug|x86 12 | Release|Any CPU = Release|Any CPU 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {64308775-BD4A-469C-BCAB-3ED830B811AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {64308775-BD4A-469C-BCAB-3ED830B811AF}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {64308775-BD4A-469C-BCAB-3ED830B811AF}.Debug|x86.ActiveCfg = Debug|Any CPU 19 | {64308775-BD4A-469C-BCAB-3ED830B811AF}.Debug|x86.Build.0 = Debug|Any CPU 20 | {64308775-BD4A-469C-BCAB-3ED830B811AF}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {64308775-BD4A-469C-BCAB-3ED830B811AF}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {64308775-BD4A-469C-BCAB-3ED830B811AF}.Release|x86.ActiveCfg = Release|Any CPU 23 | {64308775-BD4A-469C-BCAB-3ED830B811AF}.Release|x86.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {98323629-93FD-4BD1-AC70-7A6CE6905B17} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /ASCOM/Arduino Flatbox.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smgill75/ArduinoFlatbox/147e3d02d6b963719ea32f449ec0626344cf05c3/ASCOM/Arduino Flatbox.snk -------------------------------------------------------------------------------- /ASCOM/CSharpASCOM.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smgill75/ArduinoFlatbox/147e3d02d6b963719ea32f449ec0626344cf05c3/ASCOM/CSharpASCOM.ico -------------------------------------------------------------------------------- /ASCOM/Driver.cs: -------------------------------------------------------------------------------- 1 | //tabs=4 2 | // -------------------------------------------------------------------------------- 3 | // 4 | // 5 | // ASCOM CoverCalibrtaor driver for ArduinoFlatbox 6 | // 7 | // Description: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam 8 | // nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam 9 | // erat, sed diam voluptua. At vero eos et accusam et justo duo 10 | // dolores et ea rebum. Stet clita kasd gubergren, no sea takimata 11 | // sanctus est Lorem ipsum dolor sit amet. 12 | // 13 | // Implements: ASCOM CoverCalibration interface version: 1 14 | // Author: (SMG) Steven Gill 15 | // 16 | // Edit Log: 17 | // 18 | // Date Who Vers Description 19 | // ----------- --- ----- ------------------------------------------------------- 20 | // 2022-03-05 SMG 0.1.0 Initial edit, created from ASCOM driver template 21 | // -------------------------------------------------------------------------------- 22 | // 23 | 24 | 25 | // This is used to define code in the template that is specific to one class implementation 26 | // unused code can be deleted and this definition removed. 27 | // 28 | #define ArduinoFlatbox 29 | 30 | using System; 31 | using System.Collections.Generic; 32 | using System.Diagnostics; 33 | using System.Text; 34 | using System.Runtime.InteropServices; 35 | 36 | using ASCOM; 37 | using ASCOM.Utilities; 38 | using ASCOM.DeviceInterface; 39 | using System.Globalization; 40 | using System.Collections; 41 | 42 | using System.Threading; 43 | using System.Management; 44 | using System.Net.Sockets; 45 | using System.Net; 46 | 47 | namespace ASCOM.ArduinoFlatbox 48 | { 49 | // 50 | // Your driver's DeviceID is ASCOM.TEMPLATEDEVICENAME.TEMPLATEDEVICECLASS 51 | // 52 | // The Guid attribute sets the CLSID for ASCOM.TEMPLATEDEVICENAME.TEMPLATEDEVICECLASS 53 | // The ClassInterface/None attribute prevents an empty interface called 54 | // _TEMPLATEDEVICENAME from being created and used as the [default] interface 55 | // 56 | // TODO Replace the not implemented exceptions with code to implement the function or 57 | // throw the appropriate ASCOM exception. 58 | // 59 | 60 | /// 61 | /// ASCOM TEMPLATEDEVICECLASS Driver for TEMPLATEDEVICENAME. 62 | /// 63 | [Guid("3A02C211-FA08-4747-B0BD-4B00EB159297")] 64 | [ProgId("ASCOM.ArduinoFlatbox")] 65 | [ClassInterface(ClassInterfaceType.None)] 66 | public class ArduinoFlatbox: ICoverCalibratorV1 67 | { 68 | 69 | internal static string driverID = "ASCOM.ArduinoFlatbox"; 70 | private static string driverDescription = "ArduinoFlatbox"; 71 | 72 | internal static string comPortProfileName = "COM Port"; // Constants used for Profile persistence 73 | internal static string comPortDefault = "COM1"; 74 | internal static string comPort; // Variables to hold the current device configuration 75 | 76 | internal static string connectionTypeName = "Connection Type"; 77 | internal static string connectionTypeDefault = "serial"; 78 | internal static string connectionType; 79 | internal static string iphostName = "host"; 80 | internal static string iphostDefault = "127.0.0.1"; 81 | internal static string iphost; 82 | internal static string portName = "port"; 83 | internal static int portDefault = 2390; 84 | internal static int port; 85 | internal static int transmit_retries = 3; 86 | 87 | internal static string traceStateProfileName = "Trace Level"; 88 | internal static string traceStateDefault = "false"; 89 | internal static ASCOM.Utilities.Serial serialport = new ASCOM.Utilities.Serial(); 90 | 91 | 92 | internal static int brightnesslevel = 0; 93 | internal static int maxbrightness = 255; 94 | internal static bool calibratoron = false; 95 | 96 | 97 | /// 98 | /// Private variable to hold the connected state 99 | /// 100 | private bool connectedState; 101 | 102 | private Util utilities; 103 | //private AstroUtils astroUtilities; 104 | 105 | 106 | internal TraceLogger tl; 107 | 108 | 109 | public ArduinoFlatbox() 110 | { 111 | tl = new TraceLogger("", "ArduinoFlatbox"); 112 | connectedState = false; 113 | ReadProfile(); 114 | 115 | 116 | tl.LogMessage("ArduinoFlatbox", "Starting initialisation"); 117 | 118 | utilities = new Util(); //Initialise util object 119 | //astroUtilities = new AstroUtils(); // Initialise astro-utilities object 120 | 121 | tl.LogMessage("AdruinoFlatbox", "Completed initialisation"); 122 | } 123 | 124 | private bool connect_network_udp() 125 | { 126 | 127 | string message = send_command_network_udp("PING:#"); 128 | 129 | 130 | if (message == "PONG:#") 131 | { 132 | LogMessage("State", "Received state {0}", message); 133 | connectedState = true; 134 | LogMessage("Connected Set", "Connecting to port {0}", comPort); 135 | return true; 136 | } 137 | else 138 | { 139 | connectedState = false; 140 | return false; 141 | } 142 | 143 | } 144 | 145 | 146 | private bool connect_serial() 147 | { 148 | try 149 | { 150 | serialport.PortName = ArduinoFlatbox.comPort; 151 | serialport.Speed = SerialSpeed.ps9600; 152 | serialport.StopBits = SerialStopBits.One; 153 | serialport.Parity = SerialParity.None; 154 | serialport.DataBits = 8; 155 | serialport.Handshake = SerialHandshake.None; 156 | 157 | serialport.DTREnable = true; 158 | serialport.ReceiveTimeout = 5; 159 | serialport.Connected = true; 160 | } 161 | catch (Exception ex) 162 | { 163 | string error_message = "Error opening port: " + ex.Message; 164 | throw new ASCOM.DriverException(error_message); 165 | } 166 | 167 | try 168 | { 169 | LogMessage("Connected set", "Sending Ping"); 170 | 171 | Thread.Sleep(1000); 172 | 173 | 174 | serialport.Transmit("PING:#"); 175 | 176 | string message = "empty"; 177 | message = serialport.ReceiveTerminated("#"); 178 | 179 | if (message == "PONG:#") 180 | { 181 | LogMessage("State", "Received state {0}", message); 182 | connectedState = true; 183 | LogMessage("Connected Set", "Connecting to port {0}", comPort); 184 | return true; 185 | } 186 | else 187 | { 188 | connectedState = false; 189 | return false; 190 | } 191 | } 192 | catch (Exception ex) 193 | { 194 | string error_message = "Error sending / receiving: " + ex.Message; 195 | System.Windows.Forms.MessageBox.Show(error_message); 196 | return false; 197 | } 198 | } 199 | 200 | private string send_command_serial(string command) 201 | { 202 | serialport.Transmit(command); 203 | return serialport.ReceiveTerminated("#"); 204 | } 205 | 206 | private string send_command_network_udp(string command) 207 | { 208 | int retry_counter = transmit_retries; 209 | string message = ""; 210 | UdpClient udpClient = new UdpClient(); 211 | while (message == "" && retry_counter > 0) 212 | { 213 | 214 | try 215 | { 216 | udpClient.Connect(iphost, port); 217 | 218 | // Sends a message to the host to which you have connected. 219 | Byte[] sendBytes = ASCIIEncoding.ASCII.GetBytes(command); 220 | 221 | udpClient.Send(sendBytes, sendBytes.Length); 222 | 223 | //IPEndPoint object will allow us to read datagrams sent from any source. 224 | IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0); 225 | 226 | // Blocks until a message returns on this socket from a remote host. 227 | udpClient.Client.ReceiveTimeout = 5000; 228 | Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint); 229 | message = Encoding.ASCII.GetString(receiveBytes); 230 | 231 | } 232 | 233 | catch (Exception e) 234 | { 235 | Console.WriteLine(e.ToString()); 236 | //System.Windows.Forms.MessageBox.Show(e.ToString()); 237 | retry_counter--; 238 | } 239 | return message; 240 | } 241 | if (retry_counter <= 0) 242 | { 243 | string error_message = "Error connecting to flatbox, please ensure the device is on and connected to the network."; 244 | throw new ASCOM.DriverException(error_message); 245 | } 246 | return ""; 247 | } 248 | 249 | 250 | private int getBrightness() 251 | { 252 | string message = "empty"; 253 | 254 | if (connectionType == "serial") 255 | { 256 | message = send_command_serial("BRIGHT:#"); 257 | } 258 | if (connectionType == "network") 259 | { 260 | message = send_command_network_udp("BRIGHT:#"); 261 | } 262 | 263 | 264 | 265 | string[] subs = message.Split(':'); 266 | 267 | int templevel = Int32.Parse(subs[1]); 268 | 269 | if (templevel >= 0 && templevel <= 255) { 270 | return templevel; 271 | } 272 | else 273 | { 274 | String error_message = "Brightness not between 0 and 255. Attemping to set brightness to 0."; 275 | setBrightness(0); 276 | throw new ASCOM.DriverException(error_message); 277 | } 278 | 279 | } 280 | 281 | 282 | private int setBrightness(int level) 283 | { 284 | if (level >= 0 && level <= 255) 285 | { 286 | string message = "empty"; 287 | string xmit = "SET:" + level.ToString() + ":#"; 288 | 289 | if (connectionType == "serial") 290 | { 291 | message = send_command_serial(xmit); 292 | } 293 | if (connectionType == "network") 294 | { 295 | message = send_command_network_udp(xmit); 296 | } 297 | 298 | string[] subs = message.Split(':'); 299 | 300 | int templevel = Int32.Parse(subs[1]); 301 | 302 | if (templevel == level) 303 | { 304 | return Int32.Parse(subs[1]); 305 | 306 | } 307 | else 308 | { 309 | return 0; 310 | } 311 | } 312 | else 313 | { 314 | send_command_network_udp("0"); 315 | String error_message = "Bug in imaging program: Invalid brightness requested (" + level.ToString() + "), must set brightness between 0 and" + maxbrightness.ToString() + ". Brightness being set to 0." ; 316 | 317 | throw new ASCOM.DriverException(error_message); 318 | //System.Windows.Forms.MessageBox.Show(error_message); 319 | } 320 | 321 | } 322 | // 323 | // PUBLIC COM INTERFACE ITEMPLATEDEVICEINTERFACE IMPLEMENTATION 324 | // 325 | 326 | #region Common properties and methods. 327 | 328 | /// 329 | /// Displays the Setup Dialog form. 330 | /// If the user clicks the OK button to dismiss the form, then 331 | /// the new settings are saved, otherwise the old values are reloaded. 332 | /// THIS IS THE ONLY PLACE WHERE SHOWING USER INTERFACE IS ALLOWED! 333 | /// 334 | public void SetupDialog() 335 | { 336 | // consider only showing the setup dialog if not connected 337 | // or call a different dialog if connected 338 | if (IsConnected) 339 | System.Windows.Forms.MessageBox.Show("Already connected, just press OK"); 340 | 341 | using (SetupDialogForm F = new SetupDialogForm(tl)) 342 | { 343 | var result = F.ShowDialog(); 344 | if (result == System.Windows.Forms.DialogResult.OK) 345 | { 346 | WriteProfile(); // Persist device configuration values to the ASCOM Profile store 347 | } 348 | } 349 | } 350 | 351 | public ArrayList SupportedActions 352 | { 353 | get 354 | { 355 | tl.LogMessage("SupportedActions Get", "Returning empty arraylist"); 356 | return new ArrayList(); 357 | } 358 | } 359 | 360 | public string Action(string actionName, string actionParameters) 361 | { 362 | LogMessage("", "Action {0}, parameters {1} not implemented", actionName, actionParameters); 363 | throw new ASCOM.ActionNotImplementedException("Action " + actionName + " is not implemented by this driver"); 364 | } 365 | 366 | public void CommandBlind(string command, bool raw) 367 | { 368 | CheckConnected("CommandBlind"); 369 | throw new ASCOM.MethodNotImplementedException("CommandBlind"); 370 | } 371 | 372 | public bool CommandBool(string command, bool raw) 373 | { 374 | CheckConnected("CommandBool"); 375 | throw new ASCOM.MethodNotImplementedException("CommandBool"); 376 | } 377 | 378 | public string CommandString(string command, bool raw) 379 | { 380 | CheckConnected("CommandString"); 381 | throw new ASCOM.MethodNotImplementedException("CommandString"); 382 | } 383 | 384 | public void Dispose() 385 | { 386 | // Clean up the trace logger and util objects 387 | tl.Enabled = false; 388 | tl.Dispose(); 389 | tl = null; 390 | utilities.Dispose(); 391 | utilities = null; 392 | //astroUtilities.Dispose(); 393 | //astroUtilities = null; 394 | } 395 | 396 | public bool Connected 397 | { 398 | get 399 | { 400 | LogMessage("Connected", "Get {0}", IsConnected); 401 | return IsConnected; 402 | } 403 | set 404 | { 405 | 406 | 407 | tl.LogMessage("Connected", "Set {0}", value); 408 | if (value == IsConnected) 409 | return; 410 | 411 | if (value) 412 | { 413 | if (connectionType == "serial") 414 | { 415 | connectedState = connect_serial(); 416 | } 417 | 418 | if (connectionType == "network") 419 | { 420 | //connectedState = connect_network(); 421 | connectedState = connect_network_udp(); 422 | 423 | } 424 | 425 | } 426 | else 427 | { 428 | 429 | connectedState = false; 430 | LogMessage("Connected Set", "Disconnecting from port {0}", comPort); 431 | //close serial port 432 | serialport.Connected = false; 433 | } 434 | } 435 | } 436 | 437 | public string Description 438 | { 439 | get 440 | { 441 | tl.LogMessage("Description Get", driverDescription); 442 | return driverDescription; 443 | } 444 | } 445 | 446 | public string DriverInfo 447 | { 448 | get 449 | { 450 | Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; 451 | // TODO customise this driver description 452 | string driverInfo = "Flatbox implemented on Arduino and it's companion firmware. Version: " + String.Format(CultureInfo.InvariantCulture, "{0}.{1}", version.Major, version.Minor); 453 | tl.LogMessage("DriverInfo Get", driverInfo); 454 | return driverInfo; 455 | } 456 | } 457 | 458 | public string DriverVersion 459 | { 460 | get 461 | { 462 | Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; 463 | string driverVersion = String.Format(CultureInfo.InvariantCulture, "{0}.{1}", version.Major, version.Minor); 464 | tl.LogMessage("DriverVersion Get", driverVersion); 465 | return driverVersion; 466 | } 467 | } 468 | 469 | public short InterfaceVersion 470 | { 471 | // set by the driver wizard 472 | get 473 | { 474 | LogMessage("InterfaceVersion Get", "TEMPLATEINTERFACEVERSION"); 475 | return Convert.ToInt16("TEMPLATEINTERFACEVERSION"); 476 | } 477 | } 478 | 479 | public string Name 480 | { 481 | get 482 | { 483 | string name = "Arduino Flatbox"; 484 | tl.LogMessage("Name Get", name); 485 | return name; 486 | } 487 | } 488 | 489 | #endregion 490 | 491 | //INTERFACECODEINSERTIONPOINT 492 | #region Private properties and methods 493 | 494 | #region ICoverCalibrator Implementation 495 | 496 | /// 497 | /// Returns the state of the device cover, if present, otherwise returns "NotPresent" 498 | /// 499 | public CoverStatus CoverState 500 | { 501 | get 502 | { 503 | return CoverStatus.NotPresent; 504 | } 505 | } 506 | 507 | /// 508 | /// Initiates cover opening if a cover is present 509 | /// 510 | public void OpenCover() 511 | { 512 | tl.LogMessage("OpenCover", "Not implemented"); 513 | throw new ASCOM.MethodNotImplementedException("OpenCover"); 514 | } 515 | 516 | /// 517 | /// Initiates cover closing if a cover is present 518 | /// 519 | public void CloseCover() 520 | { 521 | tl.LogMessage("CloseCover", "Not implemented"); 522 | throw new ASCOM.MethodNotImplementedException("CloseCover"); 523 | } 524 | 525 | /// 526 | /// Stops any cover movement that may be in progress if a cover is present and cover movement can be interrupted. 527 | /// 528 | public void HaltCover() 529 | { 530 | tl.LogMessage("HaltCover", "Not implemented"); 531 | throw new ASCOM.MethodNotImplementedException("HaltCover"); 532 | } 533 | 534 | /// 535 | /// Returns the state of the calibration device, if present, otherwise returns "NotPresent" 536 | /// 537 | public CalibratorStatus CalibratorState 538 | { 539 | get 540 | { 541 | return CalibratorStatus.Ready; 542 | } 543 | } 544 | 545 | /// 546 | /// Returns the current calibrator brightness in the range 0 (completely off) to (fully on) 547 | /// 548 | public int Brightness 549 | { 550 | get 551 | { 552 | return getBrightness(); 553 | } 554 | } 555 | 556 | /// 557 | /// The Brightness value that makes the calibrator deliver its maximum illumination. 558 | /// 559 | public int MaxBrightness 560 | { 561 | get 562 | { 563 | return maxbrightness; 564 | } 565 | } 566 | 567 | /// 568 | /// Turns the calibrator on at the specified brightness if the device has calibration capability 569 | /// 570 | /// 571 | public void CalibratorOn(int Brightness) 572 | { 573 | //brightnesslevel = Brightness; 574 | brightnesslevel = setBrightness(Brightness); 575 | calibratoron = true; 576 | } 577 | 578 | /// 579 | /// Turns the calibrator off if the device has calibration capability 580 | /// 581 | public void CalibratorOff() 582 | { 583 | brightnesslevel = setBrightness(0); 584 | calibratoron = false; 585 | } 586 | 587 | #endregion 588 | 589 | 590 | #region ASCOM Registration 591 | 592 | /// If true, registers the driver, otherwise unregisters it. 593 | private static void RegUnregASCOM(bool bRegister) 594 | { 595 | using (var P = new ASCOM.Utilities.Profile()) 596 | { 597 | P.DeviceType = "CoverCalibrator"; 598 | if (bRegister) 599 | { 600 | P.Register(driverID, driverDescription); 601 | } 602 | else 603 | { 604 | P.Unregister(driverID); 605 | } 606 | } 607 | } 608 | 609 | 610 | [ComRegisterFunction] 611 | public static void RegisterASCOM(Type t) 612 | { 613 | RegUnregASCOM(true); 614 | } 615 | 616 | [ComUnregisterFunction] 617 | public static void UnregisterASCOM(Type t) 618 | { 619 | RegUnregASCOM(false); 620 | } 621 | 622 | #endregion 623 | 624 | /// 625 | /// Returns true if there is a valid connection to the driver hardware 626 | /// 627 | private bool IsConnected 628 | { 629 | get 630 | { 631 | // TODO check that the driver hardware connection exists and is connected to the hardware 632 | return connectedState; 633 | } 634 | } 635 | 636 | /// 637 | /// Use this function to throw an exception if we aren't connected to the hardware 638 | /// 639 | /// 640 | private void CheckConnected(string message) 641 | { 642 | if (!IsConnected) 643 | { 644 | throw new ASCOM.NotConnectedException(message); 645 | } 646 | } 647 | 648 | /// 649 | /// Read the device configuration from the ASCOM Profile store 650 | /// 651 | internal void ReadProfile() 652 | { 653 | using (Profile driverProfile = new Profile()) 654 | { 655 | driverProfile.DeviceType = "CoverCalibrator"; 656 | tl.Enabled = Convert.ToBoolean(driverProfile.GetValue(driverID, traceStateProfileName, string.Empty, traceStateDefault)); 657 | comPort = driverProfile.GetValue(driverID, comPortProfileName, string.Empty, comPortDefault); 658 | connectionType = driverProfile.GetValue(driverID, connectionTypeName, string.Empty, connectionTypeDefault); 659 | iphost = driverProfile.GetValue(driverID, iphostName, string.Empty, iphostDefault); 660 | port = Int32.Parse(driverProfile.GetValue(driverID, portName, string.Empty, portDefault.ToString())); 661 | 662 | } 663 | } 664 | 665 | /// 666 | /// Write the device configuration to the ASCOM Profile store 667 | /// 668 | internal void WriteProfile() 669 | { 670 | using (Profile driverProfile = new Profile()) 671 | { 672 | driverProfile.DeviceType = "CoverCalibrator"; 673 | driverProfile.WriteValue(driverID, traceStateProfileName, tl.Enabled.ToString()); 674 | driverProfile.WriteValue(driverID, comPortProfileName, comPort.ToString()); 675 | driverProfile.WriteValue(driverID, connectionTypeName, connectionType.ToString()); 676 | driverProfile.WriteValue(driverID, iphostName, iphost.ToString()); 677 | driverProfile.WriteValue(driverID, portName, port.ToString()); 678 | } 679 | } 680 | 681 | /// 682 | /// Log helper function that takes formatted strings and arguments 683 | /// 684 | /// 685 | /// 686 | /// 687 | internal void LogMessage(string identifier, string message, params object[] args) 688 | { 689 | var msg = string.Format(message, args); 690 | tl.LogMessage(identifier, msg); 691 | } 692 | #endregion 693 | } 694 | } 695 | -------------------------------------------------------------------------------- /ASCOM/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | // 9 | // TODO - Add your authorship information here 10 | [assembly: AssemblyTitle("ASCOM.ArduinoFlatbox.CoverCalibrator")] 11 | [assembly: AssemblyDescription("ASCOM CoverCalibrator driver for TEMPLATEDEVICENAME")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("Steven Gill")] 14 | [assembly: AssemblyProduct("ASCOM CoverCalibrator driver for ArduinoFlatbox")] 15 | [assembly: AssemblyCopyright("Copyright © $year$ Steven Gill")] 16 | [assembly: AssemblyTrademark("GPLv2 See License File")] 17 | [assembly: AssemblyCulture("")] 18 | 19 | // Setting ComVisible to false makes the types in this assembly not visible 20 | // to COM components. If you need to access a type in this assembly from 21 | // COM, set the ComVisible attribute to true on that type. 22 | [assembly: ComVisible(true)] 23 | 24 | // The following GUID is for the ID of the typelib if this project is exposed to COM 25 | [assembly: Guid("28D679BA-2AF1-4557-AE15-C528C5BF91E0")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | // You can specify all the values or you can default the Revision and Build Numbers 35 | // by using the '*' as shown below: 36 | // 37 | // TODO - Set your driver's version here 38 | [assembly: AssemblyVersion("0.1.0.0")] 39 | [assembly: AssemblyFileVersion("0.1.0.0")] 40 | -------------------------------------------------------------------------------- /ASCOM/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace ASCOM.ArduinoFlatbox.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ASCOM.ArduinoFlatbox.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// Looks up a localized resource of type System.Drawing.Bitmap. 65 | /// 66 | internal static System.Drawing.Bitmap ASCOM { 67 | get { 68 | object obj = ResourceManager.GetObject("ASCOM", resourceCulture); 69 | return ((System.Drawing.Bitmap)(obj)); 70 | } 71 | } 72 | 73 | /// 74 | /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). 75 | /// 76 | internal static System.Drawing.Icon DefaultIcon { 77 | get { 78 | object obj = ResourceManager.GetObject("DefaultIcon", resourceCulture); 79 | return ((System.Drawing.Icon)(obj)); 80 | } 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /ASCOM/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 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 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 122 | ..\ASCOM.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 123 | 124 | 125 | ..\ASCOM.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 126 | 127 | -------------------------------------------------------------------------------- /ASCOM/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace ASCOM.ArduinoFlatbox.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.0.3.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ASCOM/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /ASCOM/Resources/ASCOM.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smgill75/ArduinoFlatbox/147e3d02d6b963719ea32f449ec0626344cf05c3/ASCOM/Resources/ASCOM.bmp -------------------------------------------------------------------------------- /ASCOM/Resources/LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | 3 | Version 2, June 1991 4 | 5 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 6 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 7 | 8 | Everyone is permitted to copy and distribute verbatim copies 9 | of this license document, but changing it is not allowed. 10 | Preamble 11 | The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. 12 | 13 | When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. 14 | 15 | To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. 16 | 17 | For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. 18 | 19 | We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. 20 | 21 | Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. 22 | 23 | Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. 24 | 25 | The precise terms and conditions for copying, distribution and modification follow. 26 | 27 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 28 | 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". 29 | 30 | Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 31 | 32 | 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. 33 | 34 | You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 35 | 36 | 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: 37 | 38 | a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. 39 | b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. 40 | c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) 41 | These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. 42 | 43 | Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. 44 | 45 | In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 46 | 47 | 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: 48 | 49 | a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, 50 | b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, 51 | c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) 52 | The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. 53 | 54 | If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 55 | 56 | 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 57 | 58 | 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 59 | 60 | 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 61 | 62 | 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. 63 | 64 | If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. 65 | 66 | It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. 67 | 68 | This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 69 | 70 | 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 71 | 72 | 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. 73 | 74 | Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 75 | 76 | 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. 77 | 78 | NO WARRANTY 79 | 80 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 81 | 82 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -------------------------------------------------------------------------------- /ASCOM/Resources/README.txt: -------------------------------------------------------------------------------- 1 | This project is an intended to provide a codebase for an Arduino Controlled flatbox for astrophotography. 2 | 3 | While there are other examples that utilize the Alnitak command protocol, and I use the techniques to write the 4 | value to the LED pin, I am updating the protocol to make it readable. 5 | 6 | Additionally, the code is intended to allow the user to select WiFi or serial based communications, in the current alpha stage, they both work just fine 7 | A configurator program needs to still be created to allow an end user to plug in a USB-B cable to the arduino and configure wifi paramterers. Currently a user will 8 | need to send a command manually of the serial connection to configure the WiFi parameters. 9 | 10 | If using serially, I recommend disabling WiFi 11 | 12 | ASCOM driver has been tested with NINA (my primary imaging software) and SGP 13 | 14 | 15 | Good luck and feel free to report bugs or submit patches. -------------------------------------------------------------------------------- /ASCOM/Resources/WizardImage.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smgill75/ArduinoFlatbox/147e3d02d6b963719ea32f449ec0626344cf05c3/ASCOM/Resources/WizardImage.bmp -------------------------------------------------------------------------------- /ASCOM/SetupDialogForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Drawing; 5 | using System.Runtime.InteropServices; 6 | using System.Text; 7 | using System.Windows.Forms; 8 | using ASCOM.Utilities; 9 | using ASCOM.ArduinoFlatbox; 10 | using System.Management; 11 | 12 | namespace ASCOM.ArduinoFlatbox 13 | { 14 | [ComVisible(false)] // Form not registered for COM! 15 | public partial class SetupDialogForm : Form 16 | { 17 | TraceLogger tl; // Holder for a reference to the driver's trace logger 18 | 19 | public SetupDialogForm(TraceLogger tlDriver) 20 | { 21 | InitializeComponent(); 22 | 23 | // Save the provided trace logger for use within the setup dialogue 24 | tl = tlDriver; 25 | 26 | if (ArduinoFlatbox.connectionType == "network") 27 | { 28 | rdwifi.Checked = true; 29 | } 30 | else 31 | { 32 | rdSerial.Checked = true; 33 | } 34 | txtport.Text = ArduinoFlatbox.port.ToString(); 35 | txtIP.Text = ArduinoFlatbox.iphost.ToString(); 36 | // Initialise current values of user settings from the ASCOM Profile 37 | InitUI(); 38 | } 39 | 40 | private void cmdOK_Click(object sender, EventArgs e) // OK button event handler 41 | { 42 | // Place any validation constraint checks here 43 | // Update the state variables with results from the dialogue 44 | if (rdwifi.Checked == true) 45 | { 46 | ArduinoFlatbox.connectionType = "network"; 47 | ArduinoFlatbox.iphost = txtIP.Text; 48 | ArduinoFlatbox.port = Int32.Parse(txtport.Text); 49 | } 50 | else if (rdSerial.Checked == true && comboBoxComPort.Items.Count > 0) 51 | { 52 | ArduinoFlatbox.connectionType = "serial"; 53 | ArduinoFlatbox.comPort = (string)comboBoxComPort.SelectedItem; 54 | } 55 | 56 | } 57 | 58 | private void cmdCancel_Click(object sender, EventArgs e) // Cancel button event handler 59 | { 60 | Close(); 61 | } 62 | 63 | private void BrowseToAscom(object sender, EventArgs e) // Click on ASCOM logo event handler 64 | { 65 | try 66 | { 67 | System.Diagnostics.Process.Start("https://ascom-standards.org/"); 68 | } 69 | catch (System.ComponentModel.Win32Exception noBrowser) 70 | { 71 | if (noBrowser.ErrorCode == -2147467259) 72 | MessageBox.Show(noBrowser.Message); 73 | } 74 | catch (System.Exception other) 75 | { 76 | MessageBox.Show(other.Message); 77 | } 78 | } 79 | 80 | private void InitUI() 81 | { 82 | // set the list of com ports to those that are currently available 83 | string[] comports = System.IO.Ports.SerialPort.GetPortNames(); // use System.IO because it's static 84 | comboBoxComPort.Items.Clear(); 85 | if (comports.Length > 0) 86 | { 87 | comboBoxComPort.Items.AddRange(comports); 88 | } 89 | // select the current port if possible 90 | 91 | if (comboBoxComPort.Items.Contains(ArduinoFlatbox.comPort)) 92 | { 93 | comboBoxComPort.SelectedItem = ArduinoFlatbox.comPort; 94 | } 95 | else if (comports.Length > 0 ) 96 | { 97 | comboBoxComPort.SelectedItem = comboBoxComPort.Items[0]; 98 | } 99 | } 100 | 101 | private void radioButton1_CheckedChanged(object sender, EventArgs e) 102 | { 103 | comboBoxComPort.Enabled = true; 104 | txtIP.Enabled = false; 105 | txtport.Enabled = false; 106 | } 107 | 108 | private void rdwifi_CheckedChanged(object sender, EventArgs e) 109 | { 110 | txtIP.Enabled = true; 111 | txtport.Enabled = true; 112 | comboBoxComPort.Enabled=false; 113 | } 114 | } 115 | } -------------------------------------------------------------------------------- /ASCOM/SetupDialogForm.designer.cs: -------------------------------------------------------------------------------- 1 | namespace ASCOM.ArduinoFlatbox 2 | { 3 | partial class SetupDialogForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.cmdOK = new System.Windows.Forms.Button(); 32 | this.cmdCancel = new System.Windows.Forms.Button(); 33 | this.label1 = new System.Windows.Forms.Label(); 34 | this.picASCOM = new System.Windows.Forms.PictureBox(); 35 | this.label2 = new System.Windows.Forms.Label(); 36 | this.comboBoxComPort = new System.Windows.Forms.ComboBox(); 37 | this.rdSerial = new System.Windows.Forms.RadioButton(); 38 | this.rdwifi = new System.Windows.Forms.RadioButton(); 39 | this.panel1 = new System.Windows.Forms.Panel(); 40 | this.lbNet = new System.Windows.Forms.Label(); 41 | this.txtIP = new System.Windows.Forms.TextBox(); 42 | this.txtport = new System.Windows.Forms.TextBox(); 43 | this.label3 = new System.Windows.Forms.Label(); 44 | ((System.ComponentModel.ISupportInitialize)(this.picASCOM)).BeginInit(); 45 | this.panel1.SuspendLayout(); 46 | this.SuspendLayout(); 47 | // 48 | // cmdOK 49 | // 50 | this.cmdOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 51 | this.cmdOK.DialogResult = System.Windows.Forms.DialogResult.OK; 52 | this.cmdOK.Location = new System.Drawing.Point(520, 92); 53 | this.cmdOK.Name = "cmdOK"; 54 | this.cmdOK.Size = new System.Drawing.Size(59, 24); 55 | this.cmdOK.TabIndex = 0; 56 | this.cmdOK.Text = "OK"; 57 | this.cmdOK.UseVisualStyleBackColor = true; 58 | this.cmdOK.Click += new System.EventHandler(this.cmdOK_Click); 59 | // 60 | // cmdCancel 61 | // 62 | this.cmdCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 63 | this.cmdCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; 64 | this.cmdCancel.Location = new System.Drawing.Point(520, 122); 65 | this.cmdCancel.Name = "cmdCancel"; 66 | this.cmdCancel.Size = new System.Drawing.Size(59, 25); 67 | this.cmdCancel.TabIndex = 1; 68 | this.cmdCancel.Text = "Cancel"; 69 | this.cmdCancel.UseVisualStyleBackColor = true; 70 | this.cmdCancel.Click += new System.EventHandler(this.cmdCancel_Click); 71 | // 72 | // label1 73 | // 74 | this.label1.Location = new System.Drawing.Point(12, 9); 75 | this.label1.Name = "label1"; 76 | this.label1.Size = new System.Drawing.Size(193, 31); 77 | this.label1.TabIndex = 2; 78 | this.label1.Text = "Arduino Flatbox Configuration"; 79 | // 80 | // picASCOM 81 | // 82 | this.picASCOM.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 83 | this.picASCOM.Cursor = System.Windows.Forms.Cursors.Hand; 84 | this.picASCOM.Image = global::ASCOM.ArduinoFlatbox.Properties.Resources.ASCOM; 85 | this.picASCOM.Location = new System.Drawing.Point(531, 9); 86 | this.picASCOM.Name = "picASCOM"; 87 | this.picASCOM.Size = new System.Drawing.Size(48, 56); 88 | this.picASCOM.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; 89 | this.picASCOM.TabIndex = 3; 90 | this.picASCOM.TabStop = false; 91 | this.picASCOM.Click += new System.EventHandler(this.BrowseToAscom); 92 | this.picASCOM.DoubleClick += new System.EventHandler(this.BrowseToAscom); 93 | // 94 | // label2 95 | // 96 | this.label2.AutoSize = true; 97 | this.label2.Location = new System.Drawing.Point(180, 46); 98 | this.label2.Name = "label2"; 99 | this.label2.Size = new System.Drawing.Size(53, 13); 100 | this.label2.TabIndex = 5; 101 | this.label2.Text = "COM Port"; 102 | // 103 | // comboBoxComPort 104 | // 105 | this.comboBoxComPort.FormattingEnabled = true; 106 | this.comboBoxComPort.Location = new System.Drawing.Point(244, 41); 107 | this.comboBoxComPort.Name = "comboBoxComPort"; 108 | this.comboBoxComPort.Size = new System.Drawing.Size(100, 21); 109 | this.comboBoxComPort.TabIndex = 7; 110 | // 111 | // rdSerial 112 | // 113 | this.rdSerial.AutoSize = true; 114 | this.rdSerial.Location = new System.Drawing.Point(6, 3); 115 | this.rdSerial.Name = "rdSerial"; 116 | this.rdSerial.Size = new System.Drawing.Size(108, 17); 117 | this.rdSerial.TabIndex = 8; 118 | this.rdSerial.TabStop = true; 119 | this.rdSerial.Text = "Serial Connection"; 120 | this.rdSerial.UseVisualStyleBackColor = true; 121 | this.rdSerial.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged); 122 | // 123 | // rdwifi 124 | // 125 | this.rdwifi.AutoSize = true; 126 | this.rdwifi.Location = new System.Drawing.Point(6, 31); 127 | this.rdwifi.Name = "rdwifi"; 128 | this.rdwifi.Size = new System.Drawing.Size(102, 17); 129 | this.rdwifi.TabIndex = 9; 130 | this.rdwifi.TabStop = true; 131 | this.rdwifi.Text = "WiFi connection"; 132 | this.rdwifi.UseVisualStyleBackColor = true; 133 | this.rdwifi.CheckedChanged += new System.EventHandler(this.rdwifi_CheckedChanged); 134 | // 135 | // panel1 136 | // 137 | this.panel1.Controls.Add(this.rdwifi); 138 | this.panel1.Controls.Add(this.rdSerial); 139 | this.panel1.Location = new System.Drawing.Point(15, 43); 140 | this.panel1.Name = "panel1"; 141 | this.panel1.Size = new System.Drawing.Size(135, 66); 142 | this.panel1.TabIndex = 10; 143 | // 144 | // lbNet 145 | // 146 | this.lbNet.AutoSize = true; 147 | this.lbNet.Location = new System.Drawing.Point(162, 77); 148 | this.lbNet.Name = "lbNet"; 149 | this.lbNet.Size = new System.Drawing.Size(76, 13); 150 | this.lbNet.TabIndex = 11; 151 | this.lbNet.Text = "IP / Hostname"; 152 | // 153 | // txtIP 154 | // 155 | this.txtIP.Location = new System.Drawing.Point(244, 73); 156 | this.txtIP.Name = "txtIP"; 157 | this.txtIP.Size = new System.Drawing.Size(125, 20); 158 | this.txtIP.TabIndex = 12; 159 | // 160 | // txtport 161 | // 162 | this.txtport.Location = new System.Drawing.Point(244, 99); 163 | this.txtport.Name = "txtport"; 164 | this.txtport.Size = new System.Drawing.Size(100, 20); 165 | this.txtport.TabIndex = 13; 166 | // 167 | // label3 168 | // 169 | this.label3.AutoSize = true; 170 | this.label3.Location = new System.Drawing.Point(207, 103); 171 | this.label3.Name = "label3"; 172 | this.label3.Size = new System.Drawing.Size(26, 13); 173 | this.label3.TabIndex = 14; 174 | this.label3.Text = "Port"; 175 | // 176 | // SetupDialogForm 177 | // 178 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 179 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 180 | this.ClientSize = new System.Drawing.Size(589, 155); 181 | this.Controls.Add(this.label3); 182 | this.Controls.Add(this.txtport); 183 | this.Controls.Add(this.txtIP); 184 | this.Controls.Add(this.lbNet); 185 | this.Controls.Add(this.panel1); 186 | this.Controls.Add(this.comboBoxComPort); 187 | this.Controls.Add(this.label2); 188 | this.Controls.Add(this.picASCOM); 189 | this.Controls.Add(this.label1); 190 | this.Controls.Add(this.cmdCancel); 191 | this.Controls.Add(this.cmdOK); 192 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; 193 | this.MaximizeBox = false; 194 | this.MinimizeBox = false; 195 | this.Name = "SetupDialogForm"; 196 | this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; 197 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 198 | this.Text = "Arduino Flatbox Setup"; 199 | ((System.ComponentModel.ISupportInitialize)(this.picASCOM)).EndInit(); 200 | this.panel1.ResumeLayout(false); 201 | this.panel1.PerformLayout(); 202 | this.ResumeLayout(false); 203 | this.PerformLayout(); 204 | 205 | } 206 | 207 | #endregion 208 | 209 | private System.Windows.Forms.Button cmdOK; 210 | private System.Windows.Forms.Button cmdCancel; 211 | private System.Windows.Forms.Label label1; 212 | private System.Windows.Forms.PictureBox picASCOM; 213 | private System.Windows.Forms.Label label2; 214 | private System.Windows.Forms.ComboBox comboBoxComPort; 215 | private System.Windows.Forms.RadioButton rdSerial; 216 | private System.Windows.Forms.RadioButton rdwifi; 217 | private System.Windows.Forms.Panel panel1; 218 | private System.Windows.Forms.Label lbNet; 219 | private System.Windows.Forms.TextBox txtIP; 220 | private System.Windows.Forms.TextBox txtport; 221 | private System.Windows.Forms.Label label3; 222 | } 223 | } -------------------------------------------------------------------------------- /ASCOM/SetupDialogForm.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 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 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /ASCOM/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ASCOM/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Arduino_Sketch/ArduinoFlatBox/ArduinoFlatBox.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Protocol definitions: 4 | Command word is followed by a ":" to seprate fields and terminated with a ":#" Just makes reading it easier it the simple protocol parser 5 | 6 | 7 | Serial *and* WiFi: 8 | Command received Command returned to drivrer 9 | PING:# looks for device PONG:# 10 | SET::# set s brightness value SET::# returns value requested for sanity check 11 | and writes to analog pin 12 | BRIGHT:# BRIGHT::# returns the current brightness level 13 | 14 | 15 | Serial Only 16 | GETCONFIG:# asks for config GETCONFIG::::::::# - sorry, will not return password of your wifi 17 | 18 | 19 | SETCONFIG:values:# SETCONFIG: returns 0 or 1 if configuration change was successful or not 20 | Values in config (in order) 21 | enable wifi (0 or 1) 22 | static IP or DHCP (1 for static, 0 for DHCP) 23 | IP address (string format, e.g. 192.168.1.230) 24 | Subnet mask (string format, e.g. 255.255.255.0) 25 | DNS server (string format, e.g. 192.168.1.1) 26 | Default gateway (string format, e.g. 192.168.1.1) 27 | WiFi SSID = text string 28 | WiFi Password = text string 29 | 30 | TODO: decide if there is a wildcard in the GUI (e.g.8 "*" and determine to maintain the password stored in EEPROM since we will not send the password back via serial) 31 | 32 | example: 33 | SETCONFIG:1:1:192.168.1.230:255.255.255.0:192.168.1.1:192.168.1.1:my_ssid:my_password:# would set wifi on and static IP based on above parameters 34 | SETCONFIG:1:0:::::my_ssid:my_password:# would set wifi on and DHCP. Data would be clear. A driver side call can still set this if you want to use get config and preserve it between calls. 35 | SETCONFIG:0:0::::::::# would set it to serial only. 36 | 37 | 38 | TODO: set timesouts on WiFi connect so that serial is usable and makes the below statement true. Also, define a period of time in which entire setup to WiFi just "gives up" 39 | Note: serial will always work, even when connected to WiFi, but if Wifi is enabled but not present, performance may suffer / lag due to reconnect attempts and waiting for timeouts. 40 | 41 | */ 42 | 43 | // use if NINA baords like MKR WiFi 1010, Arduino MKR VIDOR 4000, Arduino UNO WiFi Rev.2 and Nano 33 IoT 44 | #include 45 | // Use if MKR1000 or other 101 boards 46 | // #include 47 | #include 48 | #include 49 | 50 | 51 | // all of this struct maintains config for persitence between power cycles and is loaded from EEPROMex which allows block loading of the struct. 52 | // EEPROMex is good too, because it checks the state of EERPOM before committing a write. If the user sends the config and it hasn't change, it won't add a cyclle to the EERPOm 53 | // This particular use case has a very low likelihood to overwhelm the EEPROM, but it is worth it 54 | 55 | // Note: as of 3/16/2022 there is a known issue with EERPOMex and Boards such as the NANO wifi rev2. It's not the EEPROMex per se as much as the isready calling EEPROM.h for this board. 56 | // if compiling yourself, move the EEPROMex.cpp into your library. Note: here is the diff starting at line 98: 57 | 58 | //Orig: 59 | // /** 60 | // * Check if EEPROM memory is ready to be accessed 61 | // */ 62 | //bool EEPROMClassEx::isReady() { 63 | // return eeprom_is_ready(); 64 | //} 65 | 66 | //New: 67 | // /** 68 | // * Check if EEPROM memory is ready to be accessed 69 | // */ 70 | //bool EEPROMClassEx::isReady() { 71 | // #if defined(ARDUINO_ARCH_MEGAAVR) //work around a bug in 72 | // return bit_is_clear(NVMCTRL.STATUS,NVMCTRL_EEBUSY_bp); 73 | // #else 74 | // return eeprom_is_ready(); 75 | // #endif 76 | //} 77 | 78 | 79 | 80 | // 81 | struct configuration { 82 | bool wifi_enable = false; 83 | bool static_ip = false; 84 | int wifi_ip[4]; 85 | int subnet[4]; 86 | int dns[4]; 87 | int gateway[4]; 88 | char ssid[32]; 89 | char pass[64]; 90 | }; configuration my_config; 91 | 92 | volatile int ledPin = 10; // the pin that the LED is attached to, needs to be a PWM pin. 93 | int brightness = 0; 94 | char packetBuffer[256]; //buffer to hold incoming packet 95 | WiFiUDP Udp; 96 | int status = WL_IDLE_STATUS; 97 | int brightlevel = 0; 98 | unsigned int localPort = 2390; 99 | 100 | void setup() { 101 | int retries = 5; 102 | Serial.begin(9600,SERIAL_8N1); 103 | //Serial.println("Starting up..."); 104 | 105 | // set defaults for config prior to reading from EEPROM 106 | //load_defaults(); 107 | //write_config(); 108 | //preload the configuration from EEPROM 109 | // TODO: determine that EEPROM was never written and initialize default values 110 | read_config(); 111 | 112 | // initialize the ledPin as an output: 113 | pinMode(ledPin, OUTPUT); 114 | // set brightness to 0 115 | analogWrite(ledPin, 0); 116 | 117 | // if the config says wifi is enabled, start it up 118 | if (my_config.wifi_enable) { 119 | 120 | if (my_config.static_ip) { 121 | // build IP structs from int arrays store in config struct 122 | IPAddress ip = IPAddress(my_config.wifi_ip[0], my_config.wifi_ip[1], my_config.wifi_ip[2], my_config.wifi_ip[3]); 123 | IPAddress dns = IPAddress(my_config.dns[0], my_config.dns[1], my_config.dns[2], my_config.dns[3]); 124 | IPAddress gateway = IPAddress(my_config.gateway[0], my_config.gateway[1], my_config.gateway[2], my_config.gateway[3]); 125 | IPAddress subnet = IPAddress(my_config.subnet[0], my_config.subnet[1], my_config.subnet[2], my_config.subnet[3]); 126 | 127 | 128 | WiFi.config(ip, dns, gateway, subnet); 129 | } 130 | while (status != WL_CONNECTED && retries >0) { 131 | retries--; 132 | status = WiFi.begin(my_config.ssid, my_config.pass); 133 | delay(1000); 134 | } 135 | if (retries > 0) { 136 | Udp.begin(localPort); 137 | } 138 | else { 139 | //my_config.wifi_enable 140 | Serial.println("Timeout connecting WiFi. Giving up."); 141 | } 142 | } 143 | } 144 | 145 | void loop() { 146 | handleSerial(); 147 | if(my_config.wifi_enable) { 148 | handleUDP(); 149 | } 150 | } 151 | 152 | void handleUDP () { 153 | int packetSize = Udp.parsePacket(); 154 | String commandresponse = "PONG:#"; 155 | String command; 156 | String setting; 157 | String buffertostring; 158 | String terminator = ":#"; 159 | String ackcommand; 160 | 161 | if (packetSize) { 162 | IPAddress remoteIp = Udp.remoteIP(); 163 | 164 | // read the packet into packetBufffer 165 | command = Udp.readStringUntil(':'); 166 | setting = Udp.readStringUntil('#'); 167 | 168 | if (command == "PING"){ 169 | commandresponse = "PONG:#"; 170 | } 171 | 172 | if (command == "BRIGHT"){ 173 | ackcommand = "BRIGHT:"; 174 | commandresponse = ackcommand + brightlevel + terminator; 175 | } 176 | 177 | if (command == "SET") { 178 | brightlevel = setting.toInt(); 179 | analogWrite(ledPin, brightlevel); 180 | ackcommand = "SET:"; 181 | commandresponse = ackcommand + brightlevel + terminator; 182 | } 183 | 184 | char ReplyBuffer[commandresponse.length()+1]; 185 | commandresponse.toCharArray(ReplyBuffer, commandresponse.length()+1); 186 | Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); 187 | Udp.write(ReplyBuffer); 188 | Udp.endPacket(); 189 | } 190 | } 191 | 192 | 193 | void handleSerial() { 194 | String command; 195 | String setting; 196 | int i; 197 | 198 | while ( Serial.available() > 0 ) { 199 | command = Serial.readStringUntil(':'); 200 | if (command == "PING"){ 201 | setting = Serial.readStringUntil('#'); 202 | Serial.println("PONG:#"); 203 | } 204 | 205 | if (command == "BRIGHT"){ 206 | setting = Serial.readStringUntil('#'); 207 | Serial.print("BRIGHT:"); Serial.print(brightlevel); Serial.println(":#"); 208 | } 209 | 210 | if (command == "SET") { 211 | setting = Serial.readStringUntil('#'); 212 | brightlevel = setting.toInt(); 213 | analogWrite(ledPin, brightlevel); 214 | Serial.print("SET:"); Serial.print(brightlevel); Serial.println(":#"); 215 | } 216 | 217 | if (command == "GETCONFIG") { 218 | setting = Serial.readStringUntil('#'); 219 | Serial.print("GETCONFIG"); 220 | Serial.print(':'); 221 | Serial.print(String(my_config.wifi_enable)); 222 | Serial.print(':'); 223 | Serial.print(my_config.static_ip); 224 | Serial.print(':'); 225 | // print static IP config 226 | for (i=0; i<4; i++){ 227 | Serial.print(my_config.wifi_ip[i]); 228 | if (i !=3){ 229 | Serial.print('.'); 230 | } 231 | } 232 | Serial.print(':'); 233 | 234 | //subnet 235 | for (i=0; i<4; i++){ 236 | Serial.print(my_config.subnet[i]); 237 | if (i !=3){ 238 | Serial.print('.'); 239 | } 240 | } 241 | Serial.print(':'); 242 | 243 | // dns 244 | for (i=0; i<4; i++){ 245 | Serial.print(my_config.dns[i]); 246 | if (i !=3){ 247 | Serial.print('.'); 248 | } 249 | } 250 | Serial.print(':'); 251 | 252 | //gateway 253 | for (i=0; i<4; i++){ 254 | Serial.print(my_config.gateway[i]); 255 | if (i !=3){ 256 | Serial.print('.'); 257 | } 258 | } 259 | Serial.print(':'); 260 | Serial.println(String(my_config.ssid) + ":#"); 261 | } 262 | if (command == "SETCONFIG") { 263 | /* we expect these parameters 264 | * enable wifi 265 | * static ip or DHCP 266 | * IP address 267 | * Subnet mask 268 | * dns server 269 | * default gateway 270 | * 271 | */ 272 | 273 | // TODO: evaluate inputs and discard if malformed. We currently expect perfect input 274 | 275 | // enable wifi? 276 | setting = Serial.readStringUntil(':'); 277 | if (setting == "1") { 278 | my_config.wifi_enable = true; 279 | } 280 | else { 281 | my_config.wifi_enable = false; 282 | } 283 | 284 | // static or DHCP? 285 | setting = Serial.readStringUntil(':'); 286 | if (setting == "1") { 287 | my_config.static_ip = true; 288 | } 289 | else { 290 | my_config.static_ip = false; 291 | } 292 | 293 | // ip address 294 | for (i=0; i<4; i++) { 295 | if (i < 3) { 296 | setting = Serial.readStringUntil('.'); 297 | } 298 | else { 299 | setting = Serial.readStringUntil(':'); 300 | } 301 | my_config.wifi_ip[i] = setting.toInt(); 302 | } 303 | // subnet_mask 304 | for (i=0; i<4; i++) { 305 | if (i < 3) { 306 | setting = Serial.readStringUntil('.'); 307 | } 308 | else { 309 | setting = Serial.readStringUntil(':'); 310 | } 311 | my_config.subnet[i] = setting.toInt(); 312 | } 313 | 314 | // dns 315 | for (i=0; i<4; i++) { 316 | if (i < 3) { 317 | setting = Serial.readStringUntil('.'); 318 | } 319 | else { 320 | setting = Serial.readStringUntil(':'); 321 | } 322 | my_config.dns[i] = setting.toInt(); 323 | } 324 | 325 | // default gateway 326 | for (i=0; i<4; i++) { 327 | if (i < 3) { 328 | setting = Serial.readStringUntil('.'); 329 | } 330 | else { 331 | setting = Serial.readStringUntil(':'); 332 | } 333 | my_config.gateway[i] = setting.toInt(); 334 | } 335 | //wifi ssid 336 | setting = Serial.readStringUntil(':'); 337 | setting.toCharArray(my_config.ssid, sizeof(my_config.ssid)+1); 338 | 339 | 340 | //wifi pass 341 | setting = Serial.readStringUntil('#'); 342 | //Serial.println(setting); 343 | setting.toCharArray(my_config.pass, sizeof(my_config.pass)+1); 344 | //Serial.println(my_config.pass); 345 | delay(1000); 346 | 347 | write_config(); 348 | delay(1000); 349 | Serial.println("SETCONFIG:#"); 350 | } 351 | 352 | } 353 | } 354 | 355 | void read_config() { 356 | EEPROM.readBlock(0, my_config); 357 | } 358 | 359 | void write_config() { 360 | EEPROM.writeBlock(0, my_config); 361 | } 362 | 363 | void load_defaults() { 364 | // make serial only and put placeholders in for static IP and wifi parameters 365 | my_config.wifi_enable = false; 366 | my_config.static_ip = false; 367 | 368 | my_config.wifi_ip[0] = 192; 369 | my_config.wifi_ip[1] = 168; 370 | my_config.wifi_ip[2] = 1; 371 | my_config.wifi_ip[3] = 200; 372 | 373 | my_config.subnet[0] = 255; 374 | my_config.subnet[1] = 255; 375 | my_config.subnet[2] = 255; 376 | my_config.subnet[3] = 0; 377 | 378 | my_config.dns[0] = 192; 379 | my_config.dns[1] = 168; 380 | my_config.dns[2] = 1; 381 | my_config.dns[3] = 1; 382 | 383 | my_config.gateway[0] = 192; 384 | my_config.gateway[1] = 168; 385 | my_config.gateway[2] = 1; 386 | my_config.gateway[3] = 1; 387 | 388 | strcpy(my_config.ssid, "your_ssid"); 389 | strcpy(my_config.pass, "your_pass"); 390 | 391 | } 392 | 393 | 394 | // residual debug functions 395 | 396 | void printWifiData() { 397 | 398 | // print your board's IP address: 399 | 400 | IPAddress ip = WiFi.localIP(); 401 | 402 | Serial.print("IP Address: "); 403 | 404 | Serial.println(ip); 405 | } 406 | 407 | void printCurrentNet() { 408 | 409 | // print the SSID of the network you're attached to: 410 | Serial.print("SSID: "); 411 | Serial.println(WiFi.SSID()); 412 | 413 | // print the MAC address of the router you're attached to: 414 | 415 | byte bssid[6]; 416 | WiFi.BSSID(bssid); 417 | Serial.print("BSSID: "); 418 | // print the received signal strength: 419 | long rssi = WiFi.RSSI(); 420 | Serial.print("signal strength (RSSI):"); 421 | Serial.println(rssi); 422 | // print the encryption type: 423 | byte encryption = WiFi.encryptionType(); 424 | Serial.print("Encryption Type:"); 425 | Serial.println(encryption, HEX); 426 | Serial.println(); 427 | } 428 | -------------------------------------------------------------------------------- /Arduino_Sketch/EEPROMex/EEPROMex.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | EEPROMEx.cpp - Extended EEPROM library 3 | Copyright (c) 2012 Thijs Elenbaas. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | /****************************************************************************** 21 | * Includes 22 | ******************************************************************************/ 23 | #include "EEPROMex.h" 24 | 25 | /****************************************************************************** 26 | * Definitions 27 | ******************************************************************************/ 28 | 29 | #define _EEPROMEX_VERSION 1_0_0 // software version of this library 30 | #define _EEPROMEX_DEBUG // Enables logging of maximum of writes and out-of-memory 31 | /****************************************************************************** 32 | * Constructors 33 | ******************************************************************************/ 34 | 35 | // Boards with ATmega328, Duemilanove, Uno, Uno SMD, Lilypad - 1024 bytes (1 kilobyte) 36 | // Boards with ATmega1280 or 2560, Arduino Mega series – 4096 bytes (4 kilobytes) 37 | // Boards with ATmega168, Lilypad, old Nano, Diecimila – 512 bytes 38 | // By default we choose conservative settings 39 | EEPROMClassEx::EEPROMClassEx() 40 | : _allowedWrites(100) 41 | { 42 | } 43 | 44 | /****************************************************************************** 45 | * User API 46 | ******************************************************************************/ 47 | 48 | /** 49 | * Set starting position and memory size that EEPROMEx may manage 50 | */ 51 | void EEPROMClassEx::setMemPool(int base, int memSize) { 52 | //Base can only be adjusted if no addresses have already been issued 53 | if (_nextAvailableaddress == _base) 54 | _base = base; 55 | _nextAvailableaddress=_base; 56 | 57 | //Ceiling can only be adjusted if not below issued addresses 58 | if (memSize >= _nextAvailableaddress ) 59 | _memSize = memSize; 60 | 61 | #ifdef _EEPROMEX_DEBUG 62 | if (_nextAvailableaddress != _base) 63 | Serial.println("Cannot change base, addresses have been issued"); 64 | 65 | if (memSize < _nextAvailableaddress ) 66 | Serial.println("Cannot change ceiling, below issued addresses"); 67 | #endif 68 | 69 | } 70 | 71 | /** 72 | * Set global maximum of allowed writes 73 | */ 74 | void EEPROMClassEx::setMaxAllowedWrites(int allowedWrites) { 75 | #ifdef _EEPROMEX_DEBUG 76 | _allowedWrites = allowedWrites; 77 | #endif 78 | } 79 | 80 | /** 81 | * Get a new starting address to write to. Adress is negative if not enough space is available 82 | */ 83 | int EEPROMClassEx::getAddress(int noOfBytes){ 84 | int availableaddress = _nextAvailableaddress; 85 | _nextAvailableaddress += noOfBytes; 86 | 87 | #ifdef _EEPROMEX_DEBUG 88 | if (_nextAvailableaddress > _memSize) { 89 | Serial.println("Attempt to write outside of EEPROM memory"); 90 | return -availableaddress; 91 | } else { 92 | return availableaddress; 93 | } 94 | #endif 95 | return availableaddress; 96 | } 97 | 98 | /** 99 | * Check if EEPROM memory is ready to be accessed 100 | */ 101 | bool EEPROMClassEx::isReady() { 102 | #if defined(ARDUINO_ARCH_MEGAAVR) //work around a bug in 103 | return bit_is_clear(NVMCTRL.STATUS,NVMCTRL_EEBUSY_bp); 104 | #else 105 | return eeprom_is_ready(); 106 | #endif 107 | } 108 | 109 | /** 110 | * Read a single byte 111 | * This function performs as readByte and is added to be similar to the EEPROM library 112 | */ 113 | uint8_t EEPROMClassEx::read(int address) 114 | { 115 | return readByte(address); 116 | } 117 | 118 | /** 119 | * Read a single bit 120 | */ 121 | bool EEPROMClassEx::readBit(int address, byte bit) { 122 | if (bit> 7) return false; 123 | if (!isReadOk(address+sizeof(uint8_t))) return false; 124 | byte byteVal = eeprom_read_byte((unsigned char *) address); 125 | byte bytePos = (1 << bit); 126 | return (byteVal & bytePos); 127 | } 128 | 129 | /** 130 | * Read a single byte 131 | */ 132 | uint8_t EEPROMClassEx::readByte(int address) 133 | { 134 | if (!isReadOk(address+sizeof(uint8_t))) return 0; 135 | return eeprom_read_byte((unsigned char *) address); 136 | } 137 | 138 | /** 139 | * Read a single 16 bits integer 140 | */ 141 | uint16_t EEPROMClassEx::readInt(int address) 142 | { 143 | if (!isReadOk(address+sizeof(uint16_t))) return 0; 144 | return eeprom_read_word((uint16_t *) address); 145 | } 146 | 147 | /** 148 | * Read a single 32 bits integer 149 | */ 150 | uint32_t EEPROMClassEx::readLong(int address) 151 | { 152 | if (!isReadOk(address+sizeof(uint32_t))) return 0; 153 | return eeprom_read_dword((unsigned long *) address); 154 | } 155 | 156 | /** 157 | * Read a single float value 158 | */ 159 | float EEPROMClassEx::readFloat(int address) 160 | { 161 | if (!isReadOk(address+sizeof(float))) return 0; 162 | float _value; 163 | readBlock(address, _value); 164 | return _value; 165 | } 166 | 167 | /** 168 | * Read a single double value (size will depend on board type) 169 | */ 170 | double EEPROMClassEx::readDouble(int address) 171 | { 172 | if (!isReadOk(address+sizeof(double))) return 0; 173 | double _value; 174 | readBlock(address, _value); 175 | return _value; 176 | } 177 | 178 | /** 179 | * Write a single byte 180 | * This function performs as writeByte and is added to be similar to the EEPROM library 181 | */ 182 | bool EEPROMClassEx::write(int address, uint8_t value) 183 | { 184 | return writeByte(address, value); 185 | } 186 | 187 | /** 188 | * Write a single bit 189 | */ 190 | bool EEPROMClassEx::writeBit(int address, uint8_t bit, bool value) { 191 | updateBit(address, bit, value); 192 | return true; 193 | } 194 | 195 | /** 196 | * Write a single byte 197 | */ 198 | bool EEPROMClassEx::writeByte(int address, uint8_t value) 199 | { 200 | if (!isWriteOk(address+sizeof(uint8_t))) return false; 201 | eeprom_write_byte((unsigned char *) address, value); 202 | return true; 203 | } 204 | 205 | /** 206 | * Write a single 16 bits integer 207 | */ 208 | bool EEPROMClassEx::writeInt(int address, uint16_t value) 209 | { 210 | if (!isWriteOk(address+sizeof(uint16_t))) return false; 211 | eeprom_write_word((uint16_t *) address, value); 212 | return true; 213 | } 214 | 215 | /** 216 | * Write a single 32 bits integer 217 | */ 218 | bool EEPROMClassEx::writeLong(int address, uint32_t value) 219 | { 220 | if (!isWriteOk(address+sizeof(uint32_t))) return false; 221 | eeprom_write_dword((unsigned long *) address, value); 222 | return true; 223 | } 224 | 225 | /** 226 | * Write a single float value 227 | */ 228 | bool EEPROMClassEx::writeFloat(int address, float value) 229 | { 230 | return (writeBlock(address, value)!=0); 231 | } 232 | 233 | /** 234 | * Write a single double value (size will depend on board type) 235 | */ 236 | bool EEPROMClassEx::writeDouble(int address, double value) 237 | { 238 | return (writeBlock(address, value)!=0); 239 | } 240 | 241 | /** 242 | * Update a single byte 243 | * The EEPROM will only be overwritten if different. This will reduce wear. 244 | * This function performs as updateByte and is added to be similar to the EEPROM library 245 | */ 246 | bool EEPROMClassEx::update(int address, uint8_t value) 247 | { 248 | return (updateByte(address, value)); 249 | } 250 | 251 | /** 252 | * Update a single bit 253 | * The EEPROM will only be overwritten if different. This will reduce wear. 254 | */ 255 | bool EEPROMClassEx::updateBit(int address, uint8_t bit, bool value) 256 | { 257 | if (bit> 7) return false; 258 | 259 | byte byteValInput = readByte(address); 260 | byte byteValOutput = byteValInput; 261 | // Set bit 262 | if (value) { 263 | byteValOutput |= (1 << bit); //Set bit to 1 264 | } else { 265 | byteValOutput &= ~(1 << bit); //Set bit to 0 266 | } 267 | // Store if different from input 268 | if (byteValOutput!=byteValInput) { 269 | writeByte(address, byteValOutput); 270 | } 271 | return true; 272 | } 273 | 274 | 275 | /** 276 | * Update a single byte 277 | * The EEPROM will only be overwritten if different. This will reduce wear. 278 | */ 279 | bool EEPROMClassEx::updateByte(int address, uint8_t value) 280 | { 281 | return (updateBlock(address, value)!=0); 282 | } 283 | 284 | /** 285 | * Update a single 16 bits integer 286 | * The EEPROM will only be overwritten if different. This will reduce wear. 287 | */ 288 | bool EEPROMClassEx::updateInt(int address, uint16_t value) 289 | { 290 | return (updateBlock(address, value)!=0); 291 | } 292 | 293 | /** 294 | * Update a single 32 bits integer 295 | * The EEPROM will only be overwritten if different. This will reduce wear. 296 | */ 297 | bool EEPROMClassEx::updateLong(int address, uint32_t value) 298 | { 299 | return (updateBlock(address, value)!=0); 300 | } 301 | 302 | /** 303 | * Update a single float value 304 | * The EEPROM will only be overwritten if different. This will reduce wear. 305 | */ 306 | bool EEPROMClassEx::updateFloat(int address, float value) 307 | { 308 | return (updateBlock(address, value)!=0); 309 | } 310 | 311 | /** 312 | * Update a single double value (size will depend on board type) 313 | * The EEPROM will only be overwritten if different. This will reduce wear. 314 | */ 315 | bool EEPROMClassEx::updateDouble(int address, double value) 316 | { 317 | return (writeBlock(address, value)!=0); 318 | } 319 | 320 | /** 321 | * Performs check to see if writing to a memory address is allowed 322 | */ 323 | bool EEPROMClassEx::isWriteOk(int address) 324 | { 325 | #ifdef _EEPROMEX_DEBUG 326 | _writeCounts++; 327 | if (_allowedWrites == 0 || _writeCounts > _allowedWrites ) { 328 | Serial.println("Exceeded maximum number of writes"); 329 | return false; 330 | } 331 | 332 | if (address > _memSize) { 333 | Serial.println("Attempt to write outside of EEPROM memory"); 334 | return false; 335 | } else { 336 | return true; 337 | } 338 | #endif 339 | return true; 340 | } 341 | 342 | /** 343 | * Performs check to see if reading from a memory address is allowed 344 | */ 345 | bool EEPROMClassEx::isReadOk(int address) 346 | { 347 | #ifdef _EEPROMEX_DEBUG 348 | if (address > _memSize) { 349 | Serial.println("Attempt to write outside of EEPROM memory"); 350 | return false; 351 | } else { 352 | return true; 353 | } 354 | #endif 355 | return true; 356 | } 357 | 358 | int EEPROMClassEx::_base= 0; 359 | int EEPROMClassEx::_memSize= 512; 360 | int EEPROMClassEx::_nextAvailableaddress= 0; 361 | int EEPROMClassEx::_writeCounts =0; 362 | 363 | EEPROMClassEx EEPROM; 364 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | 3 | Version 2, June 1991 4 | 5 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 6 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 7 | 8 | Everyone is permitted to copy and distribute verbatim copies 9 | of this license document, but changing it is not allowed. 10 | Preamble 11 | The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. 12 | 13 | When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. 14 | 15 | To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. 16 | 17 | For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. 18 | 19 | We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. 20 | 21 | Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. 22 | 23 | Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. 24 | 25 | The precise terms and conditions for copying, distribution and modification follow. 26 | 27 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 28 | 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". 29 | 30 | Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 31 | 32 | 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. 33 | 34 | You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 35 | 36 | 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: 37 | 38 | a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. 39 | b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. 40 | c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) 41 | These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. 42 | 43 | Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. 44 | 45 | In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 46 | 47 | 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: 48 | 49 | a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, 50 | b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, 51 | c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) 52 | The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. 53 | 54 | If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 55 | 56 | 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 57 | 58 | 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 59 | 60 | 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 61 | 62 | 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. 63 | 64 | If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. 65 | 66 | It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. 67 | 68 | This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 69 | 70 | 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 71 | 72 | 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. 73 | 74 | Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 75 | 76 | 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. 77 | 78 | NO WARRANTY 79 | 80 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 81 | 82 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -------------------------------------------------------------------------------- /Protocol_Definitions.txt: -------------------------------------------------------------------------------- 1 | Protocol definitions (serial and UDP): 2 | 3 | Driver Command: PING:# 4 | Arduino Response: PONG:# 5 | Confirms a flatbox device supporting the protocol is on the other side 6 | 7 | 8 | Driver Command: SET::# 9 | Arduino Response: SET::# 10 | Tells flatbox the set brightness to level sepcificed by . Returns the current brightness returns the same value as a sanity check and confirm it is complete 11 | 12 | Driver Command: BRIGHT:# 13 | Arduino Response: BRIGHT::# 14 | Asks flatbox the current brightness level. Returns the current brightness 15 | 16 | 17 | Protocol definition (serial only) 18 | 19 | Driver Command: GETCONFIG:# 20 | Arduino Response: GETCONFIG::::::::# - sorry, will not return password of your wifi 21 | Asks flatbox to get the current config (tbd for configuration program) 22 | 23 | Driver Command SETCONFIG::::::::# 24 | Arduino response SETCONFIG::# returns 0 or 1 if configuration change was successful or not 25 | 26 | 27 | 28 | Note for values: 29 | Values in config (in order) 30 | enable wifi (0 or 1) 31 | static IP or DHCP (1 for static, 0 for DHCP) 32 | IP address (string format, e.g. 192.168.1.230) 33 | Subnet mask (string format, e.g. 255.255.255.0) 34 | DNS server (string format, e.g. 192.168.1.1) 35 | Default gateway (string format, e.g. 192.168.1.1) 36 | WiFi SSID = text string 37 | WiFi Password = text string 38 | 39 | TODO: decide if there is a wildcard in the GUI (e.g.8 "*" and determine to maintain the password stored in EEPROM since we will not send the password back via serial) 40 | 41 | example: 42 | SETCONFIG:1:1:192.168.1.230:255.255.255.0:192.168.1.1:192.168.1.1:my_ssid:my_password:# would set wifi on and static IP based on above parameters 43 | SETCONFIG:1:0:::::my_ssid:my_password:# would set wifi on and DHCP. Data would be clear. A driver side call can still set this if you want to use get config and preserve it between calls. 44 | SETCONFIG:0:0::::::::# would set it to serial only. 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ArduinoFlatbox 2 | 3 | The code contained within this repository is distributed under the terms of GPL version 2.0. Please refer to License.txt for more details 4 | 5 | This project is an intended to provide a codebase for an Arduino Controlled flatbox for astrophotography. 6 | 7 | While there are other examples that utilize the Alnitak command protocol, and I use the techniques to write the 8 | value to the LED pin, I am updating the protocol to make it readable. 9 | 10 | Additionally, the code is intended to allow the user to select WiFi or serial based communications, in the current alpha stage, they both work just fine 11 | A configurator program needs to still be created to allow an end user to plug in a USB-B cable to the arduino and configure wifi paramterers. Currently a user will 12 | need to send a command manually of the serial connection to configure the WiFi parameters. 13 | 14 | If using serially, I recommend disabling WiFi 15 | 16 | ASCOM driver has been tested with NINA (my primary imaging software) and SGP 17 | 18 | 19 | Good luck and feel free to report bugs or submit patches. 20 | 21 | 22 | Building the package: 23 | You need the ASCOM platform version 6.5.2 and development libraries to build the driver. I have included NUGET to allow automated download of the platform for proper compilation. 24 | 25 | The build process will attempt to register the DLL on the machine upon build. You will get a failure unless you are running Visual Studio as an administrator. 26 | 27 | You can build your own installation package by running InnoSetup found here: https://jrsoftware.org/isinfo.php 28 | 29 | Inside the ASCOM directory in an ISS file that you can right click and select "compile." This will place a setup executable in the same directory. You can then take this and install 30 | on any other computer. Note: the InnoSetup .iss file expects you to build a release version. The setup will not build a setup package for a debug version. 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /TODO.txt: -------------------------------------------------------------------------------- 1 | Create HEX file for upload of sketch 2 | Consider removing need for Arduino software for sketch upload and move more to a firmware model for non-DIY people 3 | 4 | Add handling for cover open / close on both Arduino and ASCOM driver 5 | 6 | Binary distribution --------------------------------------------------------------------------------