From eab090470ed6ed323adf7cd1cf2ae9e3c202fc1b Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 17 Jan 2021 02:44:54 +0000 Subject: [PATCH] first commit --- .gitignore | 213 +++++++++++ .../PillTracker.xcodeproj/project.pbxproj | 354 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + PillTracker/PillTracker/AppDelegate.swift | 36 ++ .../AccentColor.colorset/Contents.json | 11 + .../AppIcon.appiconset/Contents.json | 98 +++++ .../PillTracker/Assets.xcassets/Contents.json | 6 + .../Base.lproj/LaunchScreen.storyboard | 25 ++ .../PillTracker/Base.lproj/Main.storyboard | 150 ++++++++ PillTracker/PillTracker/Info.plist | 68 ++++ PillTracker/PillTracker/NSData+int8.swift | 19 + PillTracker/PillTracker/SceneDelegate.swift | 52 +++ .../PillTracker/SimpleBluetoothIO.swift | 125 +++++++ PillTracker/PillTracker/ViewController.swift | 122 ++++++ README.md | 1 + embedded/main/main.ino | 167 +++++++++ 17 files changed, 1462 insertions(+) create mode 100644 .gitignore create mode 100644 PillTracker/PillTracker.xcodeproj/project.pbxproj create mode 100644 PillTracker/PillTracker.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 PillTracker/PillTracker.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 PillTracker/PillTracker/AppDelegate.swift create mode 100644 PillTracker/PillTracker/Assets.xcassets/AccentColor.colorset/Contents.json create mode 100644 PillTracker/PillTracker/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 PillTracker/PillTracker/Assets.xcassets/Contents.json create mode 100644 PillTracker/PillTracker/Base.lproj/LaunchScreen.storyboard create mode 100644 PillTracker/PillTracker/Base.lproj/Main.storyboard create mode 100644 PillTracker/PillTracker/Info.plist create mode 100644 PillTracker/PillTracker/NSData+int8.swift create mode 100644 PillTracker/PillTracker/SceneDelegate.swift create mode 100644 PillTracker/PillTracker/SimpleBluetoothIO.swift create mode 100644 PillTracker/PillTracker/ViewController.swift create mode 100644 README.md create mode 100644 embedded/main/main.ino diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3910157 --- /dev/null +++ b/.gitignore @@ -0,0 +1,213 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/macos,windows,linux,swift,c +# Edit at https://www.toptal.com/developers/gitignore?templates=macos,windows,linux,swift,c + +### C ### +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Swift ### +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## User settings +xcuserdata/ + +## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) +*.xcscmblueprint +*.xccheckout + +## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) +build/ +DerivedData/ +*.moved-aside +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 + +## Obj-C/Swift specific +*.hmap + +## App packaging +*.ipa +*.dSYM.zip +*.dSYM + +## Playgrounds +timeline.xctimeline +playground.xcworkspace + +# Swift Package Manager +# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. +# Packages/ +# Package.pins +# Package.resolved +# *.xcodeproj +# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata +# hence it is not needed unless you have added a package configuration file to your project +# .swiftpm + +.build/ + +# CocoaPods +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# Pods/ +# Add this line if you want to avoid checking in source code from the Xcode workspace +# *.xcworkspace + +# Carthage +# Add this line if you want to avoid checking in source code from Carthage dependencies. +# Carthage/Checkouts + +Carthage/Build/ + +# Accio dependency management +Dependencies/ +.accio/ + +# fastlane +# It is recommended to not store the screenshots in the git repo. +# Instead, use fastlane to re-generate the screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://docs.fastlane.tools/best-practices/source-control/#source-control + +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots/**/*.png +fastlane/test_output + +# Code Injection +# After new code Injection tools there's a generated folder /iOSInjectionProject +# https://github.com/johnno1962/injectionforxcode + +iOSInjectionProject/ + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.toptal.com/developers/gitignore/api/macos,windows,linux,swift,c diff --git a/PillTracker/PillTracker.xcodeproj/project.pbxproj b/PillTracker/PillTracker.xcodeproj/project.pbxproj new file mode 100644 index 0000000..06facf3 --- /dev/null +++ b/PillTracker/PillTracker.xcodeproj/project.pbxproj @@ -0,0 +1,354 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + 504389FD25B3B4EF008C4BC0 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504389FC25B3B4EF008C4BC0 /* AppDelegate.swift */; }; + 504389FF25B3B4EF008C4BC0 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504389FE25B3B4EF008C4BC0 /* SceneDelegate.swift */; }; + 50438A0125B3B4EF008C4BC0 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50438A0025B3B4EF008C4BC0 /* ViewController.swift */; }; + 50438A0425B3B4EF008C4BC0 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 50438A0225B3B4EF008C4BC0 /* Main.storyboard */; }; + 50438A0625B3B4F0008C4BC0 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 50438A0525B3B4F0008C4BC0 /* Assets.xcassets */; }; + 50438A0925B3B4F0008C4BC0 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 50438A0725B3B4F0008C4BC0 /* LaunchScreen.storyboard */; }; + 50438A1225B3B50E008C4BC0 /* SimpleBluetoothIO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50438A1125B3B50E008C4BC0 /* SimpleBluetoothIO.swift */; }; + 50438A1525B3B52A008C4BC0 /* NSData+int8.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50438A1425B3B52A008C4BC0 /* NSData+int8.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 504389F925B3B4EF008C4BC0 /* PillTracker.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PillTracker.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 504389FC25B3B4EF008C4BC0 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 504389FE25B3B4EF008C4BC0 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; + 50438A0025B3B4EF008C4BC0 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + 50438A0325B3B4EF008C4BC0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 50438A0525B3B4F0008C4BC0 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 50438A0825B3B4F0008C4BC0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 50438A0A25B3B4F0008C4BC0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 50438A1125B3B50E008C4BC0 /* SimpleBluetoothIO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleBluetoothIO.swift; sourceTree = ""; }; + 50438A1425B3B52A008C4BC0 /* NSData+int8.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSData+int8.swift"; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 504389F625B3B4EF008C4BC0 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 504389F025B3B4EF008C4BC0 = { + isa = PBXGroup; + children = ( + 504389FB25B3B4EF008C4BC0 /* PillTracker */, + 504389FA25B3B4EF008C4BC0 /* Products */, + ); + sourceTree = ""; + }; + 504389FA25B3B4EF008C4BC0 /* Products */ = { + isa = PBXGroup; + children = ( + 504389F925B3B4EF008C4BC0 /* PillTracker.app */, + ); + name = Products; + sourceTree = ""; + }; + 504389FB25B3B4EF008C4BC0 /* PillTracker */ = { + isa = PBXGroup; + children = ( + 504389FC25B3B4EF008C4BC0 /* AppDelegate.swift */, + 504389FE25B3B4EF008C4BC0 /* SceneDelegate.swift */, + 50438A0025B3B4EF008C4BC0 /* ViewController.swift */, + 50438A0225B3B4EF008C4BC0 /* Main.storyboard */, + 50438A0525B3B4F0008C4BC0 /* Assets.xcassets */, + 50438A0725B3B4F0008C4BC0 /* LaunchScreen.storyboard */, + 50438A0A25B3B4F0008C4BC0 /* Info.plist */, + 50438A1125B3B50E008C4BC0 /* SimpleBluetoothIO.swift */, + 50438A1425B3B52A008C4BC0 /* NSData+int8.swift */, + ); + path = PillTracker; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 504389F825B3B4EF008C4BC0 /* PillTracker */ = { + isa = PBXNativeTarget; + buildConfigurationList = 50438A0D25B3B4F0008C4BC0 /* Build configuration list for PBXNativeTarget "PillTracker" */; + buildPhases = ( + 504389F525B3B4EF008C4BC0 /* Sources */, + 504389F625B3B4EF008C4BC0 /* Frameworks */, + 504389F725B3B4EF008C4BC0 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = PillTracker; + productName = PillTracker; + productReference = 504389F925B3B4EF008C4BC0 /* PillTracker.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 504389F125B3B4EF008C4BC0 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1230; + LastUpgradeCheck = 1230; + TargetAttributes = { + 504389F825B3B4EF008C4BC0 = { + CreatedOnToolsVersion = 12.3; + }; + }; + }; + buildConfigurationList = 504389F425B3B4EF008C4BC0 /* Build configuration list for PBXProject "PillTracker" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 504389F025B3B4EF008C4BC0; + productRefGroup = 504389FA25B3B4EF008C4BC0 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 504389F825B3B4EF008C4BC0 /* PillTracker */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 504389F725B3B4EF008C4BC0 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 50438A0925B3B4F0008C4BC0 /* LaunchScreen.storyboard in Resources */, + 50438A0625B3B4F0008C4BC0 /* Assets.xcassets in Resources */, + 50438A0425B3B4EF008C4BC0 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 504389F525B3B4EF008C4BC0 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 50438A0125B3B4EF008C4BC0 /* ViewController.swift in Sources */, + 504389FD25B3B4EF008C4BC0 /* AppDelegate.swift in Sources */, + 50438A1225B3B50E008C4BC0 /* SimpleBluetoothIO.swift in Sources */, + 504389FF25B3B4EF008C4BC0 /* SceneDelegate.swift in Sources */, + 50438A1525B3B52A008C4BC0 /* NSData+int8.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 50438A0225B3B4EF008C4BC0 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 50438A0325B3B4EF008C4BC0 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 50438A0725B3B4F0008C4BC0 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 50438A0825B3B4F0008C4BC0 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 50438A0B25B3B4F0008C4BC0 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 14.3; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 50438A0C25B3B4F0008C4BC0 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 14.3; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 50438A0E25B3B4F0008C4BC0 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 36JR976L6Y; + INFOPLIST_FILE = PillTracker/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = mh.smt.PillTracker; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 50438A0F25B3B4F0008C4BC0 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 36JR976L6Y; + INFOPLIST_FILE = PillTracker/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = mh.smt.PillTracker; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 504389F425B3B4EF008C4BC0 /* Build configuration list for PBXProject "PillTracker" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 50438A0B25B3B4F0008C4BC0 /* Debug */, + 50438A0C25B3B4F0008C4BC0 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 50438A0D25B3B4F0008C4BC0 /* Build configuration list for PBXNativeTarget "PillTracker" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 50438A0E25B3B4F0008C4BC0 /* Debug */, + 50438A0F25B3B4F0008C4BC0 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 504389F125B3B4EF008C4BC0 /* Project object */; +} diff --git a/PillTracker/PillTracker.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/PillTracker/PillTracker.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/PillTracker/PillTracker.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/PillTracker/PillTracker.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/PillTracker/PillTracker.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/PillTracker/PillTracker.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/PillTracker/PillTracker/AppDelegate.swift b/PillTracker/PillTracker/AppDelegate.swift new file mode 100644 index 0000000..fe1f794 --- /dev/null +++ b/PillTracker/PillTracker/AppDelegate.swift @@ -0,0 +1,36 @@ +// +// AppDelegate.swift +// PillTracker +// +// Created by Max Hunt on 16/01/2021. +// + +import UIKit + +@main +class AppDelegate: UIResponder, UIApplicationDelegate { + + + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + // Override point for customization after application launch. + return true + } + + // MARK: UISceneSession Lifecycle + + func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { + // Called when a new scene session is being created. + // Use this method to select a configuration to create the new scene with. + return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) + } + + func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { + // Called when the user discards a scene session. + // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. + // Use this method to release any resources that were specific to the discarded scenes, as they will not return. + } + + +} + diff --git a/PillTracker/PillTracker/Assets.xcassets/AccentColor.colorset/Contents.json b/PillTracker/PillTracker/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 0000000..eb87897 --- /dev/null +++ b/PillTracker/PillTracker/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/PillTracker/PillTracker/Assets.xcassets/AppIcon.appiconset/Contents.json b/PillTracker/PillTracker/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..9221b9b --- /dev/null +++ b/PillTracker/PillTracker/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,98 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "20x20" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "20x20" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "29x29" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "29x29" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "40x40" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "40x40" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "60x60" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "60x60" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "20x20" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "20x20" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "29x29" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "29x29" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "40x40" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "40x40" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "76x76" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "76x76" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "83.5x83.5" + }, + { + "idiom" : "ios-marketing", + "scale" : "1x", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/PillTracker/PillTracker/Assets.xcassets/Contents.json b/PillTracker/PillTracker/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/PillTracker/PillTracker/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/PillTracker/PillTracker/Base.lproj/LaunchScreen.storyboard b/PillTracker/PillTracker/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..865e932 --- /dev/null +++ b/PillTracker/PillTracker/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PillTracker/PillTracker/Base.lproj/Main.storyboard b/PillTracker/PillTracker/Base.lproj/Main.storyboard new file mode 100644 index 0000000..d0fce9d --- /dev/null +++ b/PillTracker/PillTracker/Base.lproj/Main.storyboard @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PillTracker/PillTracker/Info.plist b/PillTracker/PillTracker/Info.plist new file mode 100644 index 0000000..38de236 --- /dev/null +++ b/PillTracker/PillTracker/Info.plist @@ -0,0 +1,68 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + $(PRODUCT_MODULE_NAME).SceneDelegate + UISceneStoryboardFile + Main + + + + + UIApplicationSupportsIndirectInputEvents + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + NSBluetoothAlwaysUsageDescription + For Pill Detection + + diff --git a/PillTracker/PillTracker/NSData+int8.swift b/PillTracker/PillTracker/NSData+int8.swift new file mode 100644 index 0000000..6613f77 --- /dev/null +++ b/PillTracker/PillTracker/NSData+int8.swift @@ -0,0 +1,19 @@ +// +// NSData+int8.swift +// PillTracker +// +// Created by Max Hunt on 16/01/2021. +// + +import Foundation + +extension Data { + static func dataWithValue(value: Int8) -> Data { + var variableValue = value + return Data(buffer: UnsafeBufferPointer(start: &variableValue, count: 1)) + } + + func int8Value() -> Int8 { + return Int8(bitPattern: self[0]) + } +} diff --git a/PillTracker/PillTracker/SceneDelegate.swift b/PillTracker/PillTracker/SceneDelegate.swift new file mode 100644 index 0000000..ef07275 --- /dev/null +++ b/PillTracker/PillTracker/SceneDelegate.swift @@ -0,0 +1,52 @@ +// +// SceneDelegate.swift +// PillTracker +// +// Created by Max Hunt on 16/01/2021. +// + +import UIKit + +class SceneDelegate: UIResponder, UIWindowSceneDelegate { + + var window: UIWindow? + + + func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { + // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. + // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. + // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). + guard let _ = (scene as? UIWindowScene) else { return } + } + + func sceneDidDisconnect(_ scene: UIScene) { + // Called as the scene is being released by the system. + // This occurs shortly after the scene enters the background, or when its session is discarded. + // Release any resources associated with this scene that can be re-created the next time the scene connects. + // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead). + } + + func sceneDidBecomeActive(_ scene: UIScene) { + // Called when the scene has moved from an inactive state to an active state. + // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. + } + + func sceneWillResignActive(_ scene: UIScene) { + // Called when the scene will move from an active state to an inactive state. + // This may occur due to temporary interruptions (ex. an incoming phone call). + } + + func sceneWillEnterForeground(_ scene: UIScene) { + // Called as the scene transitions from the background to the foreground. + // Use this method to undo the changes made on entering the background. + } + + func sceneDidEnterBackground(_ scene: UIScene) { + // Called as the scene transitions from the foreground to the background. + // Use this method to save data, release shared resources, and store enough scene-specific state information + // to restore the scene back to its current state. + } + + +} + diff --git a/PillTracker/PillTracker/SimpleBluetoothIO.swift b/PillTracker/PillTracker/SimpleBluetoothIO.swift new file mode 100644 index 0000000..e16f1d7 --- /dev/null +++ b/PillTracker/PillTracker/SimpleBluetoothIO.swift @@ -0,0 +1,125 @@ +// +// SimpleBluetoothIO.swift +// PillTracker +// +// Created by Max Hunt on 16/01/2021. +// + +import CoreBluetooth + +protocol SimpleBluetoothIODelegate: class { + func simpleBluetoothIO(simpleBluetoothIO: SimpleBluetoothIO, didReceiveValue value: Int8) + func simpleBluetoothIO(simpleBluetoothIO: SimpleBluetoothIO, didConnect value: Bool) + func simpleBluetoothIO(simpleBluetoothIO: SimpleBluetoothIO, didDisconnect value: Bool) +} + +class SimpleBluetoothIO: NSObject { + let serviceUUID: String + weak var delegate: SimpleBluetoothIODelegate? + + var centralManager: CBCentralManager! + var connectedPeripheral: CBPeripheral? + var targetService: CBService? + var writableCharacteristic: CBCharacteristic? + var connected = false + + init(serviceUUID: String, delegate: SimpleBluetoothIODelegate?) { + self.serviceUUID = serviceUUID + self.delegate = delegate + + super.init() + + centralManager = CBCentralManager(delegate: self, queue: nil) + + } + + func writeValue(value: Int8) { + guard let peripheral = connectedPeripheral, let characteristic = writableCharacteristic else { + return + } + + let data = Data.dataWithValue(value: value) + peripheral.writeValue(data, for: characteristic, type: .withResponse) + } + +} + +extension SimpleBluetoothIO: CBCentralManagerDelegate { + func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) { + peripheral.discoverServices(nil) + self.connected = true + print("Connected! With \(peripheral.name)") + delegate?.simpleBluetoothIO(simpleBluetoothIO: self, didConnect: true) + } + + func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) { + connectedPeripheral = peripheral + if (peripheral.name != "[TV] Samsung Q7 Series (55)" && peripheral.name != "MacDeMax"){ + print("Discovered \(peripheral.name)") + } + if (peripheral.name != nil) { + if(((peripheral.name?.contains("PILL_TRACKER"))!)) + { + if let connectedPeripheral = connectedPeripheral { + connectedPeripheral.delegate = self + centralManager.connect(connectedPeripheral, options: nil) + } + centralManager.stopScan() + } + + } + + } + + func centralManagerDidUpdateState(_ central: CBCentralManager) { + if central.state == .poweredOn { + // centralManager.scanForPeripherals(withServices: [CBUUID(string: serviceUUID)], options: nil) + centralManager.scanForPeripherals(withServices: nil, options: nil) + } + } +} + +extension SimpleBluetoothIO: CBPeripheralDelegate { + func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) { + guard let services = peripheral.services else { + return + } + + targetService = services.first + if let service = services.first { + targetService = service + peripheral.discoverCharacteristics(nil, for: service) + } + } + + func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) { + guard let characteristics = service.characteristics else { + return + } + + for characteristic in characteristics { + if characteristic.properties.contains(.write) || characteristic.properties.contains(.writeWithoutResponse) { + writableCharacteristic = characteristic + } + peripheral.setNotifyValue(true, for: characteristic) + } + } + + func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) { + guard let data = characteristic.value, let delegate = delegate else { + return + } + + delegate.simpleBluetoothIO(simpleBluetoothIO: self, didReceiveValue: data.int8Value()) + } + + func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) { + print("Disconnected: \(peripheral.name)") + print("Restarting scan...") + centralManager.scanForPeripherals(withServices: nil, options: nil) + delegate?.simpleBluetoothIO(simpleBluetoothIO: self, didDisconnect: true) + } + + + +} diff --git a/PillTracker/PillTracker/ViewController.swift b/PillTracker/PillTracker/ViewController.swift new file mode 100644 index 0000000..5cf07bf --- /dev/null +++ b/PillTracker/PillTracker/ViewController.swift @@ -0,0 +1,122 @@ +// +// ViewController.swift +// PillTracker +// +// Created by Max Hunt on 16/01/2021. +// + +import UIKit + +class ViewController: UIViewController { + var simpleBluetoothIO: SimpleBluetoothIO! + + @IBOutlet var virtualButton:UISwitch! + @IBOutlet weak var ledToggleButton: UIButton! + @IBOutlet weak var statusLabel: UILabel! + @IBOutlet weak var cStatus: UILabel! + @IBOutlet weak var pillsConsumed: UILabel! + @IBOutlet weak var pillsRemaining: UILabel! + @IBOutlet weak var pillsTotal: UILabel! + @IBOutlet weak var pillsAttached: UILabel! + @IBOutlet weak var refreshToggle: UISwitch! + + let totalPills: Int = 6 + let updateFreq: Float = 2.0 + weak var timer: Timer? + + override func viewDidLoad() { + super.viewDidLoad() + overrideUserInterfaceStyle = .light + simpleBluetoothIO = SimpleBluetoothIO(serviceUUID: "4fafc201-1fb5-459e-8fcc-c5c9c331914b", delegate: self) +// startTimer() + + } + + deinit { + stopTimer() + } + + func sendUpdateCommand(){ + print("Sending update command...") + simpleBluetoothIO.writeValue(value: 51) + } + + func startTimer() { + timer?.invalidate() // just in case you had existing `Timer`, `invalidate` it before we lose our reference to it + timer = Timer.scheduledTimer(withTimeInterval: TimeInterval(updateFreq), repeats: true) { [weak self] _ in + self?.sendUpdateCommand() + } + } + + func stopTimer() { + timer?.invalidate() + } + + @IBAction func ledToggleButtonDown(_ sender: UIButton) { + simpleBluetoothIO.writeValue(value:49) + } + + @IBAction func ledToggleButtonUp(_ sender: UIButton) { + simpleBluetoothIO.writeValue(value: 50) + } + + @IBAction func forcePillRefresh(_ sender: UIButton) { + self.sendUpdateCommand() + } + @IBAction func RefreshChanged(_ sender: Any) { + if self.refreshToggle.isOn { + startTimer() + } else { + stopTimer() + } + } + +} + +extension ViewController: SimpleBluetoothIODelegate { + func simpleBluetoothIO(simpleBluetoothIO: SimpleBluetoothIO, didReceiveValue value: Int8) { + self.statusLabel.text = String(value) + print(value) + if value == 98 { + //view.backgroundColor = UIColor.yellow + virtualButton.setOn(true, animated: true) + } else if value == 99 { + //view.backgroundColor = UIColor.black + virtualButton.setOn(false, animated: true) + } else if value == 55 { + self.pillsConsumed.text = "X" + self.pillsRemaining.text = "X" + self.pillsTotal.text = "X" + self.pillsAttached.text = "Detached" + self.pillsAttached.textColor = UIColor.red + } else { + let remainingPills = Int(value) + let usedPills = self.totalPills - remainingPills + self.pillsConsumed.text = String(usedPills) + self.pillsRemaining.text = String(remainingPills) + self.pillsTotal.text = String(self.totalPills) + self.pillsAttached.text = "Attached" + self.pillsAttached.textColor = UIColor.green + } + } + + func simpleBluetoothIO(simpleBluetoothIO: SimpleBluetoothIO, didConnect value: Bool) { + print("VC: connect: \(value)") + self.cStatus.text = "Connected!" + self.cStatus.textColor = UIColor.green + DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { + print("Sending update commend") + self.sendUpdateCommand() + } + } + + func simpleBluetoothIO(simpleBluetoothIO: SimpleBluetoothIO, didDisconnect value: Bool) { + print("VC: disconnect: \(value)") + self.cStatus.text = "Disconnected..." + self.cStatus.textColor = UIColor.red + self.pillsAttached.text = "Detached" + self.pillsAttached.textColor = UIColor.red + } + + +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..a3b67b8 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# PILL TRACKER diff --git a/embedded/main/main.ino b/embedded/main/main.ino new file mode 100644 index 0000000..b9de4b9 --- /dev/null +++ b/embedded/main/main.ino @@ -0,0 +1,167 @@ +#include +#include +#include + +// See the following for generating UUIDs: +// https://www.uuidgenerator.net/ + +#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" +#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" + +#define LED_PIN 2 +#define BTN_PIN 5 + +#define PILL_1_PIN 25 +#define PILL_2_PIN 13 +#define PILL_3_PIN 12 +#define PILL_4_PIN 26 +#define PILL_5_PIN 27 +#define PILL_6_PIN 14 +#define DETECT_PIN 18 + + +int deviceConnected = false; + +int waitingForUpdate = 0; + + +class MyCallbacks: public BLECharacteristicCallbacks { + void onConnect(BLEServer* pServer) { + deviceConnected = true; + Serial.println("device connected"); + }; + + void onDisconnect(BLEServer* pServer) { + deviceConnected = false; + Serial.println("device disconnected"); + } + void onWrite(BLECharacteristic *pCharacteristic) { + std::string value = pCharacteristic->getValue(); + + if (value.length() > 0) { + Serial.print("*********"); + Serial.print(value.c_str()); + Serial.print("-"); + Serial.print(atoi(value.c_str())); + Serial.print("-"); + if(atoi(value.c_str())==1) + { + digitalWrite(LED_PIN,HIGH); + Serial.print("LEDON"); + } + else if (atoi(value.c_str())==2) + { + digitalWrite(LED_PIN,LOW); + Serial.print("LEDOFF"); + } + else if (atoi(value.c_str())==3) + { + Serial.print("UPDATE_PILL_TRACK"); + waitingForUpdate = 1; + } + else { + Serial.println(); + Serial.println(atoi(value.c_str())); + Serial.println(); + } + + Serial.println("*********"); + } + } +}; + +BLECharacteristic *pCharacteristic; +void setup() { + Serial.begin(115200); + pinMode(LED_PIN,OUTPUT); + + pinMode(PILL_1_PIN,INPUT_PULLUP); + pinMode(PILL_2_PIN,INPUT_PULLUP); + pinMode(PILL_3_PIN,INPUT_PULLUP); + pinMode(PILL_4_PIN,INPUT_PULLUP); + pinMode(PILL_5_PIN,INPUT_PULLUP); + pinMode(PILL_6_PIN,INPUT_PULLUP); + + pinMode(BTN_PIN,INPUT_PULLUP); + pinMode(DETECT_PIN,INPUT_PULLUP); + + + digitalWrite(LED_PIN,LOW); + Serial.println("1- Download and install an BLE scanner app in your phone"); + Serial.println("2- Scan for BLE devices in the app"); + Serial.println("3- Connect to MyESP32"); + Serial.println("4- Go to CUSTOM CHARACTERISTIC in CUSTOM SERVICE and write something"); + Serial.println("5- See the magic =)"); + + BLEDevice::init("PILL_TRACKER"); + BLEServer *pServer = BLEDevice::createServer(); + + BLEService *pService = pServer->createService(SERVICE_UUID); + + pCharacteristic= pService->createCharacteristic( + CHARACTERISTIC_UUID, + BLECharacteristic::PROPERTY_READ | + BLECharacteristic::PROPERTY_WRITE | + BLECharacteristic::PROPERTY_NOTIFY + ); + + pCharacteristic->setCallbacks(new MyCallbacks()); + + pCharacteristic->setValue("Hello World"); + pService->start(); + + BLEAdvertising *pAdvertising = pServer->getAdvertising(); + pAdvertising->start(); +} +int prevVal = LOW; +int prevVal2 = LOW; + +int getPillCount() { + int totalIntact = 0; + if(digitalRead(DETECT_PIN) == LOW) { + Serial.println("PROBE_ATTACHED"); + if(digitalRead(PILL_1_PIN) == LOW){totalIntact++;Serial.println("25:FULL");} + if(digitalRead(PILL_2_PIN) == LOW){totalIntact++;Serial.println("13:FULL");} + if(digitalRead(PILL_3_PIN) == LOW){totalIntact++;Serial.println("12:FULL");} + if(digitalRead(PILL_4_PIN) == LOW){totalIntact++;Serial.println("26:FULL");} + if(digitalRead(PILL_5_PIN) == LOW){totalIntact++;Serial.println("27:FULL");} + if(digitalRead(PILL_6_PIN) == LOW){totalIntact++;Serial.println("14:FULL");} + } + else { + Serial.println("PROBE_DETACHED"); + totalIntact = 55; + } + return totalIntact; +} + +void loop() { + // put your main code here, to run repeatedly: + + int currentVal = digitalRead(BTN_PIN); + if(currentVal!=prevVal) + { + prevVal=currentVal; + if(currentVal==HIGH) + { + int value = 99; + pCharacteristic->setValue((uint8_t*)&value, 4); + pCharacteristic->notify(); + } + else + { + int value = 98; + pCharacteristic->setValue((uint8_t*)&value, 4); + pCharacteristic->notify(); + } + } + + if(waitingForUpdate == 1){ + Serial.println("**********************************"); + Serial.println("**************UPDATE AND SEND PILL COUNT********************"); + Serial.println("**********************************"); + waitingForUpdate = 0; + int value = getPillCount(); + pCharacteristic->setValue((uint8_t*)&value, 4); + pCharacteristic->notify(); + } +}