Skip to content

Commit 9dcb863

Browse files
CloudyPadmalmariobehling
authored andcommitted
Reformat code and Upgraded Travis + Makefile (fossasia#95)
* docs: refactoring codebase * upgrade: python syntax for slice indices * chore: upgrading travis script * chore: updating makefile and travis * docs: added os logos
1 parent 1c554a9 commit 9dcb863

27 files changed

+1016
-996
lines changed

.travis.yml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
language: python
2+
3+
sudo: true
4+
25
python:
3-
- "2.7"
4-
- "3.4"
5-
- "3.5"
6-
- "3.6"
7-
script: nosetests
6+
- "3.4"
7+
- "3.5"
8+
- "3.6"
89

9-
notifications:
10-
slack: fossasia:bqOzo4C9y6oI6dTF8kO8zdxp
10+
before_install:
11+
- sudo apt-get -qq update
12+
- sudo mkdir -p /builds
13+
- sudo chmod a+rw /builds
14+
15+
install:
16+
- pip3 install -r requirements.txt
17+
- sudo env "PATH=$PATH" make clean
18+
- make all
19+
- sudo env "PATH=$PATH" make install
20+
21+
script: nosetests

Makefile

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
11
DESTDIR =
2+
3+
# Find library installation path
4+
INSTALL_PATH = $(patsubst Location:,,$(shell pip show PSL | grep Location))
5+
INSTALL_PATH_LEN = $(shell echo $(INSTALL_PATH) | wc -c)
6+
27
all:
3-
#make -C docs html
4-
#make -C docs/misc all
5-
# make in subdirectory PSLab-apps-master if it is there
6-
[ ! -d PSLab-apps-master ] || make -C PSLab-apps-master $@ DESTDIR=$(DESTDIR)
78
python3 setup.py build
89

910
clean:
10-
rm -rf docs/_*
11-
# make in subdirectory PSLab-apps-master if it is there
12-
[ ! -d PSLab-apps-master ] || make -C PSLab-apps-master $@ DESTDIR=$(DESTDIR)
13-
rm -rf PSL.egg-info build
14-
find . -name "*~" -o -name "*.pyc" -o -name "__pycache__" | xargs rm -rf
15-
16-
IMAGEDIR=$(DESTDIR)/usr/share/doc/pslab-common/images
11+
# Remove build files
12+
@rm -rf docs/_*
13+
@rm -rf PSL.egg-info build
14+
@find . -name "*~" -o -name "*.pyc" -o -name "__pycache__" | xargs rm -rf
15+
# Remove previously installed library files if there is any
16+
if [ ${INSTALL_PATH_LEN} -gt 2 ]; then sudo rm -rf $(INSTALL_PATH)/PSL $(INSTALL_PATH)/PSL-1* ; fi
1717

1818
install:
19-
# make in subdirectory PSLab-apps-master if it is there
20-
[ ! -d PSLab-apps-master ] || make -C PSLab-apps-master $@ DESTDIR=$(DESTDIR)
21-
# install documents
22-
install -d $(DESTDIR)/usr/share/doc/pslab
23-
#cp -a docs/_build/html $(DESTDIR)/usr/share/doc/pslab
24-
#cp docs/misc/build/*.html $(DESTDIR)/usr/share/doc/pslab/html
25-
python3 setup.py install --install-layout=deb \
26-
--root=$(DESTDIR)/ --prefix=/usr
19+
python3 setup.py install
2720
# rules for udev
2821
mkdir -p $(DESTDIR)/lib/udev/rules.d
2922
install -m 644 99-pslab.rules $(DESTDIR)/lib/udev/rules.d/99-pslab
30-
# fix a few permissions
31-
#find $(DESTDIR)/usr/share/pslab/psl_res -name auto.sh -exec chmod -x {} \;

PSL/Peripherals.py

Lines changed: 58 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ class I2C():
3434
3535
"""
3636
samples = 0
37-
total_bytes=0
37+
total_bytes = 0
3838
channels = 0
39-
tg=100
39+
tg = 100
4040
MAX_SAMPLES = 10000
41+
4142
def __init__(self, H):
4243
self.H = H
4344
from PSL import sensorlist
@@ -284,7 +285,6 @@ def read_repeat(self):
284285
except Exception as ex:
285286
self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)
286287

287-
288288
def read_end(self):
289289
try:
290290
self.H.__sendByte__(CP.I2C_HEADER)
@@ -295,7 +295,6 @@ def read_end(self):
295295
except Exception as ex:
296296
self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)
297297

298-
299298
def read_status(self):
300299
try:
301300
self.H.__sendByte__(CP.I2C_HEADER)
@@ -306,7 +305,6 @@ def read_status(self):
306305
except Exception as ex:
307306
self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)
308307

309-
310308
def readBulk(self, device_address, register_address, bytes_to_read):
311309
try:
312310
self.H.__sendByte__(CP.I2C_HEADER)
@@ -379,7 +377,7 @@ def scan(self, frequency=100000, verbose=False):
379377
self.stop()
380378
return addrs
381379

382-
def __captureStart__(self,address,location,sample_length,total_samples,tg):
380+
def __captureStart__(self, address, location, sample_length, total_samples, tg):
383381
"""
384382
Blocking call that starts fetching data from I2C sensors like an oscilloscope fetches voltage readings
385383
You will then have to call `__retrievebuffer__` to fetch this data, and `__dataProcessor` to process and return separate channels
@@ -399,16 +397,15 @@ def __captureStart__(self,address,location,sample_length,total_samples,tg):
399397
:return: Arrays X(timestamps),Y1,Y2 ...
400398
401399
"""
402-
if(tg<20):tg=20
403-
total_bytes = total_samples*sample_length
404-
print ('total bytes calculated : ',total_bytes)
405-
if(total_bytes>self.MAX_SAMPLES*2):
406-
print ('Sample limit exceeded. 10,000 int / 20000 bytes total')
407-
total_bytes = self.MAX_SAMPLES*2
408-
total_samples = total_bytes/sample_length #2* because sample array is in Integers, and we're using it to store bytes
409-
410-
411-
print ('length of each channel : ',sample_length)
400+
if (tg < 20): tg = 20
401+
total_bytes = total_samples * sample_length
402+
print('total bytes calculated : ', total_bytes)
403+
if (total_bytes > self.MAX_SAMPLES * 2):
404+
print('Sample limit exceeded. 10,000 int / 20000 bytes total')
405+
total_bytes = self.MAX_SAMPLES * 2
406+
total_samples = total_bytes / sample_length # 2* because sample array is in Integers, and we're using it to store bytes
407+
408+
print('length of each channel : ', sample_length)
412409
self.total_bytes = total_bytes
413410
self.channels = sample_length
414411
self.samples = total_samples
@@ -419,55 +416,57 @@ def __captureStart__(self,address,location,sample_length,total_samples,tg):
419416
self.H.__sendByte__(address)
420417
self.H.__sendByte__(location)
421418
self.H.__sendByte__(sample_length)
422-
self.H.__sendInt__(total_samples) #total number of samples to record
423-
self.H.__sendInt__(tg) #Timegap between samples. 1MHz timer clock
419+
self.H.__sendInt__(total_samples) # total number of samples to record
420+
self.H.__sendInt__(tg) # Timegap between samples. 1MHz timer clock
424421
self.H.__get_ack__()
425-
return 1e-6*self.samples*self.tg+.01
422+
return 1e-6 * self.samples * self.tg + .01
426423

427424
def __retrievebuffer__(self):
428425
'''
429426
Fetch data acquired by the I2C scope. refer to :func:`__captureStart__`
430427
'''
431-
total_int_samples = self.total_bytes/2
428+
total_int_samples = self.total_bytes / 2
432429
DATA_SPLITTING = 500
433-
print ('fetchin samples : ',total_int_samples,' split',DATA_SPLITTING)
434-
data=b''
435-
for i in range(int(total_int_samples/DATA_SPLITTING)):
430+
print('fetchin samples : ', total_int_samples, ' split', DATA_SPLITTING)
431+
data = b''
432+
for i in range(int(total_int_samples / DATA_SPLITTING)):
436433
self.H.__sendByte__(CP.ADC)
437434
self.H.__sendByte__(CP.GET_CAPTURE_CHANNEL)
438-
self.H.__sendByte__(0) #starts with A0 on PIC
435+
self.H.__sendByte__(0) # starts with A0 on PIC
439436
self.H.__sendInt__(DATA_SPLITTING)
440-
self.H.__sendInt__(i*DATA_SPLITTING)
441-
rem = DATA_SPLITTING*2+1
437+
self.H.__sendInt__(i * DATA_SPLITTING)
438+
rem = DATA_SPLITTING * 2 + 1
442439
for _ in range(200):
443-
partial = self.H.fd.read(rem) #reading int by int sometimes causes a communication error. this works better.
444-
rem -=len(partial)
445-
data+=partial
446-
#print ('partial: ',len(partial), end=",")
447-
if rem<=0:
440+
partial = self.H.fd.read(
441+
rem) # reading int by int sometimes causes a communication error. this works better.
442+
rem -= len(partial)
443+
data += partial
444+
# print ('partial: ',len(partial), end=",")
445+
if rem <= 0:
448446
break
449-
data=data[:-1]
450-
#print ('Pass : len=',len(data), ' i = ',i)
447+
data = data[:-1]
448+
# print ('Pass : len=',len(data), ' i = ',i)
451449

452-
if total_int_samples%DATA_SPLITTING:
450+
if total_int_samples % DATA_SPLITTING:
453451
self.H.__sendByte__(CP.ADC)
454452
self.H.__sendByte__(CP.GET_CAPTURE_CHANNEL)
455-
self.H.__sendByte__(0) #starts with A0 on PIC
456-
self.H.__sendInt__(total_int_samples%DATA_SPLITTING)
457-
self.H.__sendInt__(total_int_samples-total_int_samples%DATA_SPLITTING)
458-
rem = 2*(total_int_samples%DATA_SPLITTING)+1
453+
self.H.__sendByte__(0) # starts with A0 on PIC
454+
self.H.__sendInt__(total_int_samples % DATA_SPLITTING)
455+
self.H.__sendInt__(total_int_samples - total_int_samples % DATA_SPLITTING)
456+
rem = 2 * (total_int_samples % DATA_SPLITTING) + 1
459457
for _ in range(20):
460-
partial = self.H.fd.read(rem) #reading int by int sometimes causes a communication error. this works better.
461-
rem -=len(partial)
462-
data+=partial
463-
#print ('partial: ',len(partial), end="")
464-
if rem<=0:
458+
partial = self.H.fd.read(
459+
rem) # reading int by int sometimes causes a communication error. this works better.
460+
rem -= len(partial)
461+
data += partial
462+
# print ('partial: ',len(partial), end="")
463+
if rem <= 0:
465464
break
466-
data=data[:-1]
467-
print ('Final Pass : len=',len(data))
465+
data = data[:-1]
466+
print('Final Pass : len=', len(data))
468467
return data
469468

470-
def __dataProcessor__(self,data,*args):
469+
def __dataProcessor__(self, data, *args):
471470
'''
472471
Interpret data acquired by the I2C scope. refer to :func:`__retrievebuffer__` to fetch data
473472
@@ -482,19 +481,19 @@ def __dataProcessor__(self,data,*args):
482481

483482
try:
484483
data = [ord(a) for a in data]
485-
if('int' in args):
486-
for a in range(self.channels*self.samples/2): self.buff[a] = np.int16((data[a*2]<<8)|data[a*2+1])
484+
if ('int' in args):
485+
for a in range(self.channels * self.samples / 2): self.buff[a] = np.int16(
486+
(data[a * 2] << 8) | data[a * 2 + 1])
487487
else:
488-
for a in range(self.channels*self.samples): self.buff[a] = data[a]
488+
for a in range(self.channels * self.samples): self.buff[a] = data[a]
489489

490-
yield np.linspace(0,self.tg*(self.samples-1),self.samples)
491-
for a in range(int(self.channels/2)):
492-
yield self.buff[a:self.samples*self.channels/2][::self.channels/2]
490+
yield np.linspace(0, self.tg * (self.samples - 1), self.samples)
491+
for a in range(int(self.channels / 2)):
492+
yield self.buff[a:self.samples * self.channels / 2][::self.channels / 2]
493493
except Exception as ex:
494-
msg = "Incorrect number of bytes received",ex
494+
msg = "Incorrect number of bytes received", ex
495495
raise RuntimeError(msg)
496496

497-
498497
def capture(self, address, location, sample_length, total_samples, tg, *args):
499498
"""
500499
Blocking call that fetches data from I2C sensors like an oscilloscope fetches voltage readings
@@ -525,10 +524,10 @@ def capture(self, address, location, sample_length, total_samples, tg, *args):
525524
:return: Arrays X(timestamps),Y1,Y2 ...
526525
527526
"""
528-
t = self.__captureStart__(address,location,sample_length,total_samples,tg)
527+
t = self.__captureStart__(address, location, sample_length, total_samples, tg)
529528
time.sleep(t)
530529
data = self.__retrievebuffer__()
531-
return self.__dataProcessor__(data,*args)
530+
return self.__dataProcessor__(data, *args)
532531

533532

534533
class SPI():
@@ -665,7 +664,6 @@ def send8(self, value):
665664
except Exception as ex:
666665
self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)
667666

668-
669667
def send16(self, value):
670668
"""
671669
SENDS 16-bit data over SPI
@@ -691,7 +689,6 @@ def send16(self, value):
691689
except Exception as ex:
692690
self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)
693691

694-
695692
def send8_burst(self, value):
696693
"""
697694
SENDS 8-bit data over SPI
@@ -736,14 +733,15 @@ def send16_burst(self, value):
736733
except Exception as ex:
737734
self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)
738735

739-
def xfer(self,chan,data):
736+
def xfer(self, chan, data):
740737
self.start(chan)
741-
reply=[]
738+
reply = []
742739
for a in data:
743740
reply.append(self.send8(a))
744741
self.stop(chan)
745742
return reply
746743

744+
747745
class DACCHAN:
748746
def __init__(self, name, span, channum, **kwargs):
749747
self.name = name
@@ -771,7 +769,6 @@ def load_calibration_twopoint(self, slope, offset):
771769

772770
# print('########################',slope,offset)
773771

774-
775772
def apply_calibration(self, v):
776773
if self.calibration_enabled == 'table': # Each point is individually calibrated
777774
return int(np.clip(v + self.calibration_table[v], 0, 4095))
@@ -1014,7 +1011,6 @@ def rxchar(self):
10141011
except Exception as ex:
10151012
self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)
10161013

1017-
10181014
def txchar(self, char):
10191015
'''
10201016
Transmits a single character
@@ -1040,7 +1036,6 @@ def hasData(self):
10401036
except Exception as ex:
10411037
self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)
10421038

1043-
10441039
def flush(self):
10451040
'''
10461041
Flushes the TX and RX FIFOs
@@ -1083,7 +1078,6 @@ def read_register(self, address):
10831078
except Exception as ex:
10841079
self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)
10851080

1086-
10871081
def get_status(self):
10881082
'''
10891083
Returns a byte representing the STATUS register on the radio.

PSL/SENSORS/AD7718_class.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import print_function
2-
import time, importlib
2+
3+
import time
4+
35
import numpy as np
46

57
'''
@@ -12,8 +14,6 @@
1214
1315
'''
1416

15-
import struct
16-
1717

1818
def _bv(x):
1919
return 1 << x

PSL/SENSORS/AD9833.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import time, sys
2-
import numpy as np
1+
import sys
32

43

54
class AD9833:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy