In embedded firmware, hardware timer peripherals often expose Capture/Compare Registers (CCR) that directly control PWM duty cycles. Writing invalid values to these registers can cause incorrect output waveforms or hardware glitches.
You are given a PWMDriver class that represents a PWM timer driver. The hardware timer has a fixed period of 100 ticks, meaning the valid range for the Capture/Compare Register is 0 to 100 (inclusive).
Currently, the CCR register is publicly accessible, allowing external code to write invalid values (negative values or values greater than 100).
Your task is to refactor the driver to enforce safe access control:
privateThis ensures the internal register value always remains valid, regardless of user input.
Program Flow:
PWMDriver instance.N representing the number of input values.N times:request_valInput Format:
N (number of test inputs)N lines: Integer request_val (requested duty cycle in ticks)Input is provided via standard input (stdin).
Output Format:
For each input, print the stored register value in the following format:
CCR: <value> Each output must appear on a new line.
Example:
Input
3
50
150
-20 Output
CCR: 50
CCR: 100
CCR: 0 Constraints:
N range: 1 to 20request_val range: -1000 to 1000
Input
3 50 150 -20
Expected Output
CCR: 50 CCR: 100 CCR: 0