diff options
author | Johannes Rudolph <johannes.rudolph@gmx.com> | 2018-01-13 14:28:02 +0100 |
---|---|---|
committer | Sebastian Reichel <sre@ring0.de> | 2018-06-28 01:52:53 +0200 |
commit | c2bc2327238fc6833be861379e214661bfb391ae (patch) | |
tree | b3bf838a9d93e726d9cbe3d2b702b8172138c29e /src | |
parent | fe7729489370800a1a24ad4a0b6adf7d95979daf (diff) | |
download | serial-barcode-scanner-c2bc2327238fc6833be861379e214661bfb391ae.tar.bz2 |
scanner-session: add getCodeType()
Diffstat (limited to 'src')
-rw-r--r-- | src/scanner-session/scannersession-interface.vala | 9 | ||||
-rw-r--r-- | src/scanner-session/scannersession.vala | 22 |
2 files changed, 31 insertions, 0 deletions
diff --git a/src/scanner-session/scannersession-interface.vala b/src/scanner-session/scannersession-interface.vala index 89498df..9f989e7 100644 --- a/src/scanner-session/scannersession-interface.vala +++ b/src/scanner-session/scannersession-interface.vala @@ -24,3 +24,12 @@ public enum MessageType { WARNING, ERROR } + +public enum ScannerSessionCodeType { + USER, + GUEST, + UNDO, + LOGOUT, + EAN, + UNKNOWN +} diff --git a/src/scanner-session/scannersession.vala b/src/scanner-session/scannersession.vala index eeb02e3..23db939 100644 --- a/src/scanner-session/scannersession.vala +++ b/src/scanner-session/scannersession.vala @@ -78,6 +78,28 @@ public class ScannerSessionImplementation { return true; } + private ScannerSessionCodeType getCodeType(string scannerdata){ + if(scannerdata.has_prefix("USER ")){ + return ScannerSessionCodeType.USER; + } else if(scannerdata == "GUEST") { + return ScannerSessionCodeType.GUEST; + } else if(scannerdata == "UNDO") { + return ScannerSessionCodeType.UNDO; + } else if(scannerdata == "LOGOUT") { + return ScannerSessionCodeType.LOGOUT; + } else { + //Handle EAN Code + uint64 id = 0; + scannerdata.scanf("%llu", out id); + + /* check if scannerdata has valid format */ + if(scannerdata != "%llu".printf(id) && scannerdata != "%08llu".printf(id) && scannerdata != "%013llu".printf(id)) { + return ScannerSessionCodeType.UNKNOWN; + } + return ScannerSessionCodeType.EAN; + } + } + private void play_audio(AudioType audioType){ switch (audioType) { case AudioType.ERROR: |