Skip to content

Commit

Permalink
Added app support
Browse files Browse the repository at this point in the history
  • Loading branch information
haritha-j committed May 4, 2018
1 parent 8b88643 commit d0a5c0b
Show file tree
Hide file tree
Showing 5,746 changed files with 1,133,562 additions and 109 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
Binary file added __pycache__/ir_hasher.cpython-36.pyc
Binary file not shown.
98 changes: 95 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,45 @@
var express = require('express');
var firebase = require ("firebase");
var bodyParser = require('body-parser');
var path = require('path');
var async = require('async');
const sqlite3 = require('sqlite3').verbose();
var http = require('http');
var PythonShell = require('python-shell');


var app = express();

var array1=[];






// Initialize Firebase
var config = {
apiKey: "AIzaSyDiWj84GS73KW_R5qLTUpvTXVbIRUAuNsQ",
authDomain: "supercart-f83c1.firebaseapp.com",
databaseURL: "https://supercart-f83c1.firebaseio.com",
projectId: "supercart-f83c1",
storageBucket: "supercart-f83c1.appspot.com",
messagingSenderId: "122025235969"
};
firebase.initializeApp(config);

//firebase database
var database = firebase.database();

//write to firebase
/* function writeProductData(key) {
firebase.database().ref('products/').push().set({
name: key
});
} */



/*
let db = new sqlite3.Database('./supermarket.db', (err) => {
if (err) {
Expand All @@ -19,7 +50,6 @@ let db = new sqlite3.Database('./supermarket.db', (err) => {
db.serialize(() => {
db.each(`SELECT id as id,
img as img
FROM ad`, (err, row) => {
if (err) {
console.error(err.message);
Expand Down Expand Up @@ -117,8 +147,34 @@ app.get('/login', function(req, res, next){

//display IR beam ad
app.get('/ad/:id', function(req, res, next){
res.render('beamAd',{ad: req.params.id});
})
isle=[];

let db = new sqlite3.Database('./supermarket.db', (err) => {
if (err) {
//console.error(err.message);
}
console.log('Connected to the supermarket database.');
});
let sql = `SELECT id id, isle_name isle_name, img img FROM beam WHERE id =?`;


db.all(sql, [req.params.id], (err, rows) =>{
if(err) {
console.error(err.message);
}
else{
console.log("CVB");
rows.forEach((row)=> {
isle.push(row);
});
res.render('beamAd', {isle:isle[0]});
}




});
});



Expand Down Expand Up @@ -222,6 +278,10 @@ app.post('/users/add', function(req, res, next){

//return checkout page
app.get('/checkout/:id', function(req, res, next){
// PythonShell.run('ir_hasher.py', function (err) {
// if (err) throw err;
// console.log('finished');
// });
res.render('checkout',{bill: req.params.id});
})

Expand Down Expand Up @@ -451,11 +511,36 @@ app.post('/queue', function(req, res, next) {


//product page

app.get('/test', function(req, res, next){

var productKeyRef = firebase.database().ref('products/').orderByKey().limitToLast(1);
productKeyRef.on('value', function(snapshot) {
for (var pro in snapshot.val()){
console.log(snapshot.val()[pro]["name"]);
res.redirect('/product/3');

}

//updateStarCount(postElement, snapshot.val()[-1].name);
});

})



app.get('/product/:id', function(req, res, next){
product=[];
relIDs=[];
adIDs=[];
ad=[];

//writeProductData("Milo");

//listen to firebase database



let db = new sqlite3.Database('./supermarket.db', (err) => {
if (err) {
//console.error(err.message);
Expand Down Expand Up @@ -735,3 +820,10 @@ app.listen(3000, function(){
console.log("server on 3000");
})


//llisten to firebase server





164 changes: 164 additions & 0 deletions ir_hasher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
#!/usr/bin/env python

import pigpio
import subprocess
verifyMode = False

class hasher:

"""
This class forms a hash over the IR pulses generated by an
IR remote.
The remote key press is not converted into a code in the manner of
the lirc module. No attempt is made to decode the type of protocol
used by the remote. The hash is likely to be unique for different
keys and different remotes but this is not guaranteed.
This hashing process works for some remotes/protocols but not for
others. The only way to find out if it works for one or more of
your remotes is to try it and see.
EXAMPLE CODE
#!/usr/bin/env python
import time
import pigpio
import ir_hasher
def callback(hash):
print("hash={}".format(hash));
pi = pigpio.pi()
ir = ir_hasher.hasher(pi, 7, callback, 5)
print("ctrl c to exit");
time.sleep(300)
pi.stop()
"""

def __init__(self, pi, gpio, callback, timeout=5):

"""
Initialises an IR remote hasher on a pi's gpio. A gap of timeout
milliseconds indicates the end of the remote key press.
"""

self.pi = pi
self.gpio = gpio
self.code_timeout = timeout
self.callback = callback

self.in_code = False

pi.set_mode(gpio, pigpio.INPUT)

self.cb = pi.callback(gpio, pigpio.EITHER_EDGE, self._cb)

def _hash(self, old_val, new_val):

if new_val < (old_val * 0.60):
val = 13
elif old_val < (new_val * 0.60):
val = 23
else:
val = 2

self.hash_val = self.hash_val ^ val
self.hash_val *= 16777619 # FNV_PRIME_32
self.hash_val = self.hash_val & ((1<<32)-1)

def _cb(self, gpio, level, tick):

if level != pigpio.TIMEOUT:

if self.in_code == False:

self.in_code = True

self.pi.set_watchdog(self.gpio, self.code_timeout)

self.hash_val = 2166136261 # FNV_BASIS_32

self.edges = 1

self.t1 = None
self.t2 = None
self.t3 = None
self.t4 = tick

else:

self.edges += 1

self.t1 = self.t2
self.t2 = self.t3
self.t3 = self.t4
self.t4 = tick

if self.t1 is not None:

d1 = pigpio.tickDiff(self.t1,self.t2)
d2 = pigpio.tickDiff(self.t3,self.t4)

self._hash(d1, d2)

else:

if self.in_code:

self.in_code = False

self.pi.set_watchdog(self.gpio, 0)

if self.edges > 12:

self.callback(self.hash_val)

if __name__ == "__main__":

import time
import pigpio
import ir_hasher

hashes = {
2808021165: '1',
111974127: '2',
927325: '3',
405145461: '4',
676276135: '5',
579589237:'6',
3120151957:'7',
2433712471:'8',
1239742133:'9',
2064946831: '10'

}

def callback(hash):
if hash in hashes:
print("{}".format(hashes[hash]));
if int(hashes[hash])<3:
subprocess.call("chromium-browser http://192.168.137.1:3000/ad/%s" % hashes[hash], shell=True)
else:
if verifyMode ==False:
subprocess.call("chromium-browser http://192.168.137.1:3000/product/%s" % (int(hashes[hash])-3), shell=True)
else:
print("fafsa")
else:
print(hash);

pi = pigpio.pi()

ir = ir_hasher.hasher(pi, 24, callback, 5)

print("ctrl c to exit");

time.sleep(1000)

pi.stop()

15 changes: 15 additions & 0 deletions node_modules/.bin/pbjs

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

7 changes: 7 additions & 0 deletions node_modules/.bin/pbjs.cmd

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

15 changes: 15 additions & 0 deletions node_modules/.bin/sshpk-conv

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

7 changes: 7 additions & 0 deletions node_modules/.bin/sshpk-conv.cmd

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

15 changes: 15 additions & 0 deletions node_modules/.bin/sshpk-sign

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

7 changes: 7 additions & 0 deletions node_modules/.bin/sshpk-sign.cmd

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

Loading

0 comments on commit d0a5c0b

Please sign in to comment.