[hw_scanner] implementation of the client side component of the barcode scanner proxy
bzr revid: fva@openerp.com-20140103130930-q1shnj9172yzn0gr
This commit is contained in:
parent
0fd4888e84
commit
434513e761
|
@ -20,7 +20,6 @@ class Proxy(http.Controller):
|
|||
def __init__(self):
|
||||
self.scale = 'closed'
|
||||
self.scale_weight = 0.0
|
||||
pass
|
||||
|
||||
def connected_usb_devices(self,devices):
|
||||
connected = []
|
||||
|
|
|
@ -86,11 +86,11 @@ class ScannerDriver(hw_proxy.Proxy):
|
|||
else:
|
||||
return None
|
||||
|
||||
@http.route('/hw_proxy/is_scanner_connected', type='http', auth='admin')
|
||||
@http.route('/hw_proxy/is_scanner_connected', type='json', auth='admin')
|
||||
def is_scanner_connected(self):
|
||||
return self.get_device() != None
|
||||
|
||||
@http.route('/hw_proxy/scanner', type='http', auth='admin')
|
||||
@http.route('/hw_proxy/scanner', type='json', auth='admin')
|
||||
def scanner(self):
|
||||
device = self.get_device()
|
||||
barcode = []
|
||||
|
@ -100,14 +100,14 @@ class ScannerDriver(hw_proxy.Proxy):
|
|||
else:
|
||||
device.grab()
|
||||
while True:
|
||||
r,w,x = select([device],[],[],10)
|
||||
r,w,x = select([device],[],[],5)
|
||||
if len(r) == 0: # timeout
|
||||
device.ungrab()
|
||||
return ''
|
||||
for event in device.read():
|
||||
if event.type == ecodes.EV_KEY:
|
||||
if event.value == 1: # keydown events
|
||||
print categorize(event)
|
||||
#print categorize(event)
|
||||
if event.code in self.keymap:
|
||||
if shift:
|
||||
barcode.append(self.keymap[event.code][1])
|
||||
|
@ -117,7 +117,8 @@ class ScannerDriver(hw_proxy.Proxy):
|
|||
shift = True
|
||||
elif event.code == 28: # ENTER
|
||||
device.ungrab()
|
||||
return ''.join(barcode);
|
||||
barcode = ''.join(barcode)
|
||||
return barcode
|
||||
elif event.value == 0: #keyup events
|
||||
if event.code == 42 or event.code == 54: # LEFT SHIFT
|
||||
shift = False
|
||||
|
|
|
@ -106,18 +106,21 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
|
|||
|
||||
this.connection = new instance.web.Session(undefined,url);
|
||||
this.connection.session_id = _.uniqueId('posproxy');
|
||||
this.connected = new $.Deferred();
|
||||
this.status = 'disconnected';
|
||||
this.test_connection();
|
||||
window.proxy = this;
|
||||
},
|
||||
close: function(){
|
||||
this.connection.destroy();
|
||||
this.status = 'disconnected';
|
||||
},
|
||||
message : function(name,params){
|
||||
var callbacks = this.notifications[name] || [];
|
||||
for(var i = 0; i < callbacks.length; i++){
|
||||
callbacks[i](params);
|
||||
}
|
||||
if(this.connected){
|
||||
if(this.status !== 'disconnected'){
|
||||
return this.connection.rpc('/hw_proxy/' + name, params || {});
|
||||
}else{
|
||||
return (new $.Deferred()).reject();
|
||||
|
@ -125,9 +128,13 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
|
|||
},
|
||||
test_connection: function(){
|
||||
var self = this;
|
||||
this.connected = true;
|
||||
return this.message('test_connection').fail(function(){
|
||||
self.connected = false;
|
||||
this.status = 'connecting';
|
||||
return this.message('test_connection').then(function(){
|
||||
self.status = 'connected';
|
||||
self.connected.resolve();
|
||||
},function(){
|
||||
self.status = 'disconnected';
|
||||
self.connected.reject();
|
||||
console.error('Could not connect to the Proxy');
|
||||
});
|
||||
},
|
||||
|
@ -331,7 +338,6 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
|
|||
* }
|
||||
*/
|
||||
print_receipt: function(receipt){
|
||||
console.log('PRINT RECEIPT:', receipt);
|
||||
return this.message('print_receipt',{receipt: receipt});
|
||||
},
|
||||
|
||||
|
@ -360,6 +366,7 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
|
|||
init: function(attributes){
|
||||
this.pos = attributes.pos;
|
||||
this.action_callback = {};
|
||||
this.proxy = attributes.proxy;
|
||||
|
||||
this.action_callback_stack = [];
|
||||
|
||||
|
@ -516,16 +523,20 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
|
|||
return parse_result;
|
||||
},
|
||||
|
||||
scan: function(type,code){
|
||||
if (type === 'ean13'){
|
||||
scan: function(code){
|
||||
if(code.length < 3){
|
||||
return;
|
||||
}else if(code.length === 13 && /^\d+$/.test(code)){
|
||||
var parse_result = this.parse_ean(code);
|
||||
}else if(type === 'reference'){
|
||||
}else if(this.pos.db.get_product_by_reference(code)){
|
||||
var parse_result = {
|
||||
encoding: 'reference',
|
||||
type: 'unit',
|
||||
code: code,
|
||||
prefix: '',
|
||||
};
|
||||
}else{
|
||||
return;
|
||||
}
|
||||
|
||||
if (parse_result.type === 'error') { //most likely a checksum error, raise warning
|
||||
|
@ -541,12 +552,6 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
|
|||
}
|
||||
},
|
||||
|
||||
on_reference: function(code){
|
||||
if(this.action_callback['reference']){
|
||||
this.action_callback['reference'](code);
|
||||
}
|
||||
},
|
||||
|
||||
// starts catching keyboard events and tries to interpret codebar
|
||||
// calling the callbacks when needed.
|
||||
connect: function(){
|
||||
|
@ -583,11 +588,7 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
|
|||
// Internal Ref 5449 vs EAN13 5449000...
|
||||
|
||||
timeout = setTimeout(function(){
|
||||
if(code.length === 13 && onlynumbers){
|
||||
self.scan('ean13',code);
|
||||
}else if(code.length >= 3 && self.pos.db.get_product_by_reference(code)){
|
||||
self.scan('reference',code);
|
||||
}
|
||||
self.scan(code);
|
||||
code = "";
|
||||
onlynumbers = true;
|
||||
},100);
|
||||
|
@ -599,6 +600,27 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
|
|||
// stops catching keyboard events
|
||||
disconnect: function(){
|
||||
$('body').off('keypress', this.handler)
|
||||
this.remote_scanning = false;
|
||||
},
|
||||
connect_to_proxy: function(){
|
||||
var self = this;
|
||||
this.remote_scanning = true;
|
||||
|
||||
this.proxy.connected.then(function waitforbarcode(){
|
||||
if(!self.remote_scanning){
|
||||
return;
|
||||
}
|
||||
return self.proxy.connection.rpc('/hw_proxy/scanner',{}).then(function(barcode){
|
||||
if(!self.remote_scanning){
|
||||
return;
|
||||
}
|
||||
self.scan(barcode);
|
||||
waitforbarcode();
|
||||
},
|
||||
function(){
|
||||
setTimeout(waitforbarcode,5000);
|
||||
});
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -21,8 +21,9 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
|
|||
this.session = session;
|
||||
this.flush_mutex = new $.Mutex(); // used to make sure the orders are sent to the server once at time
|
||||
|
||||
this.barcode_reader = new module.BarcodeReader({'pos': this}); // used to read barcodes
|
||||
this.proxy = new module.ProxyDevice(); // used to communicate to the hardware devices via a local proxy
|
||||
this.barcode_reader = new module.BarcodeReader({'pos': this, proxy:this.proxy}); // used to read barcodes
|
||||
this.barcode_reader.connect_to_proxy();
|
||||
this.proxy_queue = new module.JobQueue(); // used to prevent parallels communications to the proxy
|
||||
this.db = new module.PosDB(); // a local database used to search trough products and categories & store pending orders
|
||||
this.debug = jQuery.deparam(jQuery.param.querystring()).debug !== undefined; //debug mode
|
||||
|
|
Loading…
Reference in New Issue