Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erbui manufacturer control args #655

Merged
merged 5 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions build-system/erbui/analysers/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ def make_manufacturer_data (self, manufacturer):
for generator in manufacturer.generators:

def visit (item):
if isinstance (item, ast.GeneratorArgString):
if isinstance (item, ast.ArgString):
return { item.name: item.value }
elif isinstance (item, ast.GeneratorArgDict):
elif isinstance (item, ast.ArgDict):
sub_args = {}
for sub_item in item.items:
sub_args.update (visit (sub_item))
Expand All @@ -156,9 +156,9 @@ def visit (item):
gen = {'id': generator.name, 'args': {}}

for arg in generator.args:
if isinstance (arg, ast.GeneratorArgString):
if isinstance (arg, ast.ArgString):
gen ['args'].update (visit (arg))
elif isinstance (arg, ast.GeneratorArgDict):
elif isinstance (arg, ast.ArgDict):
gen ['args'].update (visit (arg))

manufacturer_data ['generators'].append (gen)
Expand All @@ -185,7 +185,7 @@ def visit (item):
for control in manufacturer.controls:
for kind in control.kinds:
manufacturer_data ['controls'][kind].append (
{'styles': control.style, 'parts': control.parts, 'class': control.class_}
{'styles': control.style, 'parts': control.parts, 'class': control.class_, 'args': control.args_as_dict}
)

return manufacturer_data
Expand Down Expand Up @@ -235,6 +235,7 @@ def analyse_control (self, module, control, manufacturer_style_set):
raise error.incompatible_style (keyword, cur_styles_parts ['styles'])

control.simulator_class = cur_styles_parts ['class']
control.args = cur_styles_parts ['args']

component_list = cur_styles_parts ['parts']

Expand Down
31 changes: 17 additions & 14 deletions build-system/erbui/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,13 @@ def is_manufacturer (self): return isinstance (self, Manufacturer)
def is_generator (self): return isinstance (self, Generator)

@property
def is_generator_arg_string (self): return isinstance (self, GeneratorArgString)
def is_arg_string (self): return isinstance (self, ArgString)

@property
def is_generator_arg_dict (self): return isinstance (self, GeneratorArgDict)
def is_arg_dict (self): return isinstance (self, ArgDict)

@property
def is_generator_arg_dict_item (self): return isinstance (self, GeneratorArgDictItem)

@property
def is_generator_arg (self): return self.is_generator_arg_string or self.is_generator_arg_dict
def is_arg (self): return self.is_arg_string or self.is_arg_dict

@property
def is_manufacturer_control (self): return isinstance (self, ManufacturerControl)
Expand Down Expand Up @@ -1494,6 +1491,7 @@ def __init__ (self, identifier_name, keyword_kind):
self.keyword_kind = keyword_kind
self.parts = []
self.simulator_class = None
self.args = {}

@staticmethod
def typename (): return 'control'
Expand Down Expand Up @@ -2213,17 +2211,17 @@ def name (self): return self.name_string_literal.value

@property
def args (self):
entities = [e for e in self.entities if e.is_generator_arg]
entities = [e for e in self.entities if e.is_arg]
return entities


# -- GeneratorArgString ------------------------------------------------------
# -- ArgString ---------------------------------------------------------------

class GeneratorArgString (Scope):
class ArgString (Scope):
def __init__ (self, identifier, value_string_literal):
assert isinstance (identifier, adapter.Identifier)
assert isinstance (value_string_literal, StringLiteral)
super (GeneratorArgString, self).__init__ ()
super (ArgString, self).__init__ ()
self.identifier = identifier
self.value_string_literal = value_string_literal

Expand All @@ -2235,20 +2233,20 @@ def value (self):
return self.value_string_literal.value.replace ('\\n', '\n').replace ('\\t', '\t').replace ('\\"', '"')


# -- GeneratorArgDict --------------------------------------------------------
# -- ArgDict -----------------------------------------------------------------

class GeneratorArgDict (Scope):
class ArgDict (Scope):
def __init__ (self, identifier):
assert isinstance (identifier, adapter.Identifier)
super (GeneratorArgDict, self).__init__ ()
super (ArgDict, self).__init__ ()
self.identifier = identifier

@property
def name (self): return self.identifier.name

@property
def items (self):
entities = [e for e in self.entities if e.is_generator_arg]
entities = [e for e in self.entities if e.is_arg]
return entities


Expand Down Expand Up @@ -2283,6 +2281,11 @@ def class_ (self):
assert len (entities) == 1
return entities [0].name

@property
def args_as_dict (self):
dict = {e.name: e.value for e in self.entities if e.is_arg}
return dict


# -- ManufacturerControlParts ------------------------------------------------

Expand Down
4 changes: 4 additions & 0 deletions build-system/erbui/generators/front_pcb/DiyManual.erbui
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ manufacturer DiyManual {
style eastrising, 128x64
parts er.display.spi.128x64.manual
class "erb::OledModule <erb::Panel_ER_OLEDM015_2>"
arg display_width "128"
arg display_height "64"
}

control Encoder {
Expand Down Expand Up @@ -218,12 +220,14 @@ manufacturer DiyManual {
style dailywell.2ms1, on_on
parts dailywell.2ms1.manual
class "erb::Dailywell2Ms1"
arg nbr_positions "2"
}

control Switch {
style dailywell.2ms3, on_off_on
parts dailywell.2ms3.manual
class "erb::Dailywell2Ms3"
arg nbr_positions "3"
}

control Trim {
Expand Down
2 changes: 2 additions & 0 deletions build-system/erbui/generators/front_pcb/DiyWire.erbui
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,14 @@ manufacturer DiyWire {
style dailywell.2ms1, on_on
parts dailywell.2ms1.wire
class "erb::Dailywell2Ms1"
arg nbr_positions "2"
}

control Switch {
style dailywell.2ms3, on_off_on
parts dailywell.2ms3.wire
class "erb::Dailywell2Ms3"
arg nbr_positions "3"
}

control Trim {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@
(property "DistLink" "https://www.thonk.co.uk/shop/sub-mini-toggle-switches/" (id 9) (at 127 119.38 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "NbrPositions" "2" (id 11) (at 127 119.38 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid b4295a62-b9f7-4f0d-83cb-4790abcc0857))
(pin "2" (uuid 50aeb459-e2ba-452f-93c5-65ef10a8d7b6))
(pin "3" (uuid b7aa1b06-152a-4878-bd26-91c5e59b3a34))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,6 @@
(property "DistLink" "https://www.thonk.co.uk/shop/sub-mini-toggle-switches/" (id 9) (at 127 119.38 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "NbrPositions" "2" (id 11) (at 127 119.38 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid 875cd3c3-a97a-481e-8bb6-bd309e52b909))
(pin "2" (uuid 7e5425fb-b48d-42b1-98bd-dc8ebf3eb1f1))
(pin "3" (uuid dc424554-59a0-4ae1-843b-d2f0a111930f))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@
(property "DistLink" "https://www.thonk.co.uk/shop/sub-mini-toggle-switches/" (id 9) (at 127 119.38 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "NbrPositions" "3" (id 11) (at 127 119.38 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid 9fd2ab52-6399-4c17-b710-4552376670d7))
(pin "2" (uuid 78ba91bd-fd2a-43bc-84c7-9e28a82b1022))
(pin "3" (uuid 3fd92f68-aaf6-4ffd-96fc-a35780a18f20))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,6 @@
(property "DistLink" "https://www.thonk.co.uk/shop/sub-mini-toggle-switches/" (id 9) (at 127 119.38 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "NbrPositions" "3" (id 11) (at 127 119.38 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid 10ec960f-b937-484a-8f81-3bc432a8d4bf))
(pin "2" (uuid 5c6aac44-ef3e-4319-9b14-30e247e21706))
(pin "3" (uuid 10845218-2387-46fb-9972-3a98af9fc84b))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,6 @@
(property "IPN" "1.5 Display Module PTH" (id 12) (at 128.27 97.79 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "DisplayWidth" "128" (id 13) (at 128.27 97.79 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "DisplayHeight" "64" (id 14) (at 128.27 97.79 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid 46162a1f-4f1a-4174-99dd-71c1d88051e4))
(pin "2" (uuid 9790c520-7466-40b0-b06b-8d4910858173))
(pin "3" (uuid bcd58b7f-1d1d-4863-958c-c25fcb6a84ef))
Expand Down
29 changes: 2 additions & 27 deletions build-system/erbui/generators/ui/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ def generate_control (self, module, control):
control_type = '%s <erb::PinType::Dac>' % control.kind

elif control.kind in ['Switch']:
nbr_positions = self.get_nbr_positions (control)
nbr_positions = control.args ['nbr_positions']
control_type = '%s <%s>' % (control.kind, nbr_positions)

elif control.kind in ['Display']:
display_size = self.get_display_size (control)
display_size = (control.args ['display_width'], control.args ['display_height'])
control_type = '%s <%s>' % (
control.kind,
'erb::FormatSsd130x <%s, %s>' % display_size
Expand All @@ -147,31 +147,6 @@ def generate_control (self, module, control):
return source_code


#--------------------------------------------------------------------------

def get_nbr_positions (self, control):
for part in control.parts:
for symbol in part.sch.symbols:
nbr_positions_field = symbol.property ('NbrPositions')
if nbr_positions_field is not None:
return nbr_positions_field

assert False


#--------------------------------------------------------------------------

def get_display_size (self, control):
for part in control.parts:
for symbol in part.sch.symbols:
display_width_field = symbol.property ('DisplayWidth')
display_height_field = symbol.property ('DisplayHeight')
if display_width_field is not None:
return (display_width_field, display_height_field)

assert False


#--------------------------------------------------------------------------

def generate_alias (self, alias):
Expand Down
16 changes: 8 additions & 8 deletions build-system/erbui/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,15 @@ def global_namespace_declaration (): return Optional (import_declaration), mod

GRAMMAR_ROOT = global_namespace_declaration

# Generator Arg
def generator_arg_name (): return name
def generator_arg_string (): return 'arg', generator_arg_name, string_literal
def generator_arg_dict_entities (): return ZeroOrMore ([generator_arg_string, generator_arg_dict])
def generator_arg_dict (): return 'arg', generator_arg_name, '{', generator_arg_dict_entities, '}'
def generator_arg_declaration (): return [generator_arg_string, generator_arg_dict]
# Arg
def arg_name (): return name
def arg_string (): return 'arg', arg_name, string_literal
def arg_dict_entities (): return ZeroOrMore ([arg_string, arg_dict])
def arg_dict (): return 'arg', arg_name, '{', arg_dict_entities, '}'
def arg_declaration (): return [arg_string, arg_dict]

# Generator
def generator_entities (): return ZeroOrMore ([generator_arg_declaration])
def generator_entities (): return ZeroOrMore ([arg_declaration])
def generator_body (): return '{', generator_entities, '}'
def generator_name (): return string_literal
def generator_declaration (): return 'generator', generator_name, Optional (generator_body)
Expand All @@ -249,7 +249,7 @@ def generator_declaration (): return 'generator', generator_name, Optio
def manufacturer_control_class (): return 'class', string_literal
def manufacturer_control_part_name (): return _(r'(?!\b({})\b)((\w|\.)*)')
def manufacturer_control_parts (): return 'parts', manufacturer_control_part_name, ZeroOrMore (',', manufacturer_control_part_name)
def manufacturer_control_entities (): return style_declaration, manufacturer_control_parts, manufacturer_control_class
def manufacturer_control_entities (): return style_declaration, manufacturer_control_parts, manufacturer_control_class, ZeroOrMore ([arg_declaration])
def manufacturer_control_body (): return '{', manufacturer_control_entities, '}'
def manufacturer_control_kind (): return list (CONTROL_KINDS)
def manufacturer_control_kinds (): return manufacturer_control_kind, ZeroOrMore (',', manufacturer_control_kind)
Expand Down
28 changes: 14 additions & 14 deletions build-system/erbui/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,28 +814,28 @@ def visit_generator_entities (self, node, children):
return list (children)


#-- Generator Arg ---------------------------------------------------------
#-- Arg -------------------------------------------------------------------

def visit_generator_arg_declaration (self, node, children):
def visit_arg_declaration (self, node, children):
return children [0] if children else []

def visit_generator_arg_name (self, node, children):
def visit_arg_name (self, node, children):
return self.visit_identifier (node, children)

def visit_generator_arg_string (self, node, children):
generator_arg_identifier = children.generator_arg_name [0]
def visit_arg_string (self, node, children):
arg_identifier = children.arg_name [0]
value_string_literal = children.string_literal [0]
return ast.GeneratorArgString (generator_arg_identifier, value_string_literal)
return ast.ArgString (arg_identifier, value_string_literal)

def visit_generator_arg_dict (self, node, children):
generator_arg_identifier = children.generator_arg_name [0]
generator_arg = ast.GeneratorArgDict (generator_arg_identifier)
if children.generator_arg_dict_entities:
entities = children.generator_arg_dict_entities [0]
generator_arg.add (entities)
return generator_arg
def visit_arg_dict (self, node, children):
arg_identifier = children.arg_name [0]
arg = ast.ArgDict (arg_identifier)
if children.arg_dict_entities:
entities = children.arg_dict_entities [0]
arg.add (entities)
return arg

def visit_generator_arg_dict_entities (self, node, children):
def visit_arg_dict_entities (self, node, children):
return list (children)


Expand Down
Loading