Exemplo n.º 1
0
def setFanSpeed(speed, temp):
    sbc.tx_pwm(fan,
               PWM_GPIO_NR,
               PWM_FREQ,
               speed,
               pulse_offset=0,
               pulse_cycles=0)

    # print fan speed and temperature
    if VERBOSE == 1:
        print("fan speed: ", int(speed), "    temp: ", temp)

    # write fan metrics to file for node-exporter/prometheus
    if NODE_EXPORTER == 1:
        # Save a reference to the original standard output
        original_stdout = sys.stdout
        with open('/var/lib/node_exporter/fan-metrics.prom', 'w') as f:
            # Change the standard output to the file we created.
            sys.stdout = f
            print('raspberry_fan_speed ', speed)
            print('raspberry_fan_temp ', temp)
            print('raspberry_fan_min_temp ', MIN_TEMP)
            print('raspberry_fan_max_temp ', MAX_TEMP)
            print('raspberry_fan_fan_low ', FAN_LOW)
            print('raspberry_fan_fan_high ', FAN_HIGH)
            print('raspberry_fan_wait_time ', WAIT_TIME)
            print('raspberry_fan_pwm_gpio ', PWM_GPIO_NR)
            print('raspberry_fan_freq ', PWM_FREQ)
            # Reset the standard output to its original value
            sys.stdout = original_stdout
            f.close()

    return ()
Exemplo n.º 2
0
 def _set_state(self, value):
     if self._pwm:
         freq, duty = self._pwm
         self._pwm = (freq, min(100, max(0, int(value * 100))))
         lgpio.tx_pwm(self.factory._handle, self.number, *self._pwm)
     elif self.function == 'input':
         raise PinSetInput('cannot set state of pin %r' % self)
     else:
         lgpio.gpio_write(self.factory._handle, self.number, bool(value))
Exemplo n.º 3
0
 def _set_state(self, value):
     if self._pwm:
         freq, duty = self._pwm
         self._pwm = (freq, int(value * 100))
         try:
             lgpio.tx_pwm(self.factory._handle, self.number, *self._pwm)
         except lgpio.error:
             raise PinInvalidState(
                 'invalid state "{value}" for pin {self!r}'.format(
                     self=self, value=value))
     elif self.function == 'input':
         raise PinSetInput(
             'cannot set state of pin {self!r}'.format(self=self))
     else:
         lgpio.gpio_write(self.factory._handle, self.number, bool(value))
Exemplo n.º 4
0
 def _set_frequency(self, value):
     if not self._pwm and value is not None and value > 0:
         if self.function != 'output':
             raise PinPWMFixedValue('cannot start PWM on pin %r' % self)
         lgpio.tx_pwm(self.factory._handle, self.number, value, 0)
         self._pwm = (value, 0)
     elif self._pwm and value is not None and value > 0:
         freq, duty = self._pwm
         lgpio.tx_pwm(self.factory._handle, self.number, value, duty)
         self._pwm = (value, duty)
     elif self._pwm and (value is None or value == 0):
         lgpio.tx_pwm(self.factory._handle, self.number, 0, 0)
         self._pwm = None
Exemplo n.º 5
0
status = sbc.gpio_get_mode(9999, 8888)
check("gpio_get_mode 1", sbc.BAD_HANDLE, status)

status = sbc.gpio_read(9999, 8888)
check("gpio_read 1", sbc.BAD_HANDLE, status)

status = sbc.gpio_free(9999, 8888)
check("gpio_free 1", sbc.BAD_HANDLE, status)

status = sbc.group_free(9999, 8888)
check("group_free 1", sbc.BAD_HANDLE, status)

status = sbc.tx_pulse(9999, 8888, 7777, 6666, 5555, 4444)
check("tx_pulse 1", sbc.BAD_HANDLE, status)

status = sbc.tx_pwm(9999, 8888, 7777, 6666, 5555, 4444)
check("tx_pwm 1", sbc.BAD_PWM_DUTY, status)

status = sbc.tx_pwm(9999, 8888, 77777, 50, 5555, 4444)
check("tx_pwm 2", sbc.BAD_PWM_FREQ, status)

status = sbc.tx_pwm(9999, 8888, 5000, 50, 5555, 4444)
check("tx_pwm 3", sbc.BAD_HANDLE, status)

status = sbc.tx_servo(9999, 8888, 7777, 6666, 5555, 4444)
check("tx_servo 1", sbc.BAD_SERVO_FREQ, status)

status = sbc.tx_servo(9999, 8888, 7777, 50, 5555, 4444)
check("tx_servo 2", sbc.BAD_SERVO_WIDTH, status)

status = sbc.tx_servo(9999, 8888, 1500, 50, 5555, 4444)