Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 0 additions & 60 deletions BytePack.py

This file was deleted.

23 changes: 0 additions & 23 deletions CArrayWriter.py

This file was deleted.

13 changes: 7 additions & 6 deletions Example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from Mooshimeter import *
from mooshimeter.meter import Mooshimeter
from mooshimeter import bg_wrapper
import threading
import time

Expand All @@ -14,7 +15,7 @@ def run(self):

"""
Example.py
This script is meant to demonstrate use of the Mooshimeter and BGWrapper classes.
This script is meant to demonstrate use of the Mooshimeter and bg_wrapper classes.
The script does the following:
- Scan for BLE devices
- Filter for Mooshimeters
Expand Down Expand Up @@ -51,15 +52,15 @@ def writeCh2(self, meter, val):
if __name__=="__main__":
# Set up the lower level to talk to a BLED112 in port COM4
# REPLACE THIS WITH THE BLED112 PORT ON YOUR SYSTEM
BGWrapper.initialize("COM4")
bg_wrapper.initialize("COM4")
inputthread = InputThread()
inputthread.start()
cmd_queue = []
def addToQueue(s):
cmd_queue.append(s)
inputthread.cb = addToQueue
# Scan for 3 seconds
scan_results = BGWrapper.scan(5)
scan_results = bg_wrapper.scan(5)
# Filter for devices advertising the Mooshimeter service
results_wrapped = filter(lambda(p):Mooshimeter.mUUID.METER_SERVICE in p.ad_services, scan_results)
if len(results_wrapped) == 0:
Expand All @@ -75,7 +76,7 @@ def addToQueue(s):
m.loadTree()
# Wait for us to load the command tree
while m.tree.getNodeAtLongname('SAMPLING:TRIGGER')==None:
BGWrapper.idle()
bg_wrapper.idle()
# Unlock the meter by writing the correct CRC32 value
# The CRC32 node's value is written when the tree is received
m.sendCommand('admin:crc32 '+str(m.tree.getNodeAtLongname('admin:crc32').value))
Expand Down Expand Up @@ -103,7 +104,7 @@ def addToQueue(s):

while True:
# This call checks the serial port and processes new data
BGWrapper.idle()
bg_wrapper.idle()
if time.time()-last_heartbeat_time > 10:
last_heartbeat_time = time.time()
for m in meters:
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include LICENSE
include README.md
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# Mooshimeter-PythonAPI
A python API relying on the BLED112 to talk to the Mooshimeter

[![Build status](https://ci.appveyor.com/api/projects/status/5ajjxonexbaqsu6c/branch/master?svg=true)](https://ci.appveyor.com/project/spyoungtech/mooshimeter-pythonapi/branch/master)


# Install

```
pip install mooshimeter
```

**NOTE:** This package is maintained unofficially.
It has no official connection to the [official Mooshim repository](https://github.com/mooshim/Mooshimeter-PythonAPI).
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here as well



Example.py:
This script is meant to demonstrate use of the Mooshimeter and BGWrapper classes.
The script does the following:
Expand Down
36 changes: 0 additions & 36 deletions UUID.py

This file was deleted.

31 changes: 31 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
install:
- ps: |
py -2.7 -m virtualenv venv
.\venv\Scripts\activate.ps1
python -m pip install --upgrade pip
python -m pip install --upgrade .


build_script:
- ps: |
.\venv\Scripts\activate.ps1
python setup.py sdist bdist_wheel

artifacts:
- name: dist
path: dist\*

test: off

deploy_script:
- ps: |
if ($env:APPVEYOR_REPO_TAG -eq "true") {
py -2.7 -m virtualenv deploy_venv
.\deploy_venv\Scripts\activate.ps1
python -m pip install --upgrade pip
pip install --upgrade wheel
pip install --upgrade twine
twine upload dist\*
} else {
echo "Skipping Deploy Because this is not a tagged commit"
}
Empty file added mooshimeter/__init__.py
Empty file.
6 changes: 3 additions & 3 deletions BGWrapper.py → mooshimeter/bg_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import bglib
from mooshimeter.vendor import bglib
import serial
import time
from UUID import *
from mooshimeter.utils import UUID

# This module is designed to be used like a singleton class
# It wraps the functions of bglib in an easier to use way
Expand Down Expand Up @@ -126,7 +126,7 @@ def findHandleForUUID(self,uuid):
if c.uuid == uuid:
rval.append(c.handle)
if len(rval) != 1:
raise
raise Exception('Expected rval length to be exactly 1. Was %d length' % len(rval))
return rval[0]
def readByHandle(self,char_handle):
return read(self.conn_handle,char_handle)
Expand Down
6 changes: 3 additions & 3 deletions ConfigNode.py → mooshimeter/config_node.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import zlib
import CArrayWriter
from mooshimeter import utils

class NTYPE:
PLAIN =0 # May be an informational node, or a choice in a chooser
Expand Down Expand Up @@ -198,13 +198,13 @@ def writeCHeader(self,f):
f.write('} cmd_code_t;\n')

packed = self.pack()
CArrayWriter.writeHeader(f,'config_tree_packed',packed)
utils.writeHeader(f, 'config_tree_packed', packed)

f.write('extern const unsigned long config_tree_crc32;\n')
def writeCDec(self,f):
f.write('#pragma once\n')
packed = self.pack()
CArrayWriter.writeAsCArray(f,'config_tree_packed',packed)
utils.writeAsCArray(f, 'config_tree_packed', packed)

crc32 = zlib.crc32(packed)
# adapt for wart in zlib.crc32... signed ints
Expand Down
19 changes: 9 additions & 10 deletions Mooshimeter.py → mooshimeter/meter.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# coding=UTF-8
import BGWrapper
from UUID import *
from ConfigNode import *
from BytePack import *
from mooshimeter import bg_wrapper
from mooshimeter.config_node import NTYPE, ConfigNode, ConfigTree
from mooshimeter.utils import BytePack, UnderflowException, UUID
import binascii

class MeterSerOut(BGWrapper.Characteristic):
class MeterSerOut(bg_wrapper.Characteristic):
def __init__(self, meter, parent, handle, uuid):
"""
:param other: a BGWrapper.Characteristic
:param other: a bg_wrapper.Characteristic
:return:
"""
super(MeterSerOut,self).__init__(parent, handle, uuid)
Expand Down Expand Up @@ -76,10 +75,10 @@ def unpack(self):
self.aggregate += b.bytes[1:]
# Attempt to decode a message, if we succeed pop the message off the byte queue
self.interpretAggregate()
class MeterSerIn(BGWrapper.Characteristic):
class MeterSerIn(bg_wrapper.Characteristic):
def __init__(self, meter, parent, handle, uuid):
"""
:param other: a BGWrapper.Characteristic
:param other: a bg_wrapper.Characteristic
:return:
"""
super(MeterSerIn,self).__init__(parent, handle, uuid)
Expand Down Expand Up @@ -132,7 +131,7 @@ def sendToMeter(self, payload):
def __init__(self, peripheral):
"""
Initialized instance variables
:param peripheral: a BGWrapper.Peripheral instance
:param peripheral: a bg_wrapper.Peripheral instance
:return:
"""
self.p = peripheral
Expand Down Expand Up @@ -221,7 +220,7 @@ def tmp_cb():
wrap[0]+=1
self.meter_serout.enableNotify(True,tmp_cb)
def disconnect(self):
BGWrapper.disconnect(self.p.conn_handle)
bg_wrapper.disconnect(self.p.conn_handle)
def getUUIDString(self):
return self.p.getUUIDString()
def attachCallback(self,node_path,notify_cb):
Expand Down
Loading