<commit_before>#!/usr/bin/env python

import time
import os, sys
topdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(topdir)
import i2c_device

print i2c_device
print dir(i2c_device)

dev = i2c_device.I2CDevice(1,0x2d,config=topdir+'/sample_configs/dmcc_i2c.yaml')
print "Device: ", dev

reg = dev.registers['PowerMotor1']
print "Register: ", reg

print "Read from reg: ", reg.read()

num = 25
start = time.time()
for i in range(num):
    reg.read()
ms = (time.time() - start) *1000
print "Read {} 16-bit signed values in {:0.2f} ms, {:0.3f} ms/read".format(num,ms,ms/num)
print

print "Write positive to reg: "
reg.write(1500)
print "Read from reg: ", reg.read()
print
print "Write neg to reg: "
reg.write(-1500)
print "Read from reg: ", reg.read()
print
print "Write zero to reg: "
reg.write(0)
print "Read from reg: ", reg.read()
print

print "Battery voltage:", dev.registers['Voltage'].read()/1000.0
print
while True:
  #dev.registers['Execute'].write_val('Refresh')
  dev.registers['Execute'].write(0x00)
  print "QEI 1:", dev.registers['QEI1Velocity'].read()


<commit_msg>Improve DMCC example<commit_after>#!/usr/bin/env python

import time
import os, sys
topdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(topdir)
import i2c_device

print i2c_device
print dir(i2c_device)

dev = i2c_device.I2CDevice(1,0x2d,config=topdir+'/sample_configs/dmcc_i2c.yaml')
print "Device: ", dev

reg = dev.registers['PowerMotor1']
print "Register: ", reg

print "Read from reg: ", reg.read()

num = 25
start = time.time()
for i in range(num):
    reg.read()
ms = (time.time() - start) *1000
print "Read {} 16-bit signed values in {:0.2f} ms, {:0.3f} ms/read".format(num,ms,ms/num)
print

print "Write positive to reg: "
reg.write(1500)
print "Read from reg: ", reg.read()
print
print "Write neg to reg: "
reg.write(-1500)
print "Read from reg: ", reg.read()
print
print "Write zero to reg: "
reg.write(0)
print "Read from reg: ", reg.read()
print

t0 = time.time()
while True:
  #dev.registers['Execute'].write_val('Refresh')
  elapsed = time.time() - t0
  dev.registers['Execute'].write(0x00)
  pos1 = dev.registers['QEI1Position'].read()
  vel1 = dev.registers['QEI1Velocity'].read()
  voltage = dev.registers['Voltage'].read()/1000.0
  print "{:8.3f} QEI 1: Voltage: {},  Pos {}, Vel {}".format(elapsed, voltage, pos1, vel1)



{'fraction_non_alphanumeric': 0.17176372015081692, 'fraction_numerical': 0.03812316715542522, 'mean_word_length': 4.824390243902439, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2446564', 'n_tokens_mistral': 972, 'n_tokens_neox': 925, 'n_words': 223}