summaryrefslogtreecommitdiff
path: root/py/helpers.py
blob: e92163ceaac9c92015a8300da0ef859a0542d0fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import pykms

def add_props(areq, ob, map):
    for key, value in map.items():
        areq.add(ob, key, value)

def props(o):
    o.refresh_props()
    map = o.prop_map
    for propid,propval in map.items():
        prop = o.card.get_prop(propid)
        print("%-15s %d (%#x)" % (prop.name, propval, propval))

def set_prop(ob, prop, value):
    if ob.card.has_atomic:
        areq = pykms.AtomicReq(ob.card)
        areq.add(ob, prop, value)
        if areq.commit_sync() != 0:
            print("commit failed")
    else:
        if ob.set_prop_value(prop, value) != 0:
            print("setting property failed")

def set_props(ob, map):
    if ob.card.has_atomic:
        areq = pykms.AtomicReq(ob.card)

        for key, value in map.items():
            areq.add(ob, key, value)

        if areq.commit_sync() != 0:
            print("commit failed")
    else:
        for propid,propval in map.items():
            if ob.set_prop_value(propid, propval) != 0:
                print("setting property failed")

red = pykms.RGB(255, 0, 0)
green = pykms.RGB(0, 255, 0)
blue = pykms.RGB(0, 0, 255)
yellow = pykms.RGB(255, 255, 0)
purple = pykms.RGB(255, 0, 255)
white = pykms.RGB(255, 255, 255)
cyan = pykms.RGB(0, 255, 255)

def disable_planes(card):
    areq = pykms.AtomicReq(card)

    for p in card.planes:
        areq.add(p, "FB_ID", 0)
        areq.add(p, "CRTC_ID", 0)

    if areq.commit_sync() != 0:
        print("disabling planes failed")

def get_crtc_for_connector(conn):
    crtc = conn.get_current_crtc()

    if crtc != None:
        return crtc

    for crtc in conn.get_possible_crtcs():
        if crtc.mode_valid == False:
            return crtc

    raise RuntimeError("No free crtc found")