Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJKM committed Sep 9, 2019
1 parent d5481e6 commit 50c345a
Show file tree
Hide file tree
Showing 141 changed files with 8,840 additions and 0 deletions.
Binary file added Icons/icon-1024.heic
Binary file not shown.
Binary file added Icons/icon-20@2x.heic
Binary file not shown.
Binary file added Icons/icon-20@3x.heic
Binary file not shown.
Binary file added Icons/icon-29@2x.heic
Binary file not shown.
Binary file added Icons/icon-29@3x.heic
Binary file not shown.
Binary file added Icons/icon-40@2x.heic
Binary file not shown.
Binary file added Icons/icon-60@2x.heic
Binary file not shown.
Binary file added Icons/icon-60@3x.heic
Binary file not shown.
Binary file added JKM Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Logo.heic
Binary file not shown.
Binary file added Logo.xcf
Binary file not shown.
Binary file added Logo_rund.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
547 changes: 547 additions & 0 deletions MensaGuthaben.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
10 changes: 10 additions & 0 deletions MensaGuthaben.xcworkspace/contents.xcworkspacedata

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
49 changes: 49 additions & 0 deletions MensaGuthaben/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// AppDelegate.swift
// MensaGuthaben
//
// Created by Johannes Kreutz on 22.08.19.
// Copyright © 2019 Johannes Kreutz. All rights reserved.
//
// This file is part of MensaGuthaben.
//
// MensaGuthaben is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// MensaGuthaben is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with MensaGuthaben. If not, see <http://www.gnu.org/licenses/>.
//

import UIKit

@UIApplicationMain
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<UISceneSession>) {
// 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.
}

}

62 changes: 62 additions & 0 deletions MensaGuthaben/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"images" : [
{
"size" : "20x20",
"idiom" : "iphone",
"filename" : "icon-20@2x.heic",
"scale" : "2x"
},
{
"size" : "20x20",
"idiom" : "iphone",
"filename" : "icon-20@3x.heic",
"scale" : "3x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "icon-29@2x.heic",
"scale" : "2x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "icon-29@3x.heic",
"scale" : "3x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "icon-40@2x.heic",
"scale" : "2x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "icon-60@2x-1.heic",
"scale" : "3x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "icon-60@2x.heic",
"scale" : "2x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "icon-60@3x.heic",
"scale" : "3x"
},
{
"size" : "1024x1024",
"idiom" : "ios-marketing",
"filename" : "icon-1024.heic",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions MensaGuthaben/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
60 changes: 60 additions & 0 deletions MensaGuthaben/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14865.1" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14819.2"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Logo_rund.png" translatesAutoresizingMaskIntoConstraints="NO" id="CgN-8X-BVM">
<rect key="frame" x="16" y="162" width="343" height="343"/>
<constraints>
<constraint firstAttribute="width" constant="343" id="76f-fV-aoZ"/>
<constraint firstAttribute="height" constant="343" id="m3Y-PS-CTU"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="MensaGuthaben" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="JGq-ja-n4W">
<rect key="frame" x="50" y="221" width="314" height="47"/>
<fontDescription key="fontDescription" type="system" pointSize="44"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="JKM Logo.png" translatesAutoresizingMaskIntoConstraints="NO" id="Vo0-4T-7OT">
<rect key="frame" x="52.5" y="618" width="270" height="44"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="0CN-mA-QEz"/>
<constraint firstAttribute="width" constant="270" id="U8K-at-IL7"/>
</constraints>
</imageView>
</subviews>
<color key="backgroundColor" cocoaTouchSystemColor="viewFlipsideBackgroundColor"/>
<constraints>
<constraint firstItem="CgN-8X-BVM" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" id="8Vz-fC-7Iy"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="bottom" secondItem="Vo0-4T-7OT" secondAttribute="bottom" constant="5" id="8iF-A9-uTt"/>
<constraint firstItem="Vo0-4T-7OT" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="HtE-to-OYo"/>
<constraint firstItem="JGq-ja-n4W" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="WMm-oD-TdZ"/>
<constraint firstItem="CgN-8X-BVM" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="cUv-XP-uAa"/>
<constraint firstItem="CgN-8X-BVM" firstAttribute="top" secondItem="JGq-ja-n4W" secondAttribute="bottom" constant="15" id="pLx-qL-h6Y"/>
</constraints>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="52" y="374.66266866566718"/>
</scene>
</scenes>
<resources>
<image name="JKM Logo.png" width="398" height="80"/>
<image name="Logo_rund.png" width="241" height="241"/>
</resources>
</document>
175 changes: 175 additions & 0 deletions MensaGuthaben/CardScanner.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
//
// CardScanner.swift
// MensaGuthaben
//
// Created by Johannes Kreutz on 25.08.19.
// Copyright © 2019 Johannes Kreutz. All rights reserved.
//
// This file is part of MensaGuthaben.
//
// MensaGuthaben is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// MensaGuthaben is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with MensaGuthaben. If not, see <http://www.gnu.org/licenses/>.
//

import Foundation
import PromiseKit
import JKDesFireReader

class CardScanner: JKDesFireReaderDelegate {

// MARK: Properties

let delegate: CardScannerDelegate
var reader: JKDesFireReader? = nil

// MARK: Initialization

init(delegate: CardScannerDelegate) {
self.delegate = delegate
}

// MARK: Control reader session

func scan() {
// Only start a new scanning session if there is no session open
guard reader == nil else {
return
}
reader = JKDesFireReader(start: false, delegate: self)
reader?.setSessionInfoText(text: "Bitte halte deine Mensakarte an die Oberkante deines iPhone.")
reader?.setErrorInfoText(text: "Leider konnte deine Karte nicht gelesen werden.")

// Start session
if !(reader?.createReaderSession())! {
print("Error creating reader session in JKDesFireReader.")
}
}

func sessionRunning() -> Bool {
return reader == nil ? false : true
}

// MARK: Delegate functions

func didDetectDesFireTag() {
firstly {
(reader?.listApplications())!
}.done { response in
var cardKnown: Bool = false
var appId: UInt32 = 0
var fileId: UInt8 = 0

// Check if we know an application id
for id in response {
if self.isCardValid(card: id) {
cardKnown = true
appId = id
fileId = self.getFileId(card: id)!
}
}

// Show error message if card is unknown
guard cardKnown else {
self.reader?.stopRunningSession(errorMessage: "Leider konnte deine Karte nicht gelesen werden: Unbekannte Karte (ERR_APPLICATION_NOT_FOUND).")
self.delegate.sessionCancel()
return
}

// Select application
firstly {
(self.reader?.selectApplication(applicationId: appId))!
}.done { application in
var fileFound: Bool = false

// Check if the wanted file is available
for file in application.getFiles() {
if (file == fileId) {
fileFound = true
}
}

// Show error message if card is unknown
guard fileFound else {
self.reader?.stopRunningSession(errorMessage: "Leider konnte deine Karte nicht gelesen werden: Unbekannte Karte (ERR_FILE_NOT_FOUND).")
self.delegate.sessionCancel()
return
}

// Get file settings
application.getFileSettings(fileId: fileId)
.done { settings in
var lastTransaction: Int = 0

if let valueSettings = settings as? JKDesFireValueFileSettings {
lastTransaction = valueSettings.getValue()
} else {
self.reader?.stopRunningSession(errorMessage: "Leider konnte deine Karte nicht gelesen werden: Fehler beim Lesen (ERR_NO_VALUE_FILE).")
self.delegate.sessionCancel()
}

// Read value
application.getValue(fileId: fileId)
.done { value in
self.delegate.newDataAvailable(current: value.getValue(), previous: lastTransaction)
self.reader?.stopRunningSession()
}.catch { error in
self.reader?.stopRunningSession(errorMessage: "Leider konnte deine Karte nicht gelesen werden: Fehler beim Lesen (ERR_READ_VALUE).")
self.delegate.sessionCancel()
}
}.catch { error in
self.reader?.stopRunningSession(errorMessage: "Leider konnte deine Karte nicht gelesen werden: Fehler beim Lesen (ERR_READ_FILE_SETTINGS).")
self.delegate.sessionCancel()
}

}.catch { error in
self.reader?.stopRunningSession(errorMessage: "Leider konnte deine Karte nicht gelesen werden: Fehler beim Lesen (ERR_SELECT_APPLICATION).")
self.delegate.sessionCancel()
}

}.catch { error in
print("Error getting application list: " + error.localizedDescription)
self.reader?.stopRunningSession(errorMessage: "Leider konnte deine Karte nicht gelesen werden. (Fehlercode " + error.localizedDescription + ")")
self.delegate.sessionCancel()
}
}

func tagDetectionError(error: JKDesFirePublicError) {
print("Error detecting tag: " + error.localizedDescription)
self.reader?.stopRunningSession(errorMessage: "Leider konnte deine Karte nicht gelesen werden. (Fehlercode " + error.localizedDescription + ")")
self.delegate.sessionCancel()
}

// MARK: Private helpers

private func isCardValid(card: UInt32) -> Bool {
return getCard(id: card) != nil ? true : false
}

private func getFileId(card: UInt32) -> UInt8? {
let c: Card? = getCard(id: card)
if (c != nil) {
return c!.fileId
}
return nil
}

private func getCard(id: UInt32) -> Card? {
for (_, card) in Cards.c {
if (card.applicationId == id) {
return card
}
}
return nil
}

}
Loading

0 comments on commit 50c345a

Please sign in to comment.