Skip to content

Commit

Permalink
Adjust to changes in API after merge.
Browse files Browse the repository at this point in the history
  • Loading branch information
brettviren committed Nov 14, 2010
1 parent 62259b6 commit 6dcc256
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 30 deletions.
4 changes: 2 additions & 2 deletions python/gui.py
Expand Up @@ -4,6 +4,7 @@
'''


import omron
import Tkinter as tk
import matplotlib
matplotlib.use('TkAgg')
Expand Down Expand Up @@ -136,12 +137,11 @@ def cb_update_plot(self):

def cb_acquire(self):
print 'Acquiring data'
import omron
import store

omron_obj = omron.Omron()

if omron_obj.open(omron.OMRON_790IT_PID, omron.OMRON_790IT_VID) < 0:
if omron_obj.open() < 0:
print 'Failed to open device'
return

Expand Down
18 changes: 12 additions & 6 deletions python/omron_790IT_test.py
@@ -1,19 +1,24 @@
#!/usr/bin/env python

import os, sys
import omron, store, device
import os, sys

print 'Using',device.device()
print sys.path
devfile = device.device()
print 'Using', devfile, omron.VID, omron.PID

ret = omron.get_count(omron.OMRON_790IT_VID,omron.OMRON_790IT_PID)
dev = omron.create_device()
print dev, dev.device._is_inited
ret = omron.get_count(dev, omron.VID, omron.PID)
print ret
if not ret:
print 'No omron 790ITs connected!'
print 'No omron device!'
sys.exit(1)
print 'Found %d omron 790ITs'%ret
print 'Found %d omron'%ret

o = omron.Omron()
print 'Openning'
ret = o.open(omron.OMRON_790IT_VID, omron.OMRON_790IT_PID)
ret = o.open()
if ret < 0:
print 'Cannot open omron 790IT'
sys.exit(1)
Expand Down Expand Up @@ -46,6 +51,7 @@ def bad_data(r):
for ind in range(data_count-1,-1,-1):
for trial in range(3):
r = o.get_daily_bp_data(ind)
print ind,trial,r.year,r.month,r.day,r.hour,r.minute,r.second
if bad_data(r): continue
break

Expand Down
6 changes: 5 additions & 1 deletion swig/Omron.cxx
@@ -1,2 +1,6 @@
#include "Omron.h"
Omron::~Omron() {}
Omron::~Omron()
{
if (device) omron_close(device);
device = 0;
}
45 changes: 27 additions & 18 deletions swig/Omron.h
Expand Up @@ -8,6 +8,11 @@

#include "libomron/omron.h"

// unsigned ints are not wrapped well, so provide int versions
static const int VID = OMRON_VID;
static const int PID = OMRON_PID;


// Not in omron.h's API?
extern "C" {
int omron_get_daily_data_count(omron_device* dev, unsigned char bank);
Expand All @@ -16,25 +21,29 @@ int omron_get_daily_data_count(omron_device* dev, unsigned char bank);
#include <string>

class Omron {
omron_device device;
omron_device* device;
public:
typedef std::string data;

Omron() {
device.device_mode = NULL_MODE;
device = omron_create();
}
~Omron();

int open(int VID, int PID, unsigned int device_index = 0) {
return omron_open(&device, VID, PID, device_index);
int count(int vid=OMRON_VID, int pid=OMRON_PID) {
return omron_get_count(device, vid, pid);
}

int open(int vid=OMRON_VID, int pid=OMRON_PID, int device_index = 0) {
return omron_open(device, vid, pid, device_index);
}

int close() {
return omron_close(&device);
return omron_close(device);
}

int set_mode(omron_mode mode) {
return omron_set_mode(&device, mode);
return omron_set_mode(device, mode);
}

// not yet wrapped
Expand All @@ -44,59 +53,59 @@ class Omron {

Omron::data get_device_version() {
unsigned char buffer[30]={0}; /* buffer overflow begging to happen */
omron_get_device_version(&device, buffer);
omron_get_device_version(device, buffer);
return datify(buffer,30);
}

// Blood Pressure Functions
Omron::data get_bp_profile() {
unsigned char buffer[30]={0}; /* buffer overflow begging to happen */
int ret = omron_get_bp_profile(&device, buffer);
int ret = omron_get_bp_profile(device, buffer);
if (ret < 0) return Omron::data();
return datify(buffer,30);
}

//daily data information

int get_daily_data_count(int bank = 0) {
return omron_get_daily_data_count(&device, bank);
return omron_get_daily_data_count(device, bank);
}

// Not fully implemented
// omron_bp_day_info* get_all_daily_bp_data(int* count) {
// return omron_get_all_daily_bp_data(&device, count);
// return omron_get_all_daily_bp_data(device, count);
// }

// Note, reversal of arguments form C API
omron_bp_day_info get_daily_bp_data(int index, int bank = 0) {
return omron_get_daily_bp_data(&device, bank, index);
return omron_get_daily_bp_data(device, bank, index);
}

//weekly data information

// Not fully implemented
// omron_bp_week_info* get_all_weekly_bp_data(int* count) {
// return omron_get_all_weekly_bp_data(&device, count);
// return omron_get_all_weekly_bp_data(device, count);
// }

// Note, reversal of arguments from C API
omron_bp_week_info get_weekly_bp_data(int index,
bool evening=true, int bank=0) {
return omron_get_weekly_bp_data(&device, bank, index, evening?1:0);
return omron_get_weekly_bp_data(device, bank, index, evening?1:0);
}

// Pedometer Functions
omron_pd_profile_info get_pd_profile() {
return omron_get_pd_profile(&device);
return omron_get_pd_profile(device);
}
omron_pd_count_info get_pd_data_count(omron_device* dev) {
return get_pd_data_count(&device);
omron_pd_count_info get_pd_data_count() {
return omron_get_pd_data_count(device);
}
omron_pd_daily_data get_pd_daily_data(int day) {
return omron_get_pd_daily_data(&device, day);
return omron_get_pd_daily_data(device, day);
}
omron_pd_hourly_data* get_pd_hourly_data(int day) {
return omron_get_pd_hourly_data(&device, day);
return omron_get_pd_hourly_data(device, day);
}

private:
Expand Down
12 changes: 10 additions & 2 deletions swig/omron.i
@@ -1,6 +1,6 @@
%module omron
%{
#include "omron.h"
#include "libomron/omron.h"
#include "Omron.h"
%}

Expand All @@ -11,7 +11,15 @@
%array_functions(unsigned char, CharArray);

%ignore omron_get_daily_bp_data_count;
%ignore OMRON_VID; /* access as just VID */
%ignore OMRON_PID; /* access as just PID */

%rename(get_count) omron_get_count;
%rename(create_device) omron_create;
%rename(delete_device) omron_delete;

%typemap(in) uint32_t = int;
%typemap(out) uint32_t = int;

%include "omron.h"
%include "libomron/omron.h"
%include "Omron.h"

0 comments on commit 6dcc256

Please sign in to comment.