Example #1
0
def input_read(serial=None):
    reading = True
    # Arrows are composed of three chars: 1b, [, arrow
    # Ctrl+Arrows are composed of three chars: ;, 5, arrow
    is_arrow = 0
    is_ctrl_arrow = 0
    while (reading):
        if is_arrow == 0:
            print("input:")
        c = stdin_read_char()

        if DEBUG:
            print(repr(c))

        key = None
        if c == chr(3):  # Ctrl-C
            reading = False
        elif c == '\x00':
            key = 'ctrl- '
        elif c == '\x17':
            key = 'ctrl-w'
        elif c == '\x13':
            key = 'ctrl-s'
        elif c == '\x01':
            key = 'ctrl-a'
        elif c == '\x04':
            key = 'ctrl-d'
        elif c == '\x1b' and is_arrow == 0:
            is_arrow = 1
        elif c == '[' and is_arrow == 1:
            is_arrow = 2
        elif c == ';' and is_ctrl_arrow == 0:
            is_ctrl_arrow = 1
        elif c == '5' and is_ctrl_arrow == 1:
            is_ctrl_arrow = 2
        elif is_arrow == 2 or is_ctrl_arrow == 2:
            if c == 'A':
                key = 'up'
            elif c == 'B':
                key = 'down'
            elif c == 'D':
                key = 'left'
            elif c == 'C':
                key = 'right'
            if is_ctrl_arrow == 2:
                key = 'ctrl-' + key

            is_arrow = 0
            is_ctrl_arrow = 0
        else:
            key = c

        if key:
            if DEBUG:
                print("keypress: ", key)
            reading = keypress(key)
Example #2
0
    def run(self, argv):
        self.shownodeinfo()

        self.start_time0 = time.time()
        s = '{"starttime":%.3f}' % self.start_time0
        self.logger(s)

        if len(argv) == 0:
            signal.signal(signal.SIGINT, self.sigh)
            signal.signal(signal.SIGTERM, self.sigh)

            self.kp = keypress.keypress()
            self.kp.enable()
            self.rapl.start_energy_counter()
            while True:
                self.sample_temp('run')
                self.sample_energy('run')
                self.sample_freq('run')
                self.sample_acpi('run')

                time.sleep(self.intervalsec)
                if self.kp.available():
                    if self.kp.readkey() == 'q':
                        break
            self.rapl.stop_energy_counter()
            s = self.rapl.total_energy_json()
            self.logger(s)
            self.kp.disable()
            return

        self.cooldown('cooldown')

        # spawn a process and start the sampling thread
        t = threading.Thread(target=self.tee, args=[argv])
        t.start()

        self.rapl.start_energy_counter()

        while True:
            if not t.isAlive():
                break

            self.sample_temp('run')
            self.sample_energy('run')
            self.sample_freq('run')
            self.sample_acpi('run')

            time.sleep(self.intervalsec)

        self.rapl.stop_energy_counter()
        s = self.rapl.total_energy_json()
        self.logger(s)

        self.cooldown('cooldown')
Example #3
0
 def callback(self, x, y):
     # print((x,y))
     if y > 625:
         print('up')
         keypress.keypress(b'keydown Up\nkeyup Up\n')
     elif y < 375:
         print('down')
         keypress.keypress(b'keydown Down\nkeyup Down\n')
     if x > 325:
         print('left')
         keypress.keypress(b'keydown Left\nkeyup Left\n')
     elif x < 75:
         print('right')
         keypress.keypress(b'keydown Right\nkeyup Right\n')
Example #4
0
    cfg = {}
    cfg["c1"] = {"label": "Time", "unit": "Sec"}
    cfg["c1"] = {"label": "Energy", "unit": "Joules"}
    cfg["c3"] = {"label": "Power", "unit": "Watt"}
    #cfg["c"] = {"label":"Power Factor", "unit":""}
    # print >>f, json.dumps(cfg)

    # XXX: smq is not tested
    if smqflag:
        mq = smq.producer(ipaddr)
        mq.start()
        mq.dict = cfg
        print 'Message queue is started:', ipaddr

    kp = keypress.keypress()
    kp.enable()

    s = wt310.sample()
    time.sleep(1)

    sys.stderr.write('Press "q" to terminate\n')

    while True:
        wt310.start()

        s = wt310.sample()

        ts = time.time()

        ev = s['J']  # energy
Example #5
0
                if direction == "up":
                    newCol = self.parserRowHorizontal(column,"left")
                else:
                    newCol = self.parserRowHorizontal(column,"right")
                for row in range(size):
                    self.boardArray[row][col] = newCol[row]

    def noRoomToPlace(self):
        if len(self.getEmptyPosition()) == 0:return True
        else:return False

    def cannotContinue(self):
        size = self.__SIZE
        for row in range(size):
            for col in range(size):
                if col+1 < size and self.boardArray[row][col] == self.boardArray[row][col+1]:
                    return False
                if row+1 < size and self.boardArray[row][col] == self.boardArray[row+1][col]:
                    return False
        return True

if __name__ == "__main__":
    b = board()
    keyboard = keypress()
    while True:
        b.setNewBoard()
        b.printBoard()
        direction = keyboard.get()
        b.combinateSameHorizontal(direction)
        b.printBoard()