def main(): gc.enable() hw = hardware.Hardware() hw.oled_clear() hw.oled_graphic('start.txt', 0, 8) hw.oled_show() hw.pixel_color(64, 64, 64) sta = network.WLAN(network.STA_IF) ap = network.WLAN(network.AP_IF) while True: sta.active(True) starting_time = time.time() while not sta.isconnected() and (time.time() - starting_time) < 10: pass if not sta.isconnected(): time.sleep(5) gc.collect() import config config.Work(hw) ap.active(False) else: time.sleep(5) gc.collect() import widget widget.Work(hw) gc.collect()
def main(): hw = hardware.Hardware() hw.free20.set_textpos(16, 16) hw.free20.printstring('TrumpBox') for i in range(100): hw.oled.pixel((13 + i), 11, 1) hw.oled.pixel((13 + i), 39, 1) hw.oled.show() for i in range(255): hw.oled.contrast(255 - i) time.sleep(0.005) hw.oled.fill(0) hw.oled.show() sta = network.WLAN(network.STA_IF) ap = network.WLAN(network.AP_IF) while True: sta.active(True) starting_time = time.time() while not sta.isconnected() and (time.time() - starting_time) < 10: pass if not sta.isconnected(): time.sleep(5) import networkconfig networkconfig.start(hw) ap.active(False) else: time.sleep(5) import trumpbox trumpbox.blather(hw)
def updateHardware(): s = rpcServer.getServer() hardwareList = hardware.Hardware() s.registration.refresh_hw_profile(up2dateAuth.getSystemId(), hardwareList)
def __init__(self, pygame_instance, role, ip, port, name): self.pygame = pygame_instance #config self.myid = 0 # will be set by the server! self.health = 100.0 self.ammo = 1000 self.shotDuration = 100 #milliseconds self.cooldownDuration = 400 #milliseconds self.deathDuration = 5000 #milliseconds #runtime state self.shotEnd = 0 self.cooldownEnd = 0 self.deathEnd = 0 self.state = PlayerState.IDLE #self.sounds = sounds.Sounds(self.pygame) self.display = display.Display(self.pygame, self.health, self.ammo) self.hardware = hardware.Hardware() self.role = role #TODO: if the player role is server: start the server in another thread and connect client via localhost! if role == PlayerRole.SERVER: reactor.listenTCP(port, networkserver.PlayerFactory()) ip = "127.0.0.1" #always connect to our own server! self.networkclient = networkclient.NetworkClient() self.networkclient.connect( ip, port, name ) #TODO: uh, we need to iterate the server reactor during this, right?
def __init__(self): self.logger = logging.getLogger(Constants.LOGNAME) configString = open(os.path.join(basedir, "config.json")).read() self.config = json.loads(configString) self.hardware = hardware.Hardware() self.activeChannel = None self.stopTime = None self.timerThread = threading.Thread(target=self.timerRun) self.timerThread.daemon = True self.timerThread.start() self.history = history.History(os.path.join(basedir, "history.txt")) self.history.readEntries() for ch in self.hardware.getInputChannelNumbers(): self.hardware.getInput(ch).registerCallback(self.__cb)
def __init__(self, hardware=None): if hardware is None: import hardware self.events = DiscardingQueue(20) self.hardware = hardware.Hardware(self.events) self.mode = None self.finished = False self.joystick = None self.menu_items = [ ("Manual", manual.Manual), ("Challenges", [ ("Shooter", shooter.Shooter), ("Escape", [ ("Learn", escape.Learn), ("Walk", escape.Walk), ("Run", escape.Run) ]), ("Lava", [ ("Palava", lava.Lava), ]), ("Minesweeper", None), ("Eco-disaster", [ ("Test", eco.Test), ("Main", eco.EcoDisaster), ]), ]), ("Calibrate", [ ("Lens", calibrate.Lens), ("White Balance", calibrate.WhiteBalance), ("Camera Pos", calibrate.CameraPosition), ("Turning", calibrate.Spin), ("Grabber", calibrate.Grabber), ("Stabber", calibrate.StabberCal) ]), ("STOP", self.hardware.drive.stop), ("Debug", [ ("Debug?", self.exit), ]), ("Shutdown", [ ("Confirm", self.shutdown), ]), ] self.menu = menu.Menu(self.menu_items, self.hardware, self.handle_menu_select_item)
def __init__(self, ip, id): """ Create a new SmartDevice instance, identified through its IP address. :param str ip: ip address on which the device listens :raises SmartPlugException: when unable to communicate with the device """ self.__deactivated = False self._ip = ip self.__id = id self.netif = netif.Netif(self) self.cloud = cloud.Cloud(self) self.time = dtime.DTime(self) self.anti_theft = schedules.AntiTheft(self) self.count_down = schedules.Countdown(self) self.schedule = schedules.Schedule(self) self.system = system.System(self) self.firmware = firmware.Firmware(self) self.hardware = hardware.Hardware(self) self._polling_data = None self.__callbacks = []
def __init__(self, screen, tui): self.screen = screen self.tui = tui size = snack._snack.size() #get the virtualization uuid and set it to other. (virt_uuid, virt_type) = rhnreg.get_virt_info() if not virt_uuid is None: self.tui.other['virt_uuid'] = virt_uuid self.tui.other['virt_type'] = virt_type # read all hardware in tui.hardware = hardware.Hardware() toplevel = snack.GridForm(screen, HARDWARE_WINDOW.encode('utf-8'), 1, 7) text = snack.TextboxReflowed(70, HARDWARE_WINDOW_DESC1.encode('utf-8')) toplevel.add(text, 0, 0, anchorLeft=1) grid = snack.Grid(2, 2) label = snack.Label(_("Profile name:").encode('utf-8')) grid.setField(label, 0, 0, padding=(0, 0, 1, 0), anchorRight=1) self.profileEntry = snack.Entry(40) grid.setField(self.profileEntry, 1, 0, anchorLeft=1) toplevel.add(grid, 0, 1, anchorLeft=1) if tui.includeHardware: self.hardwareButton = snack.Checkbox( HARDWARE_WINDOW_CHECKBOX.encode('utf-8'), isOn=1) else: self.hardwareButton = snack.Checkbox( HARDWARE_WINDOW_CHECKBOX.encode('utf-8')) toplevel.add(self.hardwareButton, 0, 2, padding=(0, 1, 0, 0), anchorLeft=1) label = snack.Label(DESELECT.encode('utf-8')) toplevel.add(label, 0, 3, anchorLeft=1, padding=(0, 0, 0, 1)) grid = snack.Grid(4, 3) hardware_text = '' hardware_text += _("Version: ") + up2dateUtils.getVersion() + " " self.versionLabel = snack.Label(_("Version: ").encode('utf-8')) grid.setField(self.versionLabel, 0, 0, padding=(0, 0, 1, 0), anchorLeft=1) self.versionLabel2 = snack.Label(up2dateUtils.getVersion()) grid.setField(self.versionLabel2, 1, 0, anchorLeft=1) hardware_text += _("CPU model: ") for hw in tui.hardware: if hw['class'] == 'CPU': hardware_text += hw['model'] + "\n" hardware_text += _("Hostname: ") for hw in tui.hardware: if hw['class'] == 'NETINFO': unicode_hostname = idn_pune_to_unicode(hw['hostname']) hardware_text += unicode_hostname + "\n" if tui.profileName != "": self.profileEntry.set(tui.profileName) else: self.profileEntry.set(unicode_hostname.encode('utf-8')) hardware_text += _("CPU speed: ") for hw in tui.hardware: if hw['class'] == 'CPU': hardware_text += _("%d MHz") % hw['speed'] + " " hardware_text += _("IP Address: ") for hw in tui.hardware: if hw['class'] == 'NETINFO': if hw['ipaddr']: hardware_text += hw['ipaddr'] + " " elif hw['ip6addr']: hardware_text += hw['ip6addr'] + " " hardware_text += _("Memory: ") for hw in tui.hardware: if hw['class'] == 'MEMORY': hardware_text += _("%s megabytes") % hw['ram'] tb = snack.TextboxReflowed(80, hardware_text.encode('utf-8')) toplevel.add(tb, 0, 4) self.additionalHWLabel = snack.TextboxReflowed( size[0] - 10, HARDWARE_WINDOW_DESC2.encode('utf-8')) toplevel.add(self.additionalHWLabel, 0, 5, padding=(0, 1, 0, 0), anchorLeft=1) # BUTTON BAR self.bb = snack.ButtonBar(screen, [(NEXT.encode('utf-8'), "next"), (BACK.encode('utf-8'), "back"), (CANCEL.encode('utf-8'), "cancel")]) toplevel.add(self.bb, 0, 6, padding=(0, 1, 0, 0), growx=1) self.g = toplevel
import hardware
import time import pygame pygame.mixer.pre_init(44100, -16, 1, 512) # must be called before pygame.init!!! pygame.init() import sounds sounds = sounds.Sounds() import hardware hardware = hardware.Hardware() hardware.setWeaponCharacteristics(playerid=123, damage=42, laser_duration=1) while True: if hardware.isWeaponButtonDown(0): sounds.play('pew', False) hardware.shootWeapon(laser0=1, laser1=0) time.sleep(0.3) time.sleep(0.005)
import hardware
zip(self.laps, self.lanes)) @property def max_speed(self): return map((lambda l: max(l) if l else 0.0), self.speeds) @property def avg_speed(self): return map((lambda (s, l): s / l if l != 0 else 0.0), zip(map(sum, self.speeds), self.num_laps)) if __name__ == "__main__": import hardware h = hardware.Hardware("/dev/ttyUSB0") r = Race([1.0, 1.0]) try: while True: evt = h.get_event() if evt: r.add_lap(*evt) print "r.num_laps ", r.num_laps print "r.total_time", r.total_time print "r.avg_time ", r.avg_time print "r.max_speed ", r.max_speed print "r.avg_speed ", r.avg_speed print finally:
import xmlrpclib import rpcServer import hardware def updateHardware(): registered = rhnAuth.getSystemId() if not registered: print "system not registered" sys.exit(1) try: rhnAuth.updateLoginInfo() except xmlrpclib.Fault, f: faultError(f.faultString) sys.exit(1) except rhnErrors.ServerCapabilityError, e: print e sys.exit(1) except rhnErrors.CommunicationError, e: print e sys.exit(1) #print _("Updating package profile...") s = rpcServer.getServer() hardwareList = hardware.Hardware() s.registration.refresh_hw_profile(registered, hardwareList)