from astirrer import AStirrer
import time

class Stirrer(AStirrer):
	def __init__(self, params):
		super(Stirrer, self).__init__(params['dt'])
		self.isMasterOn = 0

	def __del__(self):
		self.deactivate()

	def activate(self):
		if self.isMasterOn == 0:
			self.log("Stirrer: switched On")
		self.isMasterOn = 1

	def deactivate(self):
		if self.isMasterOn == 1:
			self.log("Stirrer: switched Off")
		self.isMasterOn = 0

	def getSpeed(self):
		if self.isOn and self.isMasterOn:
			return self.speed
		return 0

	def onSetSpeed(self, speed):
		self.log("Stirrer: Set speed to {} %".format(speed))


if __name__ == '__main__':
	s = Stirrer(1.0)
	s.activate()

	print ("Set some speeds")
	s.setSpeed(50)
	time.sleep(2)
	s.setSpeed(100)
	time.sleep(2)
	s.setSpeed(50)
	time.sleep(2)

	print ("Pulsed operation, duty cycle = 50%")
	s.setDutyCycle(0.5)
	s.setCycleTime(10)
	for i in range(1,30):
		s.process()
		time.sleep(1)

	print ("Pulsed operation, duty cycle = 20%")
	s.setDutyCycle(0.2)
	s.setCycleTime(10)
	for i in range(1,30):
		s.process()
		time.sleep(1)

	s.deactivate()
