Skip to content
This repository was archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #106 from Panduza/105-add-laser-functions
Browse files Browse the repository at this point in the history
105 add laser functions
  • Loading branch information
Darcraytore1 authored Jul 17, 2024
2 parents 8b787c8 + a5202bd commit 95101fb
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 6 deletions.
6 changes: 4 additions & 2 deletions panduza/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __init__(self, broker_alias=None, interface_alias=None, url=None, port=None,
self.log.info("Init Client")

# Init MQTT client instance
self.client = mqtt.Client()
self.client = mqtt.Client(protocol=mqtt.MQTTv311, clean_session=True)
self.client.on_message = self.__on_message
self.client.on_connect = self.__on_connect
self.client.on_disconnect = self.__on_disconnect
Expand All @@ -110,7 +110,9 @@ def __init__(self, broker_alias=None, interface_alias=None, url=None, port=None,

def connect(self):
self.log.debug("Connect to broker {self.url}:" + str(self.port))
self.client.connect(self.url, self.port)
print("Try to connect")
self.client.connect(self.url, self.port, keepalive=10)
print("success to connect")
self.client.loop_start()

def disconnect(self):
Expand Down
78 changes: 74 additions & 4 deletions panduza/interfaces/blc.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ def __post_init__(self):
RwField( name_ = "value" )
)

# === ANALOG MODULATION ===
self.add_attribute(
Attribute( name_= "analog_modulation")
).add_field(
RwField( name_= "value")
)


# === POWER ===
self.add_attribute(
Attribute( name_ = "power" )
Expand Down Expand Up @@ -69,6 +77,9 @@ def __post_init__(self):
def toggle(self):
pass

############################################################
######################### ENABLE ###########################
############################################################

# Enable value need to be true or false to actually do something
def turn_on(self):
Expand All @@ -80,26 +91,85 @@ def turn_off(self):
def is_on(self):
return self.enable.value.get()

############################################################
#################### ANALOG MODULATION #####################
############################################################

# Enable value need to be true or false to actually do something
def enable_analog_modulation(self):
self.analog_modulation.value.set(True)

def disable_analog_modulation(self):
self.analog_modulation.value.set(False)

def get_analog_modulation(self):
return self.analog_modulation.value.get()

############################################################
########################## MODE ############################
############################################################

# Change mode at power or current
def set_mode_constant_power(self):
self.mode.value.set("constant_power")

def set_mode_constant_current(self):
self.mode.value.set("constant_current")

def get_mode(self):
self.mode.value.get()

############################################################
########################## POWER ###########################
############################################################


# Set power value directly with value
def set_power_value(self, value):
def set_power(self, value):
self.power.value.set(value)

# Set power value with percentage (0% to 100%)
def set_power_with_percentage(self, percentage):
value_with_percentage = (1/100) * percentage * self.power.max.get()

# I need to round the value because else the precision of the
# double could cause problem with too much decimals
decimals_value = self.power.decimals.get()

# Value given in mW
value_with_percentage = round((1/100) * percentage * self.power.max.get(), int(decimals_value))
self.power.value.set(value_with_percentage)

def get_power_min_value(self):
def get_power_min(self):
return self.power.min.get()

def get_power_max_value(self):
def get_power_max(self):
return self.power.max.get()

def get_power(self):
return self.power.value.get()

def get_power_decimals(self):
return self.power.decimals.get()


############################################################
######################## CURRENT ###########################
############################################################

# Set power value directly with value
def set_current(self, value):
self.current.value.set(value)

# Get functions

def get_current(self):
return self.current.value.get()

def get_current_min(self):
return self.current.min.get()

def get_current_max(self):
return self.current.max.get()

def get_current_decimals(self):
return self.current.decimals.get()

0 comments on commit 95101fb

Please sign in to comment.