-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
1808 lines (1469 loc) · 56.9 KB
/
__init__.py
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding:utf-8 -*-
import os
import re
import time
from threading import Timer
from datetime import timedelta
from mathutils import Vector, Matrix
from mathutils.geometry import intersect_sphere_sphere_2d, intersect_point_line, intersect_line_line_2d
import math
import blf
import bgl
import bpy
import gpu
import bmesh
from gpu_extras.batch import batch_for_shader
import sys
from bpy_extras.io_utils import ImportHelper, ExportHelper
from bpy.types import (
Text,
Scene,
Panel,
Object,
Operator,
PropertyGroup,
AddonPreferences,
UIList,
)
from bpy.props import (
IntProperty,
BoolProperty,
EnumProperty,
FloatProperty,
StringProperty,
PointerProperty,
BoolVectorProperty,
CollectionProperty,
FloatVectorProperty
)
from bpy_extras.view3d_utils import (
region_2d_to_vector_3d,
region_2d_to_origin_3d
)
bl_info = {
"name": "nESP",
"description": "Control ESP Board via Micropython",
"author": "Manahter",
"version": (0, 1, 0),
"blender": (2, 91, 0),
"location": "View3D",
"category": "Generic",
"warning": "Under development. Nothing is guaranteed",
"doc_url": "",
"tracker_url": ""
}
from .utils.nodal import Nodal, register_modal, unregister_modal
from .modules.dirio import Dirio
from .modules.Tarag import tarag
from .modules.webrepl import Webrepl, WR_CMD, WR_KEY
from .modules.rapor import blender_plug
dev = None
# TODO!!! STA/AP modu açıp kapatma kısmını yap
# Serial iletişim kısmı da eklenebilir.
class NESP_PR_Connection(PropertyGroup):
def get_isscanning(self):
return tarag.inprocess
def set_isscanning(self, value):
if value:
tarag.scan()
isscanning: BoolProperty(
name="Is Scanning?",
get=get_isscanning,
set=set_isscanning
)
scantype: EnumProperty(
name="Scan Type",
items=[
("all", "All devices", ""),
("esp", "Only ESP", ""),
]
)
def get_isconnecting(self):
return (dev.isconnect == 0) if dev and dev.dr_isactive() else False
isconnecting: BoolProperty(
name="Is connecting",
default=False,
get=get_isconnecting
)
def set_isconnected(self, value):
bpy.ops.nesp.communication(action=("connect" if value else "disconnect"))
def get_isconnected(self):
return (dev.isconnect > 0) if dev and dev.dr_isactive() else False
isconnected: BoolProperty(
name="Is connected",
description="Is Connected ?",
default=False,
get=get_isconnected,
set=set_isconnected
)
def get_inwork(self):
return self.isconnected and (dev.dr_bind_count() > 0)
inwork: BoolProperty(
name="Is in work?",
get=get_inwork
)
def get_devices(self, context):
return [(i[0], i[0] + " {:1.13}".format(i[2]), i[1]) for i in tarag.devices(only_esp=self.scantype == "esp")]
device: EnumProperty(
name="Select Device",
description="Select the device you want to connect",
items=get_devices
)
port: StringProperty(
name="Port",
description="xxx.xxx.x.xx:8266",
default="8266",
# min=0
)
password: StringProperty(
name="Password",
description="Webrepl Password",
# subtype="PASSWORD"
)
controller: EnumProperty(
items=[("UPY", "MicroPython", "")],
name="Controller",
description="Under development...",
default="UPY"
)
@classmethod
def register(cls):
Scene.nesp_pr_connection = PointerProperty(
name="NESP_PR_Connection Name",
description="NESP_PR_Connection Description",
type=cls
)
@classmethod
def unregister(cls):
global dev
if dev:
dev.disconnect()
dev.dr_terminate()
tarag.inprocess = False
del Scene.nesp_pr_connection
class NESP_OT_Connection(Operator, Nodal):
bl_idname = "nesp.connection"
bl_label = "ESP Connection"
bl_description = "ESP Connect"
bl_options = {'REGISTER'}
action: EnumProperty(
items=[
("void", "Do nothing", ""),
("scan", "Scan Network for Devices", ""),
("connect", "Connect/Disconnect", ""),
("disconnect", "Disconnect", "")
]
)
dr = None
delay = 1
def invoke(self, context, event=None):
pr_con = context.scene.nesp_pr_connection
pr_dev = context.scene.nesp_pr_device
if self.action == "scan":
pr_con.isscanning = True
elif self.action == "connect" and pr_con.port.isdigit():
self.disconnect()
# Burası; zaten bağlıyız, disconnect yap ve dön demek oluyor
if pr_con.isconnected or pr_con.isconnecting:
return {"FINISHED"}
# Bağlanmayı dene
else:
ip = pr_con.device
global dev
dev = Dirio(target=Webrepl,
kwargs={"host": ip,
"port": int(pr_con.port),
"password": pr_con.password})
dev.start()
pr_dev.ip = pr_con.device
for i in tarag.devices():
if i[0] == ip:
pr_dev.ip = ip
pr_dev.mac = i[1]
pr_dev.vendor = i[2]
context.window_manager.modal_handler_add(self)
self._last_time = time.time()
return self.timer_add(context)
elif self.action == "disconnect":
self.disconnect()
return {"FINISHED"}
def n_modal(self, context, event):
if self.action == "connect":
return self.modal_connect(context)
return {'PASS_THROUGH'}
def modal_connect(self, context):
global dev
if not dev:
return self.timer_remove(context)
# Bağlanamadı
if dev.isconnect < 0:
self.disconnect()
return self.timer_remove(context)
# Bağlandı
if dev.isconnect > 0:
bpy.ops.nesp.communication(start=True)
return self.timer_remove(context)
return {'PASS_THROUGH'}
def disconnect(self):
bpy.ops.nesp.communication(start=False)
global dev
if dev:
try:
dev.disconnect()
dev.dr_terminate()
except Exception:
...
dev = None
class NESP_PT_Connection(Panel):
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "nESP"
bl_label = "Connection"
bl_idname = "NESP_PT_connection"
# @classmethod
# def poll(__cls__, context):
# return context.scene.nesp_pr_head.tool_scene
def draw(self, context):
pr = context.scene.nesp_pr_connection
row = self.layout.row(align=True)
col1 = row.column()
col1.alignment = "RIGHT"
col1.label(text="Control")
col1.label(text="Device")
col1.label(text="Port")
col1.label(text="Key")
col1.scale_x = .8
col2 = row.column(align=False)
col2.prop(pr, "controller", text="")
row = col2.row(align=True)
row.prop(pr, "device", text="")
row.prop(pr, "isscanning", text="", icon="VIEWZOOM")
row.enabled = not pr.isscanning
col2.prop(pr, "port", text="")
col2.prop(pr, "password", text="")
conn = pr.isconnected
row = self.layout.row()
if conn:
row.operator(
"nesp.connection",
text="Connected",
icon="LINKED",
depress=True
).action = "disconnect"
elif pr.isconnecting:
row.alert = True
row.operator(
"nesp.connection",
text="Connecting",
icon="ANIM"
).action = "disconnect"
else:
row.operator(
"nesp.connection",
text="Connect",
icon="UNLINKED",
).action = "connect"
def draw_header_preset(self, context):
pr = context.scene.nesp_pr_connection
if not pr.isconnected:
icon = "UNLINKED"
elif pr.inwork:
icon = "TIME"#"PROP_ON"
else:
icon = "MESH_CIRCLE"#"PROP_OFF"
self.layout.prop(pr, "inwork",
icon_only=True,
emboss=False,
icon=icon)
#icon=("OUTLINER_OB_FORCE_FIELD" if pr.inwork else "PROP_OFF"))
# ##########################################################
# ##########################################################
class NESP_PR_MessageItem(PropertyGroup):
ingoing: BoolProperty(
name="Ingoing?",
description="Message is Ingoing / Outgoing"
)
message: StringProperty(
name="Messsage?",
description="Message"
)
# time = time.time()
# incoming = StringProperty(name="Incoming", default="")
@classmethod
def register(cls):
Scene.nesp_pr_messageitem = PointerProperty(
name="NESP_PR_MessageItem Name",
description="NESP_PR_MessageItem Description",
type=cls)
@classmethod
def unregister(cls):
del Scene.nesp_pr_messageitem
class NESP_UL_Messages(UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
row = layout.row()
if item.message.startswith("Traceback (most recent call last):"):
icon = "FUND" # "FUND" or "COLORSET_01_VEC"
elif item.ingoing:
icon = "BLANK1"
else:
icon = "RIGHTARROW_THIN"
row.prop(item, "message",
text="", # time.strftime(item.time),
icon=icon, # "BLANK1" "NONE"
emboss=False)
if not item.ingoing and item == data.items[data.active_item_index]:
row.operator("nesp.messages", emboss=False, text="", icon="LOOP_BACK").msg = item.message
pass
# COPYDOWN
# LOOP_BACK
class NESP_OT_Messages(Operator):
bl_idname = "nesp.messages"
bl_label = "Messages Operator"
bl_description = "Clear Messages in the ListBox"
bl_options = {'REGISTER'}
action: EnumProperty(
items=[
("add", "Add to message", ""),
("remove", "Remove to message", ""),
("clear", "Clear all messages", ""),
("clearqueu", "Clear Queu", "")
]
)
msg: StringProperty()
def execute(self, context):
pr_com = context.scene.nesp_pr_communication
if self.action == "add":
print("Developing ...")
elif self.action == "remove":
print("Developing ...")
pr_com.items.remove(pr_com.active_item_index)
elif self.action == "clear":
pr_com.items.clear()
pr_com.active_item_index = 0
if self.msg:
pr_com.messaging = self.msg
return {'FINISHED'}
class NESP_PR_Communication(PropertyGroup):
items: CollectionProperty(
type=NESP_PR_MessageItem,
name="Messages",
description="All Message Items Collection"
)
active_item_index: IntProperty(
name="Active Item",
default=-1,
description="Selected message index in Collection"
)
############################################################
# #################################################### QUEUE
# Mesaj Kuyruğu
queue_list = []
queue_hist = []
############################################################
# ################################################ MESSAGING
def append_outgoing(self, context):
if not self.messaging or not context.scene.nesp_pr_connection.isconnected:
return
#self.send(context, self.messaging)
# Mesajı gönderilenler kuyruğuna ekle
message = self.messaging
self.queue_list.append(message)
pr_com = context.scene.nesp_pr_communication
# Mesajı Communication panele ekle
item = pr_com.items.add()
item.ingoing = False
item.message = message
pr_com.active_item_index = len(pr_com.items) - 1
self.messaging = ""
messaging: StringProperty(name="Outgoing Message",
update=append_outgoing)
# ##########################################################
# ########################################## WebRepl Methods
def append_incoming(self, message):
# Gelen cevapları panele ekle. Hepsini değil tabi ki
for i in message.strip().split("\n"):
c = i.strip()
if not c:
continue
item = self.items.add()
item.ingoing = True
item.message = c
self.active_item_index = len(self.items) - 1
@classmethod
def register(cls):
Scene.nesp_pr_communication = PointerProperty(
name="NESP_PR_Communication Name",
description="NESP_PR_Communication Description",
type=cls)
@classmethod
def unregister(cls):
del Scene.nesp_pr_communication
class NESP_OT_Communication(Operator, Nodal):
bl_idname = "nesp.communication"
bl_label = "Communication"
bl_description = "Communication Description"
bl_options = {'REGISTER'}
pr_con = None
pr_com = None
pr_dev = None
pr_fsy = None
pr_pin = None
delay = 0
def n_invoke(self, context, event):
dev.listen()
self.pr_con = context.scene.nesp_pr_connection
self.pr_com = context.scene.nesp_pr_communication
self.pr_dev = context.scene.nesp_pr_device
self.pr_fsy = context.scene.nesp_pr_filesystem
self.pr_pin = context.scene.nesp_pr_pins
self.pr_pin.items.clear()
# platformu öğren
bpy.ops.nesp.commands(command=WR_CMD.PLATFORM)
# Dosyalarını öğren
bpy.ops.nesp.filesystem()
# Pin durumlarını oku
bpy.ops.nesp.pins(action="reload")
# boot dosyasını oku.
Timer(1, lambda: self.pr_com.queue_list.append((WR_KEY._FILE_READ, WR_CMD.BOOT_FILE))).start()
return self.timer_add(context)
mode = ""
file = ""
wait = 0
def n_modal(self, context, event):
if not self.pr_con.isconnected:
unregister_modal(self)
return self.timer_remove(context)
if not self.pr_con.isconnected:
return {"CANCELLED"}
if self.pr_com.queue_list:
val = self.pr_com.queue_list.pop(0)
if type(val) in (tuple, list):
if val[0] == WR_KEY._FILE_WRITE:
dev.put_file_content(val[1], val[2])
elif val[0] == WR_KEY._FILE_READ:
dev.get_file_content(val[1])
else:
dev.send(val)
self.pr_com.queue_hist.append(val)
# Son gönderilenler yankı olarak geldiğinde boşuna ekrana eklemeleyim diye
if len(self.pr_com.queue_hist) > 20:
self.pr_com.queue_hist = self.pr_com.queue_hist[10:]
return {'PASS_THROUGH'}
# a = dev.receives
a = dev.receives.copy()
dev.receives.clear()
if a and len(a):
cmds = WR_CMD.all()
for i in a:
if i in cmds or i in self.pr_com.queue_hist:
continue
pr_dev = self.pr_dev
if i.startswith(WR_KEY._OS_INFO):
# OSI: (sysname='esp8266', nodename='esp8266', release='2.0.0(5a875ba)',
# version='v1.13 on 2020-09-02', machine='ESP module (1M) with ESP8266')
ans = i.replace(WR_KEY._OS_INFO, "", 1).strip("() \t\r\n")
res = {}
for c in ans.split(","):
key, val = c.split("=", 1)
res[key.strip()] = val.strip("'")
pr_dev.machine = res.get("machine", "")
pr_dev.platform = res.get("sysname", "")
pr_dev.micropy_version = res.get("version", "")
pr_dev.release = res.get("release", "")
elif i.startswith(WR_KEY._PLATFORM):
# PLT: esp8266
pr_dev.platform = i.replace(WR_KEY._PLATFORM, "", 1).strip()
elif i.startswith(WR_KEY._MEMORY):
# GC: total: WR_KEY, used: 3152, free: 34800
ans = i.replace(WR_KEY._MEMORY, "", 1).strip()
nums = re.findall(r'\d+', ans)
if len(nums) > 2:
pr_dev.memory = f"%{(int(nums[1]) * 100) // int(nums[0])}"
elif i.startswith(WR_KEY._PIN):
# PIN: 0 0
# PinNo PinValue
ans = i.replace(WR_KEY._PIN, "", 1).strip().split(maxsplit=3)
if len(ans) == 4:
no = int(ans[0])
value = bool(int(ans[1]))
io = str(ans[2])
name = str(ans[3])
data = self.pr_pin
isok = False
# Item'lerde varsa güncelle.
for p in data.items:
if p.no == no:
p.io = io
p.name = name
p.value = value
isok = True
# Itemlerde yoksa, yeni oluştur.
if not isok:
item = data.items.add()
item.no = no
item.io = io
item.name = name
item.value = value
data.active_item_index = len(data.items) - 1
elif i.startswith(WR_KEY._SIGNAL):
# SIG: -72
# https://hackster.imgix.net/uploads/attachments/1004079/frsy0u3k10zeout_large_zLKM8zCIqi.jpg?auto=compress%2Cformat&w=740&h=555&fit=max
ans = i.replace(WR_KEY._SIGNAL, "", 1).strip()
pr_dev.wifi_strength = f"%{100 + ((40 + int(ans)) * 2)}" if ans.replace("-", "").isdigit() else ans
elif i.startswith(WR_KEY._FREQUENCE):
# FRQ: 80000000
ans = i.replace(WR_KEY._FREQUENCE, "", 1).strip()
pr_dev.frequence = f"{int(ans) / 1000000}MHz" if ans.isdigit() else ans
elif i.startswith(WR_KEY._FLASH_SIZE):
# FLS: 1048576
ans = i.replace(WR_KEY._FLASH_SIZE, "", 1).strip()
pr_dev.flash_size = f"{int(ans) / 1048576}Mb" if ans.isdigit() else ans
elif i.startswith(WR_KEY._LISTDIR):
# LDR: [('ay.py', 32768, 0, 18), ('boot.py', 32768, 0, 175), ('webrepl_cfg.py', 32768, 0, 16)]
ans = i.replace(WR_KEY._LISTDIR, "", 1).strip()
try:
res = eval(ans)
except:
res = []
pr_fsy = self.pr_fsy
pr_fsy.items.clear()
aii = pr_fsy.active_item_index
pr_fsy.active_item_index = 0
path = pr_fsy.path
for r in res:
item = pr_fsy.items.add()
item.name = r[0]
item.isdir = r[1] == 16384
item.path = os.path.join(path, r[0])
item.ismaking = False
if len(pr_fsy.items) > aii:
pr_fsy.active_item_index = aii
elif i.startswith(WR_KEY._DIR):
# DIR: (True, ['__class__', 'from_bytes', 'to_bytes'], '2')
ans = i.replace(WR_KEY._DIR, "", 1).strip()
try:
res = eval(ans)
except:
res = (False, [], "")
pr_fsy = self.pr_fsy
pr_fsy.items.clear()
pr_fsy.active_item_index = 0
# if isval
if res[0]:
item = pr_fsy.items.add()
item.isval = True
item.isdir = False
item.name = res[2]
else:
for r in res[1]:
if r == "__class__":
continue
item = pr_fsy.items.add()
item.isval = False
item.isdir = True
item.name = r
elif i.startswith(WR_KEY._MODULES):
# <MDL:
# ...
# MDL>
self.pr_fsy.items.clear()
self.mode = "module"
self.wait = time.time()
elif i.startswith(WR_KEY.MODULES_):
# <MDL:
# ...
# MDL>
if self.mode == "module":
self.mode = ""
elif i.startswith(WR_KEY._FILE_READ):
# FRD: filename.py
ans, data = i.split("\n", 1)
file_name = ans.replace(WR_KEY._FILE_READ, "", 1).strip()
if file_name in bpy.data.texts:
file = bpy.data.texts[file_name]
file.clear()
else:
file = bpy.data.texts.new(file_name)
file.write(data)
for area in context.screen.areas:
if area.type == "TEXT_EDITOR":
area.spaces[0].text = file
elif self.mode == "module":
if i.startswith("Plus any mod"):
continue
if time.time() - self.wait > 3:
self.mode = ""
ans = i.strip().split()
pr_fsy = self.pr_fsy
pr_fsy.active_item_index = 0
for r in ans:
item = pr_fsy.items.add()
item.isdir = False
item.name = r
elif i.startswith(WR_KEY._RELOAD_DIR_):
bpy.ops.nesp.filesystem(action="reload")
else:
self.pr_com.append_incoming(i)
if context.area:
context.area.tag_redraw()
# a = dev.receives
# if a:
# a.clear()
# dev'in bir değişkeninde WebRepl ile alınan cevaplar depolanıyor olacak.
# Oradaki cevapları alıyoruz okuyoruz.
# Eğer değişmesi gereken değişken varsa oraya aktarıyoruz.
# Değişmesi gereken birşey yoksa, doğrudan Comm panele ekliyoruz
# Eğer bir fonksiyon çalışırsa, alanları yenile
# if dev.dr_binds_check():
# if context.area:
# context.area.tag_redraw()
return {'PASS_THROUGH'}
class NESP_PT_Communication(Panel):
bl_idname = "NESP_PT_communication"
bl_label = "Communication"
bl_region_type = "UI"
bl_space_type = "VIEW_3D"
bl_category = "nESP"
# bl_options = {"DEFAULT_CLOSED", "HIDE_HEADER"}
# @classmethod
# def poll(__cls__, context):
# return context.scene.nesp_pr_connection.isconnected
def draw(self, context):
layout = self.layout
layout.enabled = context.scene.nesp_pr_connection.isconnected
pr = context.scene.nesp_pr_communication
row = layout.row(align=True)
row.operator("nesp.commands", text="Raw").command = WR_CMD.CONTROL_A
row.operator("nesp.commands", text="Normal").command = WR_CMD.CONTROL_B
row.operator("nesp.commands", text="Interrupt").command = WR_CMD.CONTROL_C
row.operator("nesp.commands", text="Reset").command = WR_CMD.CONTROL_D
col = layout.column(align=True)
col.template_list(
"NESP_UL_Messages", # TYPE
"nesp_ul_messages", # ID
pr, # Data Pointer
"items", # Propname
pr, # active_dataptr
"active_item_index", # active_propname
rows=3,
type='DEFAULT'
)
row = col.row(align=True)
# if not context.scene.nesp_pr_connection.isconnected:
# row.enabled = False
# row.alert = True
row.prop(pr, "messaging", text="", full_event=False)
row.operator("nesp.messages", text="", icon="TRASH", ).action = "clear"
class NESP_OT_Commands(Operator):
bl_idname = "nesp.commands"
bl_label = "nESP Commands"
bl_description = ""
bl_options = {'REGISTER'}
command: StringProperty()
def execute(self, context):
pr_com = context.scene.nesp_pr_communication
if self.command == "get_infos":
pr_com.queue_list.extend([WR_CMD.SIGNAL,
WR_CMD.MEMORY,
WR_CMD.OS_INFO,
WR_CMD.FREQUENCE,
WR_CMD.FLASH_SIZE,
])
elif self.command == "get_status":
pr_com.queue_list.extend([WR_CMD.MEMORY, WR_CMD.SIGNAL])
elif self.command == WR_CMD.MEMORY_OPTIMIZE:
pr_com.queue_list.append(WR_CMD.MEMORY_OPTIMIZE)
pr_com.queue_list.append(WR_CMD.MEMORY)
else:
pr_com.queue_list.append(self.command)
return {'FINISHED'}
class NESP_PR_Device(PropertyGroup):
ip: StringProperty(name="IP Address")
mac: StringProperty(name="MAC Address")
vendor: StringProperty(name="Vendor Name")
machine: StringProperty(name="Machine")
platform: StringProperty(name="Platform")
release: StringProperty(name="Release")
micropy_version: StringProperty(name="MicroPy Version")
memory: StringProperty(name="Used Memory")
frequence: StringProperty(name="Frequence")
flash_size: StringProperty(name="Flash Size")
wifi_strength: StringProperty(name="Wifi Signal Quality")
@classmethod
def register(cls):
Scene.nesp_pr_device = PointerProperty(
name="NESP_PT_Device Name",
description="NESP_PT_Device Description",
type=cls
)
@classmethod
def unregister(cls):
del Scene.nesp_pr_device
class NESP_PT_Device(Panel):
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "nESP"
bl_label = "Device"
bl_idname = "NESP_PT_device"
def draw(self, context):
pr = context.scene.nesp_pr_device
self.layout.enabled = context.scene.nesp_pr_connection.isconnected
row = self.layout.row(align=True)
col1 = row.column()
col1.alignment = "RIGHT"
col1.label(text="IP", icon="MOD_PARTICLES")
col1.label(text="MAC", icon="RNA")
col1.label(text="Vendor", icon="MOD_BUILD")
col2 = row.column()
col2.label(text=pr.ip)
col2.label(text=pr.mac)
col2.label(text=pr.vendor)
class NESP_PT_DeviceDetails(Panel):
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "nESP"
bl_label = "Details"
bl_parent_id = "NESP_PT_device"
bl_options = {'DEFAULT_CLOSED'}
def draw(self, context):
pr = context.scene.nesp_pr_device
layout = self.layout
layout.enabled = context.scene.nesp_pr_connection.isconnected
row = layout.row(align=True)
row.operator("nesp.commands", text="Get Device Info", icon="WORDWRAP_ON").command = "get_infos"
row = layout.row(align=True)
col1 = row.column()
col1.alignment = "RIGHT"
col1.label(text="Machine", icon="FILE_ARCHIVE") # NODE_SEL PACKAGE SYSTEM
col1.label(text="Platform", icon="DESKTOP") # NODE UGLYPACKAGE DESKTOP PARTICLE_DATA
col1.label(text="MicroPy", icon="SCRIPT") # SCRIPT
col1.label(text="Release", icon="PACKAGE") # FILE_TEXT LINENUMBERS_ON WORDWRAP_ON
col1.label(text="Flash Size", icon="DISK_DRIVE") # DISK_DRIVE EXTERNAL_DRIVE
col1.label(text="Frequence", icon="FORCE_HARMONIC") # SEQ_HISTOGRAM RIGID_BODY FORCE_HARMONIC
col2 = row.column()
col2.label(text=pr.machine)
col2.label(text=pr.platform)
col2.label(text=pr.micropy_version)
col2.label(text=pr.release)
col2.label(text=pr.flash_size)
col2.label(text=pr.frequence)
class NESP_PT_DeviceStatus(Panel):
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "nESP"
bl_label = "Status"
bl_parent_id = "NESP_PT_device"
bl_options = {'DEFAULT_CLOSED'}
def draw(self, context):
pr = context.scene.nesp_pr_device
layout = self.layout
layout.enabled = context.scene.nesp_pr_connection.isconnected
row = layout.row(align=True)
row.operator("nesp.commands", text="Get Status Info", icon="STATUSBAR").command = "get_status"
row = layout.row(align=True)
col1 = row.column()
col1.alignment = "RIGHT"
col1.label(text="Memory", icon="MEMORY")
col1.label(text="Signal", icon="MOD_WAVE")
col2 = row.column()
col2.alignment = "RIGHT"
row2 = col2.row(align=True)
row2.label(text=pr.memory)
row2.operator("nesp.commands", text="", emboss=False, icon="BRUSH_DATA").command = WR_CMD.MEMORY_OPTIMIZE
row2.operator("nesp.commands", text="", emboss=False, icon="FILE_REFRESH").command = WR_CMD.MEMORY
row3 = col2.row(align=True)
row3.label(text=pr.wifi_strength)
row3.operator("nesp.commands", text="", emboss=False, icon="FILE_REFRESH").command = WR_CMD.SIGNAL
col2.scale_x = 1.2
# ##########################################################
# ##########################################################
class NESP_UL_FileSystems(UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
row = layout.row(align=True)
if item.isval:
icon = "DISK_DRIVE"
elif item.isdir:
icon = "FILEBROWSER"
elif item.name.endswith(".py"):
icon = "FILE_SCRIPT" # "SCRIPTPLUGINS" # "FUND" or "COLORSET_01_VEC"
else:
icon = "BLANK1"
row.prop(item, "name",
text="",
icon=icon,
emboss=False)
# Eğer bu item seçiliyse;
if item == data.items[data.active_item_index]:
# print("context", context)
# print("layout", layout)
# print("data", data)
# print("item", item)
# print("icon", icon)
# print("active_data", active_data)
# print("active_propname", active_propname)
# print("", dir(data.items))
# print("", )
# print("", )
pr = context.scene.nesp_pr_filesystem